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.
- package/dist/client.js +1 -1
- package/dist/config/index.d.ts +7 -0
- package/dist/config/schemas/paths.d.ts +6 -0
- package/dist/config/utils.d.ts +1 -0
- package/dist/config.js +1 -1
- package/dist/index.js +1 -1
- package/dist/runtime/adapter-express.js +14 -14
- package/dist/runtime/adapter-fastify.js +14 -14
- package/dist/runtime/adapter-fetch-cloudflare.js +19 -19
- package/dist/runtime/adapter-fetch.js +14 -14
- package/dist/runtime/adapter-nestjs.js +14 -14
- package/dist/runtime/adapter-nextjs.js +14 -14
- package/dist/runtime/cloudflare-worker.js +26 -26
- package/dist/runtime/http.js +26 -26
- package/dist/runtime/stdio.js +16 -16
- package/dist/runtime/utils/server.d.ts +1 -0
- package/dist/runtime/utils/skills.d.ts +11 -0
- package/dist/runtime/vercel.js +21 -21
- package/dist/types/skill.d.ts +26 -0
- package/package.json +1 -1
|
@@ -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 n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(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(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return t[n](o,o.exports,a),o.exports}a.d=(t,r)=>{for(var n in r)a.o(r,n)&&!a.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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 n={};return(()=>{let t,r,i,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w;a.r(n),a.d(n,{xmcpHandler:()=>fX,withAuth:()=>fK,resourceMetadataOptions:()=>fW,serverCardHandler:()=>fQ,resourceMetadataHandler:()=>fG});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),J=(t,r,a)=>(a=null!=t?L(V(t)):{},((t,r,a,n)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var i,o=U(r),s=0,l=o.length;s<l;s++)i=o[s],F.call(t,i)||i===a||Z(t,i,{get:(t=>r[t]).bind(null,i),enumerable:!(n=D(r,i))||n.enumerable});return t})(!r&&t&&t.__esModule?a:Z(a,"default",{value:t,enumerable:!0}),t));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function X(t,r="|"){return t.map(t=>eb(t)).join(r)}function Q(t,r){return"bigint"==typeof r?r.toString():r}class ee{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function et(t){return new ee(t)}function er(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let ea=Symbol("evaluating");function en(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function ei(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function eo(t){return ei(t._zod.def)??t._zod.def.shape}function es(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return en(this,r,t),t},enumerable:!0,configurable:!0})}function el(t,r,a){r in t?en(t,r,a):t[r]=a}function ec(t,r,a,n){let i=eo(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(i,o);a.enumerable&&(a.get?es(t,o,()=>{let t=r._zod.def.shape[o];return n?n(t,o):t}):el(t,o,n?n(a.value,o):a.value))}}function eu(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ep(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let em=et(()=>{if(eJ.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function eh(t){if(!1===ep(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==ep(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function ef(t){return eh(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let eg=new Set(["string","number","symbol"]);function ey(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(t,r,a){let n=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(n._zod.parent=t),n}function e_(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function eb(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(t,r){let a=eo(t),n=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&n.push(t)}return n}function eR(t,r){let a={};ec(a,t,Reflect.ownKeys(eo(t)));for(let t of Reflect.ownKeys(r)){let n=Object.getOwnPropertyDescriptor(r,t);n.enumerable&&(n.get?es(a,t,()=>r[t]):el(a,t,n.value))}return a}function ek(t,r,a,n="partial"){let i=r._zod.def.checks;if(i&&i.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let o=a?new Set(ew(r,a)):void 0,s={};return ec(s,r,Reflect.ownKeys(eo(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),ev(r,eu(r._zod.def,{shape:s,checks:[]}))}function ex(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eP(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eE(t){return"string"==typeof t?t:t?.message}function eT(t,r,a){var n;for(let i=r;i<t.length;i++)(n=t[i]).schema??(n.schema=a)}function ej(t,r,a){let n=t.inst?._zod?.traits;n?.has("$ZodType")&&(n.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let i=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:eE(t.inst?._zod.def?.error?.(t))??eE(i?.(t))??eE(r?.error?.(t))??eE(a.customError?.(t))??eE(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eO=/[\uD800-\uDBFF]/;function eC(t){let r=t.length;if(!eO.test(t))return r;let a=r;for(let n=0;n<r-1;n++)(64512&t.charCodeAt(n))==55296&&(64512&t.charCodeAt(n+1))==56320&&(a--,n++);return a}function eI(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eN(...t){let[r,a,n]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:n}:{...r}}function eq(t,r,a,n=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:n,value:a}),a}function eA(t,r){for(let a in t){let n=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eq(this,a,n(this))},set(t){eq(this,a,t)}})}return r}let eM=!1,ez={configurable:!0,get(){eM=!0}};function eL(r,a,n){let i=Object.getPrototypeOf(r._zod);if(a in i&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(i,a,{configurable:!0,get(){Object.defineProperty(this,a,ez);let t=eM;eM=!1;try{let r=n(this);return eM?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eM=eM||t,r}catch(r){throw delete this[a],eM=eM||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eZ=Object.freeze({status:"aborted"}),eD={value:void 0,enumerable:!1},eU="captureStackTrace"in Error?Error:null;function eV(t,r,a,n){function i(t){this.def=t,this.constr=u,this.traits=new Set}i.prototype={};let o=a&&new WeakSet;function s(n,s){if(n._zod){if(n._zod.traits.has(t))return}else{eD.value=new i(s);try{Object.defineProperty(n,"_zod",eD)}finally{eD.value=void 0}}if(n._zod.traits.add(t),r(n,s),o){let t=Object.getPrototypeOf(n),r=n._zod.constr.prototype,i=t;for(;i&&i!==r;)i=Object.getPrototypeOf(i);let s=i??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eq(this,r,a.bind(this))},set(t){eq(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in n||(n[t]=l[t].bind(n)))}let l=n?.Parent??Object;class c extends l{}function u(t){let r=n?.Parent?function(t){let r=eU;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eU=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 i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!n?.Parent&&r instanceof n.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eF extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eH extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eJ=globalThis.__zod_globalConfig;function eB(t){return t&&Object.assign(eJ,t),eJ}class eK extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eG="~memo",eW=[];function eY(t){return null!==t&&"object"==typeof t}function eX(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eQ=new WeakMap,e0=[],e1={alloc(t,a,n){let i=r;if(!i)return n;r=void 0;let o={value:n,issues:null};return i.set(a.value,o),e0.push(o),n},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var n,i;let o;if("backward"!==a.direction&&(n=a,i=t.value,void 0!==(o=n[eG]?.backEdges)&&eY(i)&&o.has(i)))throw new eK;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var a;let n,i,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===n){let r=function t(r,a,n){var i,o;let s=eQ.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let i=t(r,a,n);i>l&&(l=i)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=ei(d);u(r?((r,i)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(i&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,n):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 i=d._cachedInner??(n?r._zod.innerType:void 0);u(i?t(i,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),i=r,1!==(o=l)&&eQ.set(i,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?n=!0:s=!0}let p=c.value;if(!eY(p))return a(c,u);let m=u[eG];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eG]=m),i===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,i=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...eX(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;r=d;let g=e0.length,y=a(c,u);r=void 0;let v=e0.length>g?e0.pop():void 0;return y instanceof Promise?y.then(t=>(v&&(v.issues=t.issues.length?eX(t.issues):eW),t)):(v&&(v.issues=y.issues.length?eX(y.issues):eW),y)};t._zod.parse=l,t._zod.run===a&&(t._zod.run=l)})}},e2=/^[cC][0-9a-z]{6,}$/,e9=/^[0-9a-z]+$/,e4=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e3=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e5=/^[a-zA-Z0-9_-]{21}$/,e7=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e8=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,te=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tt=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,tr=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,ta=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,tn=/^(([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}|:))$/,ti=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tu=RegExp(`^${tc}$`);function td(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eV("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),tb=t=>{let r=t.value;return null!=r&&void 0!==r.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eV("$ZodCheckLessThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=n=>{(r.inclusive?n.value<=r.value:n.value<r.value)||n.issues.push({origin:tS[typeof n.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:n.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tw=eV("$ZodCheckGreaterThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=n=>{(r.inclusive?n.value>=r.value:n.value>r.value)||n.issues.push({origin:tS[typeof n.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:n.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tR=eV("$ZodCheckMultipleOf",(t,r)=>{t_.init(t,r),t._zod.check=a=>{let n,i,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==(i=Math.round(n=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(n),1),Math.abs(n-i)<o?0:n-i))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tk=eV("$ZodCheckNumberFormat",(t,r)=>{t_.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),n=a?"int":"number",[i,o]=eS[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:n,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:n,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:n,inclusive:!0,continue:!r.abort}))}l<i&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tx=eV("$ZodCheckMaxLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length;if(("string"==typeof n&&i>r.maximum?eC(n):i)<=r.maximum)return;let o=eI(n);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:n,inst:t,continue:!r.abort})}}),tP=eV("$ZodCheckMinLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length;if(("string"==typeof n&&i>=r.minimum&&i<2*r.minimum?eC(n):i)>=r.minimum)return;let o=eI(n);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:n,inst:t,continue:!r.abort})}}),tE=eV("$ZodCheckLengthEquals",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length,o="string"==typeof n&&i>=r.length&&i<=2*r.length?eC(n):i;if(o===r.length)return;let s=eI(n),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tT=eV("$ZodCheckStringFormat",(t,r)=>{var a,n;t_.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(n=t._zod).check??(n.check=()=>{})}),tj=eV("$ZodCheckRegex",(t,r)=>{tT.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tO=eV("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=ty),tT.init(t,r)}),tC=eV("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tv),tT.init(t,r)}),tI=eV("$ZodCheckIncludes",(t,r)=>{t_.init(t,r);let a=ey(r.includes),n=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=n,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tN=eV("$ZodCheckStartsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`^${ey(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tq=eV("$ZodCheckEndsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`.*${ey(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tA=eV("$ZodCheckOverwrite",(t,r)=>{t_.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tM{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
1
|
+
!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 n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(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(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return t[n](o,o.exports,a),o.exports}a.d=(t,r)=>{for(var n in r)a.o(r,n)&&!a.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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 n={};return(()=>{let t,r,i,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w;a.r(n),a.d(n,{xmcpHandler:()=>f3,withAuth:()=>f1,resourceMetadataOptions:()=>f9,serverCardHandler:()=>f6,resourceMetadataHandler:()=>f2});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,M,z,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),J=(t,r,a)=>(a=null!=t?L(V(t)):{},((t,r,a,n)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var i,o=U(r),s=0,l=o.length;s<l;s++)i=o[s],F.call(t,i)||i===a||Z(t,i,{get:(t=>r[t]).bind(null,i),enumerable:!(n=D(r,i))||n.enumerable});return t})(!r&&t&&t.__esModule?a:Z(a,"default",{value:t,enumerable:!0}),t));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,a])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function X(t,r="|"){return t.map(t=>eb(t)).join(r)}function Q(t,r){return"bigint"==typeof r?r.toString():r}class ee{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function et(t){return new ee(t)}function er(t){let r=+!!t.startsWith("^"),a=t.endsWith("$")?t.length-1:t.length;return t.slice(r,a)}let ea=Symbol("evaluating");function en(t,r,a){Object.defineProperty(t,r,{value:a,writable:!0,enumerable:!0,configurable:!0})}function ei(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function eo(t){return ei(t._zod.def)??t._zod.def.shape}function es(t,r,a){Object.defineProperty(t,r,{get(){let t=a();return en(this,r,t),t},enumerable:!0,configurable:!0})}function el(t,r,a){r in t?en(t,r,a):t[r]=a}function ec(t,r,a,n){let i=eo(r);for(let o of a){let a=Object.getOwnPropertyDescriptor(i,o);a.enumerable&&(a.get?es(t,o,()=>{let t=r._zod.def.shape[o];return n?n(t,o):t}):el(t,o,n?n(a.value,o):a.value))}}function eu(...t){let r={};for(let a of t)Object.assign(r,Object.getOwnPropertyDescriptors(a));return Object.defineProperties({},r)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ep(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let em=et(()=>{if(eJ.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function eh(t){if(!1===ep(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let a=r.prototype;return!1!==ep(a)&&!1!==Object.prototype.hasOwnProperty.call(a,"isPrototypeOf")}function ef(t){return eh(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let eg=new Set(["string","number","symbol"]);function ey(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(t,r,a){let n=new t._zod.constr(r??t._zod.def);return(!r||a?.parent)&&(n._zod.parent=t),n}function e_(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function eb(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(t,r){let a=eo(t),n=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(a,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&n.push(t)}return n}function eR(t,r){let a={};ec(a,t,Reflect.ownKeys(eo(t)));for(let t of Reflect.ownKeys(r)){let n=Object.getOwnPropertyDescriptor(r,t);n.enumerable&&(n.get?es(a,t,()=>r[t]):el(a,t,n.value))}return a}function ek(t,r,a,n="partial"){let i=r._zod.def.checks;if(i&&i.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let o=a?new Set(ew(r,a)):void 0,s={};return ec(s,r,Reflect.ownKeys(eo(r)),t&&((r,a)=>o&&!o.has(a)?r:new t({type:"optional",innerType:r}))),ev(r,eu(r._zod.def,{shape:s,checks:[]}))}function ex(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue!==!0)return!0;return!1}function eP(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eE(t){return"string"==typeof t?t:t?.message}function eT(t,r,a){var n;for(let i=r;i<t.length;i++)(n=t[i]).schema??(n.schema=a)}function ej(t,r,a){let n=t.inst?._zod?.traits;n?.has("$ZodType")&&(n.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let i=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,o=t.message?t.message:eE(t.inst?._zod.def?.error?.(t))??eE(i?.(t))??eE(r?.error?.(t))??eE(a.customError?.(t))??eE(a.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=o,r?.reportInput&&(s.input=t.input),s}let eO=/[\uD800-\uDBFF]/;function eC(t){let r=t.length;if(!eO.test(t))return r;let a=r;for(let n=0;n<r-1;n++)(64512&t.charCodeAt(n))==55296&&(64512&t.charCodeAt(n+1))==56320&&(a--,n++);return a}function eI(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function eN(...t){let[r,a,n]=t;return"string"==typeof r?{message:r,code:"custom",input:a,inst:n}:{...r}}function eq(t,r,a,n=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:n,value:a}),a}function eA(t,r){for(let a in t){let n=t[a];Object.defineProperty(r,a,{configurable:!0,enumerable:!0,get(){return eq(this,a,n(this))},set(t){eq(this,a,t)}})}return r}let eM=!1,ez={configurable:!0,get(){eM=!0}};function eL(r,a,n){let i=Object.getPrototypeOf(r._zod);if(a in i&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(i,a,{configurable:!0,get(){Object.defineProperty(this,a,ez);let t=eM;eM=!1;try{let r=n(this);return eM?delete this[a]:Object.defineProperty(this,a,{configurable:!0,writable:!0,value:r}),eM=eM||t,r}catch(r){throw delete this[a],eM=eM||t,r}},set(t){Object.defineProperty(this,a,{configurable:!0,writable:!0,value:t})}})}let eZ=Object.freeze({status:"aborted"}),eD={value:void 0,enumerable:!1},eU="captureStackTrace"in Error?Error:null;function eV(t,r,a,n){function i(t){this.def=t,this.constr=u,this.traits=new Set}i.prototype={};let o=a&&new WeakSet;function s(n,s){if(n._zod){if(n._zod.traits.has(t))return}else{eD.value=new i(s);try{Object.defineProperty(n,"_zod",eD)}finally{eD.value=void 0}}if(n._zod.traits.add(t),r(n,s),o){let t=Object.getPrototypeOf(n),r=n._zod.constr.prototype,i=t;for(;i&&i!==r;)i=Object.getPrototypeOf(i);let s=i??t;if(!o.has(s)){o.add(s);for(let t in a){let r=Object.getOwnPropertyDescriptor(a,t);r.get?Object.defineProperty(s,t,{...r,enumerable:!1}):function(t,r,a){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?a:eq(this,r,a.bind(this))},set(t){eq(this,r,t)}})}(s,t,r.value)}}}let l=u.prototype;for(let t in l)Object.prototype.hasOwnProperty.call(l,t)&&(t in n||(n[t]=l[t].bind(n)))}let l=n?.Parent??Object;class c extends l{}function u(t){let r=n?.Parent?function(t){let r=eU;if(r){let a=r.stackTraceLimit;if("number"==typeof a){try{r.stackTraceLimit=0}catch{return eU=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 i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!n?.Parent&&r instanceof n.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eF extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eH extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eJ=globalThis.__zod_globalConfig;function eB(t){return t&&Object.assign(eJ,t),eJ}class eK extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eG="~memo",eW=[];function eY(t){return null!==t&&"object"==typeof t}function eX(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eQ=new WeakMap,e0=[],e1={alloc(t,a,n){let i=r;if(!i)return n;r=void 0;let o={value:n,issues:null};return i.set(a.value,o),e0.push(o),n},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,a=(t,a)=>{var n,i;let o;if("backward"!==a.direction&&(n=a,i=t.value,void 0!==(o=n[eG]?.backEdges)&&eY(i)&&o.has(i)))throw new eK;return r(t,a)};t._zod.parse=a,t._zod.run===r&&(t._zod.run=a)})},attach(t){var a;let n,i,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===n){let r=function t(r,a,n){var i,o;let s=eQ.get(r);if(void 0!==s)return 2*!!s;if(a.has(r))return 2;a.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let i=t(r,a,n);i>l&&(l=i)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=ei(d);u(r?((r,i)=>{let o=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(i&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,a,n):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 i=d._cachedInner??(n?r._zod.innerType:void 0);u(i?t(i,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),i=r,1!==(o=l)&&eQ.set(i,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?n=!0:s=!0}let p=c.value;if(!eY(p))return a(c,u);let m=u[eG];if(m||(m={buckets:new WeakMap,backEdges:void 0},u[eG]=m),i===u)d=o;else{var h;let r;(r=(h=m).buckets.get(t))||(r=new WeakMap,h.buckets.set(t,r)),d=r,i=u,o=d}let f=d.get(p);if(f)return c.value=f.value,f.issues?f.issues.length&&c.issues.push(...eX(f.issues)):(c.memo=!0,m.backEdges??(m.backEdges=new WeakSet),m.backEdges.add(f.value)),c;r=d;let g=e0.length,y=a(c,u);r=void 0;let v=e0.length>g?e0.pop():void 0;return y instanceof Promise?y.then(t=>(v&&(v.issues=t.issues.length?eX(t.issues):eW),t)):(v&&(v.issues=y.issues.length?eX(y.issues):eW),y)};t._zod.parse=l,t._zod.run===a&&(t._zod.run=l)})}},e2=/^[cC][0-9a-z]{6,}$/,e9=/^[0-9a-z]+$/,e4=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e3=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e5=/^[a-zA-Z0-9_-]{21}$/,e7=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e8=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,te=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tt=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,tr=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,ta=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,tn=/^(([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}|:))$/,ti=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tu=RegExp(`^${tc}$`);function td(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eV("$ZodCheck",(t,r)=>{var a;t._zod??(t._zod={}),t._zod.def=r,(a=t._zod).onattach??(a.onattach=[])}),tb=t=>{let r=t.value;return null!=r&&void 0!==r.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eV("$ZodCheckLessThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=n=>{(r.inclusive?n.value<=r.value:n.value<r.value)||n.issues.push({origin:tS[typeof n.value]??a,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:n.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tw=eV("$ZodCheckGreaterThan",(t,r)=>{t_.init(t,r);let a=tS[typeof r.value];t._zod.check=n=>{(r.inclusive?n.value>=r.value:n.value>r.value)||n.issues.push({origin:tS[typeof n.value]??a,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:n.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tR=eV("$ZodCheckMultipleOf",(t,r)=>{t_.init(t,r),t._zod.check=a=>{let n,i,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==(i=Math.round(n=a.value/r.value),o=4*Number.EPSILON*Math.max(Math.abs(n),1),Math.abs(n-i)<o?0:n-i))||a.issues.push({origin:typeof a.value,code:"not_multiple_of",divisor:r.value,input:a.value,inst:t,continue:!r.abort})}}),tk=eV("$ZodCheckNumberFormat",(t,r)=>{t_.init(t,r),r.format=r.format||"float64";let a=r.format?.includes("int"),n=a?"int":"number",[i,o]=eS[r.format];t._zod.check=s=>{let l=s.value;if(a){if(!Number.isInteger(l))return void s.issues.push({expected:n,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:n,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:n,inclusive:!0,continue:!r.abort}))}l<i&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!r.abort}),l>o&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:o,inclusive:!0,inst:t,continue:!r.abort})}}),tx=eV("$ZodCheckMaxLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length;if(("string"==typeof n&&i>r.maximum?eC(n):i)<=r.maximum)return;let o=eI(n);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:n,inst:t,continue:!r.abort})}}),tP=eV("$ZodCheckMinLength",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length;if(("string"==typeof n&&i>=r.minimum&&i<2*r.minimum?eC(n):i)>=r.minimum)return;let o=eI(n);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:n,inst:t,continue:!r.abort})}}),tE=eV("$ZodCheckLengthEquals",(t,r)=>{var a;t_.init(t,r),(a=t._zod.def).when??(a.when=tb),t._zod.check=a=>{let n=a.value,i=n.length,o="string"==typeof n&&i>=r.length&&i<=2*r.length?eC(n):i;if(o===r.length)return;let s=eI(n),l=o>r.length;a.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:t,continue:!r.abort})}}),tT=eV("$ZodCheckStringFormat",(t,r)=>{var a,n;t_.init(t,r),r.pattern?(a=t._zod).check??(a.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:r.format,input:a.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(n=t._zod).check??(n.check=()=>{})}),tj=eV("$ZodCheckRegex",(t,r)=>{tT.init(t,r),t._zod.check=a=>{r.pattern.lastIndex=0,r.pattern.test(a.value)||a.issues.push({origin:"string",code:"invalid_format",format:"regex",input:a.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),tO=eV("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=ty),tT.init(t,r)}),tC=eV("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tv),tT.init(t,r)}),tI=eV("$ZodCheckIncludes",(t,r)=>{t_.init(t,r);let a=ey(r.includes),n=new RegExp("number"==typeof r.position?`^.{${r.position},}${a}`:a);r.pattern=n,t._zod.check=a=>{a.value.includes(r.includes,r.position)||a.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:a.value,inst:t,continue:!r.abort})}}),tN=eV("$ZodCheckStartsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`^${ey(r.prefix)}.*`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:t,continue:!r.abort})}}),tq=eV("$ZodCheckEndsWith",(t,r)=>{t_.init(t,r);let a=RegExp(`.*${ey(r.suffix)}$`);r.pattern??(r.pattern=a),t._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:t,continue:!r.abort})}}),tA=eV("$ZodCheckOverwrite",(t,r)=>{t_.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tM{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),a=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(a)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
2
2
|
${r.join("\n")}
|
|
3
3
|
};`)(...Object.values(this.closed))}}let tz={major:4,minor:6,patch:5},tL=eV("$ZodType",(t,r)=>{var a;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=tz;let n=t._zod.def.checks,i=t._zod.traits.has("$ZodCheck")?[t,...n??[]]:n?.length?[...n]:[];for(let r of i)for(let a of r._zod.onattach)a(t);if(0===i.length)(a=t._zod).deferred??(a.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{let r=(r,a,n)=>{let i;if(r.memo)return r;let o=ex(r);for(let s of a){if(s._zod.def.when){if(function(t,r=0){if(!0===t.aborted)return!0;for(let a=r;a<t.issues.length;a++)if(t.issues[a]?.continue===!1)return!0;return!1}(r)||!s._zod.def.when(r))continue}else if(o)continue;let a=r.issues.length,l=s._zod.check(r);if(l instanceof Promise&&n?.async===!1)throw new eF;if(i||l instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await l,r.issues.length!==a&&(eT(r.issues,a,t),o||(o=ex(r,a)))});else{if(r.issues.length===a)continue;eT(r.issues,a,t),o||(o=ex(r,a))}}return i?i.then(()=>r):r},a=(a,n,o)=>{if(ex(a))return a.aborted=!0,a;let s=r(n,i,o);if(s instanceof Promise){if(!1===o.async)throw new eF;return s.then(r=>t._zod.parse(r,o))}return t._zod.parse(s,o)};t._zod.run=(n,o)=>{if(o.skipChecks)return t._zod.parse(n,o);if("backward"===o.direction){let r=t._zod.parse({value:n.value,issues:[]},{...o,skipChecks:!0});return r instanceof Promise?r.then(t=>a(t,n,o)):a(r,n,o)}let s=t._zod.parse(n,o);if(s instanceof Promise){if(!1===o.async)throw new eF;return s.then(t=>r(t,i,o))}return r(s,i,o)}}},{get"~standard"(){return eq(this,"~standard",tU(this),!1)},set"~standard"(value){eq(this,"~standard",value)}}),tZ=(t,r)=>t.issues.length?{issues:t.issues.map(t=>ej(t,r,eB()))}:{value:t.value};async function tD(t,r){let a={async:!0};return tZ(await t._zod.run({value:r,issues:[]},a),a)}function tU(t){return{validate:r=>{let a={async:!1};try{let n=t._zod.run({value:r,issues:[]},a);if(!(n instanceof Promise))return tZ(n,a)}catch(t){}return tD(t,r)},vendor:"zod",version:1}}let tV=eV("$ZodString",(t,r)=>{tL.init(t,r),t._zod.pattern=r.pattern??tp,t._zod.parse=(a,n)=>{if(r.coerce)try{a.value=String(a.value)}catch(t){}return"string"==typeof a.value||a.issues.push({expected:"string",code:"invalid_type",input:a.value,inst:t}),a}}),tF=eV("$ZodStringFormat",(t,r)=>{tT.init(t,r),tV.init(t,r)}),tH=eV("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=e8),tF.init(t,r)}),tJ=eV("$ZodUUID",(t,r)=>{if(r.version){let t={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(void 0===t)throw Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=te(t))}else r.pattern??(r.pattern=te());tF.init(t,r)}),tB=eV("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=tt),tF.init(t,r)});function tK(t){try{if("undefined"!=typeof URL&&"function"==typeof URL.canParse)return URL.canParse(t);return new URL(t),!0}catch{return!1}}let tG=/[\t\n\r]/g;function tW(t){return t.replace(tG,"")}let tY=eV("$ZodURL",(t,r)=>{tF.init(t,r),t._zod.check=a=>{try{var n,i;let o=a.value.trim(),s="normalize"in r||"hostname"in r||"protocol"in r?function(t,r){if(!r.normalize&&r.protocol?.source===ts.source&&!/^https?:\/\//i.test(t))return 1;try{if("undefined"!=typeof URL){let r=URL;if("function"==typeof r.parse)return r.parse(t)??2}return new URL(t)}catch{return 2}}(o,r):tK(o)||2;if(1===s)return void a.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:a.value,inst:t,continue:!r.abort});if(2===s)return void a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort});if(!0===s){a.value=tW(o);return}r.hostname&&((n=r.hostname).lastIndex=0,!n.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&&((i=r.protocol).lastIndex=0,!i.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol))&&a.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:a.value,inst:t,continue:!r.abort}),a.value=r.normalize?s.href:tW(o);return}catch(n){a.issues.push({code:"invalid_format",format:"url",input:a.value,inst:t,continue:!r.abort})}}}),tX=eV("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=RegExp(tr,"u")),tF.init(t,r)}),tQ=eV("$ZodNanoID",(t,r)=>{var a;if(void 0!==r.length&&(!Number.isInteger(r.length)||r.length<1))throw Error(`Invalid nanoid length: ${r.length}`);r.pattern??(r.pattern=void 0===r.length?e5:(a=r.length,RegExp(`^[a-zA-Z0-9_-]{${a}}$`))),tF.init(t,r)}),t0=eV("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=e2),tF.init(t,r)}),t1=eV("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=e9),tF.init(t,r)}),t2=eV("$ZodULID",(t,r)=>{r.pattern??(r.pattern=e4),tF.init(t,r)}),t9=eV("$ZodXID",(t,r)=>{r.pattern??(r.pattern=e3),tF.init(t,r)}),t4=eV("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=e6),tF.init(t,r)}),t3=eV("$ZodISODateTime",(t,r)=>{let a,n,i;r.pattern??(a=["Z"],r.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),n=`${td({precision:r.precision,seconds:!0})}(?:${a.join("|")})`,i=r.local?`${n}|${td({precision:r.precision})}`:n,r.pattern=RegExp(`^${tc}T(?:${i})$`)),tF.init(t,r)}),t6=eV("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=tu),tF.init(t,r)}),t5=eV("$ZodISOTime",(t,r)=>{r.pattern??(r.pattern=RegExp(`^${td(r)}$`)),tF.init(t,r)}),t7=eV("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=e7),tF.init(t,r)}),t8=eV("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=ta),tF.init(t,r)}),re=/^[0-9a-fA-F:.]+$/;function rt(t){return!!re.test(t)&&tK(`http://[${t}]`)}let rr=eV("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=tn),tF.init(t,r),t._zod.check=a=>{rt(a.value)||a.issues.push({code:"invalid_format",format:"ipv6",input:a.value,inst:t,continue:!r.abort})}}),ra=eV("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=ti),tF.init(t,r)}),rn=eV("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=to),tF.init(t,r),t._zod.check=a=>{!function(t){let r=t.split("/");if(2!==r.length)return!1;let[a,n]=r;if(!n)return!1;let i=Number(n);return`${i}`===n&&!(i<0)&&!(i>128)&&rt(a)}(a.value)&&a.issues.push({code:"invalid_format",format:"cidrv6",input:a.value,inst:t,continue:!r.abort})}});function ri(t){if(""===t)return!0;if(/\s/.test(t)||t.length%4!=0)return!1;try{return atob(t),!0}catch{return!1}}let ro=/^[0-9a-zA-Z+/]*={0,2}$/,rs=eV("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=ro),tF.init(t,r),t._zod.check=a=>{ri(a.value)||a.issues.push({code:"invalid_format",format:"base64",input:a.value,inst:t,continue:!r.abort})}}),rl=/^[A-Za-z0-9_-]*$/,rc=eV("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=rl),tF.init(t,r),t._zod.check=a=>{!function(t){if(!rl.test(t))return!1;let r=t.replace(/[-_]/g,t=>"-"===t?"+":"/");return ri(r.padEnd(4*Math.ceil(r.length/4),"="))}(a.value)&&a.issues.push({code:"invalid_format",format:"base64url",input:a.value,inst:t,continue:!r.abort})}}),ru=eV("$ZodE164",(t,r)=>{r.pattern??(r.pattern=tl),tF.init(t,r)}),rd=eV("$ZodJWT",(t,r)=>{tF.init(t,r),t._zod.check=a=>{!function(t,r=null){try{let a=t.split(".");if(3!==a.length)return!1;let[n]=a;if(!n)return!1;let i=JSON.parse(atob(n));if("typ"in i&&i?.typ!=="JWT"||!i.alg||r&&(!("alg"in i)||i.alg!==r))return!1;return!0}catch{return!1}}(a.value,r.alg)&&a.issues.push({code:"invalid_format",format:"jwt",input:a.value,inst:t,continue:!r.abort})}}),rp=eV("$ZodNumber",(t,r)=>{tL.init(t,r),t._zod.pattern=th,t._zod.parse=(a,n)=>{if(r.coerce)try{a.value=Number(a.value)}catch(t){}let i=a.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return a;let o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:String(i):void 0;return a.issues.push({expected:"number",code:"invalid_type",input:i,inst:t,...o?{received:o}:{}}),a}}),rm=eV("$ZodNumberFormat",(t,r)=>{tk.init(t,r),rp.init(t,r)}),rh=eV("$ZodBoolean",(t,r)=>{tL.init(t,r),t._zod.pattern=tf,t._zod.parse=(a,n)=>{if(r.coerce)try{a.value=!!a.value}catch(t){}let i=a.value;return"boolean"==typeof i||a.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:t}),a}}),rf=eV("$ZodNull",(t,r)=>{tL.init(t,r),t._zod.pattern=tg,t._zod.values=new Set([null]),t._zod.parse=(r,a)=>{let n=r.value;return null===n||r.issues.push({expected:"null",code:"invalid_type",input:n,inst:t}),r}}),rg=eV("$ZodAny",(t,r)=>{tL.init(t,r),t._zod.parse=t=>t}),ry=eV("$ZodUnknown",(t,r)=>{tL.init(t,r),t._zod.parse=t=>t}),rv=eV("$ZodNever",(t,r)=>{tL.init(t,r),t._zod.parse=(r,a)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function r_(t,r,a){t.issues.length&&r.issues.push(...eP(a,t.issues)),r.value[a]=t.value}let rb=eV("$ZodArray",(t,r)=>{tL.init(t,r);let a=eJ.memoizer;a?.attach(t),t._zod.parse=(n,i)=>{let o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:t}),n;n.value=a?a.alloc(t,n,Array(o.length),i):Array(o.length);let s=[],l=i?.abortEarly;for(let t=0;t<o.length;t++){let a=o[t],c=r.element._zod.run({value:a,issues:[]},i);if(c instanceof Promise)s.push(c.then(r=>r_(r,n,t)));else if(r_(c,n,t),l&&0!==c.issues.length&&ex(c))break}return s.length?Promise.all(s).then(()=>n):n}});function rS(t,r,a,n,i,o){let s=a in n,l="optional"===o;if(s||!l||"optional"!==i){if(t.issues.length){if(void 0!==i&&l&&!s)return;r.issues.push(...eP(a,t.issues))}if(!s&&void 0===i){t.issues.length||r.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[a]});return}void 0===t.value?(s||"defaulted"===i&&!l)&&(r.value[a]=void 0):r.value[a]=t.value}}let r$=[];function rw(t){var r;let a=Object.keys(t.shape),n=Object.getOwnPropertySymbols(t.shape),i=n.length?n:r$,o=i.length?[...a,...i]: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:i,keySet:new Set(a),numKeys:a.length,optionalKeys:new Set(s)}}function rR(t,r,a,n,i,o,s){let l=[],c=i.keySet,u=i.catchall._zod,d=u.def.type,p=u.optin,m=u.optout,h=0;for(let i in r){if(s&&a.issues.length!==h){if(ex(a,h))break;h=a.issues.length}if(c.has(i))continue;if("__proto__"===i){"never"===d&&l.push(i);continue}if("never"===d){l.push(i);continue}let o=u.run({value:r[i],issues:[]},n);o instanceof Promise?t.push(o.then(t=>rS(t,a,i,r,p,m))):rS(o,a,i,r,p,m)}return(l.length&&a.issues.push({code:"unrecognized_keys",keys:l,input:r,inst:o,continue:!0}),t.length)?Promise.all(t).then(()=>a):a}let rk=eV("$ZodObject",(t,r)=>{let a;tL.init(t,r);let n=Object.getOwnPropertyDescriptor(r,"shape"),i=n?.get?n.get.raw:r.shape??{};if(i){let t=()=>{let a={...i};return Object.defineProperty(r,"shape",{value:a}),t.raw=a,a};t.raw=i,Object.defineProperty(r,"shape",{get:t})}let o=et(()=>rw(r));eL(t,"propValues",t=>{let r=t.def.shape,a={};for(let t in r){let n=r[t]._zod;if(n.values){for(let r of(Object.prototype.hasOwnProperty.call(a,t)||en(a,t,new Set),n.values))a[t].add(r);void 0!==n.optin&&a[t].add(void 0)}}return a});let s=r.catchall,l=eJ.memoizer;l?.attach(t),t._zod.parse=(r,n)=>{a??(a=o.value);let i=r.value;if(!ep(i))return r.issues.push({expected:"object",code:"invalid_type",input:i,inst:t}),r;r.value=l?l.alloc(t,r,{},n):{};let c=[],u=a.shape,d=n?.abortEarly,p=r.issues.length;for(let t of a.allKeys){if(d&&r.issues.length!==p){if(ex(r,p))break;p=r.issues.length}if("__proto__"===t)continue;let a=u[t],o=a._zod.optin,s=a._zod.optout,l=a._zod.run({value:i[t],issues:[]},n);l instanceof Promise?c.push(l.then(a=>rS(a,r,t,i,o,s))):rS(l,r,t,i,o,s)}return s?rR(c,i,r,n,o.value,t,!0===d):c.length?Promise.all(c).then(()=>r):r}}),rx=eV("$ZodObjectJIT",(t,r)=>{let a,n;rk.init(t,r);let i=t._zod.parse,o=et(()=>rw(r)),s=eJ.memoizer,l=!eJ.jitless,c=l&&em.value,u=r.catchall;t._zod.parse=(d,p)=>{n??(n=o.value);let m=d.value;return ep(m)?l&&c&&p?.async===!1&&!0!==p.jitless?(a||(a=(r=>{let a=o.value,n=a.symbolKeys,i=new tM(["payload","ctx"],{shape:r,inst:t,memo:s,syms:n}),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 n&&(i+=`id: ${n}
|
|
75
75
|
`),i+=`data: ${JSON.stringify(a)}
|
|
76
76
|
|
|
77
|
-
`,t.enqueue(r.encode(i)),!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,n,i,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p0(t,this._maxRequestBodySize);if(r.tooLarge){let t=pX(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{n=Array.isArray(a)?a.map(t=>ol.parse(t)):[ol.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=n.some(t=>ow.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(n.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{i=await this._checkScopeChallenge(n,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!n.some(t=>cK(t))){for(let a of n)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=n.find(t=>ow.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),n))cK(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of n)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),n))cK(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),n)){let n,i;cK(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(n=()=>{this.closeSSEStream(a.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:n,closeStandaloneSSEStream:i})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cW(t)||cY(t))&&(a=t.id),void 0===a){let r;if(cW(t)||cY(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let n=this._requestToStreamMapping.get(a);if(!n)throw Error(`No connection established for request ID: ${String(a)}`);let i=this._streamMapping.get(n);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(n,t),i=this._streamMapping.get(n)),i?.controller&&i?.encoder&&(void 0===r||!i.replayedEventIds?.has(r))&&this.writeSSEEvent(i.controller,i.encoder,t,r)}if(cW(t)||cY(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===n).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!i){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&&i.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?i.resolveJson(Response.json(a[0],{status:200,headers:t})):i.resolveJson(Response.json(a,{status:200,headers:t})),i.cleanup()}else i.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p2(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p9(t,r,a,n,i=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==n&&{data:n}},id:i},{status:t})}function p4(t,r=null){return p9(t.httpStatus,t.code,t.message,t.data,r)}function p3(t){return t instanceof Error?t:Error(String(t))}function p6(t=null){return p9(500,-32603,"Internal server error",void 0,t)}function p5(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p7(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function p8(t,r,a=!0,n=4194304){let i,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p0(t,n);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{i=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===i||(s=i)}else i=s;if(c||void 0===i)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:ui(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:ui(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:ui(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ur("jsonrpc-shape","empty-batch",400,new cg(cf.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cF(uo(t)?t.params:void 0))return ur("jsonrpc-shape","batch-with-modern-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cK(t)||cG(t)||cW(t)||cY(t)))return ur("jsonrpc-shape","batch-with-invalid-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cW(r)||cY(r)?{kind:"legacy",reason:"response"}:uo(r)&&cK(r)?function(t,r){let a=r.params,n=r.method,i=t.protocolVersionHeader,o=void 0!==i&&i>=lW;if("initialize"===n&&!function(t){if(!cF(t))return!1;let r=cH(t);if(void 0===r||!(r>=lW))return!1;let a=cV(t);return void 0!==a&&0===cJ(a).length}(a)){if(o)return ua("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=uo(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cF(a)){let o=cV(a),s=(void 0===o?[]:cJ(o))[0];if(void 0!==s)return ur("envelope","envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cH(a);return void 0!==i&&void 0!==l&&i!==l?ua("header-body-version-mismatch",i,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${i}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("method-header-mismatch",t.mcpMethodHeader,`the body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:us(l)}}if(o){let t=cV(a),r=cJ(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),n=void 0===t?["_meta"]:r.length>0?r:[iJ];return ur("envelope","modern-header-without-claim",400,new cg(cf.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${n.join(", ")}`,{envelope:{missing:n}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(t,r):uo(r)&&cG(r)?function(t,r){let a=r.params,n=r.method,i=t.protocolVersionHeader,o=void 0!==i&&i>=lW;if(cF(a)){let o=cH(a);if(void 0===o){let t=cV(a),r=(void 0===t?[]:cJ(t)).find(t=>t.key===iJ)??{key:iJ,problem:"expected a protocol version string"};return ur("envelope","notification-envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==i&&i!==o)return ua("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${i}`);let s=us(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(t,r):ur("jsonrpc-shape","invalid-json-rpc-body",400,new cg(cf.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...p7(t),...void 0!==i&&{body:i}}),body:i,parsedBody:s,forwardRequest:l}}let me=require("async_hooks"),mt=(t,r)=>{globalThis[t]=r},mr=t=>globalThis[t];function ma({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),n=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mr(a))return mr(a);let i=new me.AsyncLocalStorage,o=globalThis[n]??{current:null};mt(n,o);let s={provider:(t,a)=>(r&&(o.current=t),i.run(t,a)),getContext:()=>{let a=i.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 n=i.getStore()??(r?o.current:null);if(!n)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(n,a)}};return mt(a,s),s}let mn=ma({name:"http-request-context"}),mi=mn.setContext,mo=mn.getContext,ms=mn.provider,ml=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),mc=t=>{if(!ml(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},mu=t=>{if(t&&"initialize"===t.method&&ml(t.params))return mc(t.params.clientInfo)},md=(t,r)=>{let a=r.toLowerCase();for(let[r,n]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(n)?n[0]:n;if("string"!=typeof t)break;let i=t.trim();return i.length>0?i:void 0}};function mp(t){let{tags:r,enabled:a,...n}=t;return{...n,_meta:void 0===r?n._meta:{...n._meta,"xmcp/tags":r}}}let mm=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)}},mh=ma({name:"request-context",fallback:!1}),mf=ma({name:"client-info-context"});mf.setContext;let mg=mf.getContext;mf.provider;let my=new Set(["message","mode","requestedSchema"]),mv=new Set(["elicitationId","message","mode","url"]),m_=new Set(["properties","required","type"]),mb=new Set(["default","description","format","maxLength","minLength","title","type"]),mS=new Set(["default","description","enum","enumNames","title","type"]),m$=new Set(["default","description","title","type"]),mw=new Set(["default","description","maximum","minimum","title","type"]),mR=new Set(["date","date-time","email","uri"]);async function mk(t,r,a){let n=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mP(t,"Elicitation request must be a plain object."),mx(t,mv,"URL elicitation"),mE(t.message,"URL elicitation requires a string message."),mT(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mT(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){mP(t,"Elicitation request must be a plain object."),mx(t,my,"Form elicitation"),mE(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mP(r,"Form elicitation requires a flat object schema."),mx(r,m_,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mP(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mP(r,`Form elicitation field "${t}" must be a plain object.`),mj(r.title,`Form elicitation field "${t}" title must be a string.`),mj(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,n;if(mx(r,mS,`Form elicitation field "${t}"`),mC(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,n=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mC(a,n),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mj(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)){mx(r,mb,`Form elicitation field "${t}"`),mO(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mO(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mj(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mj(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mR.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mR).join(", ")}.`);return}if("boolean"===r.type){if(mx(r,m$,`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){mx(r,mw,`Form elicitation field "${t}"`),mO(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mO(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mO(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(n,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mx(t,r,a){let n=Object.keys(t).filter(t=>!r.has(t));if(0!==n.length)throw Error(`${a} includes unsupported key(s): ${n.join(", ")}.`)}function mP(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mE(t,r){if("string"!=typeof t)throw Error(r)}function mT(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mj(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mO(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mC(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let mI=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mN=new Set(["task","toolChoice","tools"]),mq=new Set(["text","image","audio"]);async function mA(t,r,a){let n=function(t){mM(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>mN.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let n=r.filter(t=>!mI.has(t));if(n.length>0)throw Error(`Sampling request includes unsupported key(s): ${n.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(mM(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;mM(a,`Sampling message at index ${t} requires a content object.`);let n=a.type;if("string"!=typeof n||!mq.has(n))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(n)}". Supported types are text, image, and audio.`);if("text"===n&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===n||"audio"===n)&&("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(n,a)}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mM(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let mz={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 mL(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=mz[t.type];return r?r(t):{valid:!0}}function mZ(t,r,a,n){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${n}: expected a plain object.`);let i=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!i.has(t));if(o.length>0)throw Error(`Tool "${a}" ${n}: unrecognized key(s): ${o.join(", ")}`);for(let[i,o]of Object.entries(r))try{o.parse(t[i])}catch(t){throw Error(`Tool "${a}" ${n}: ${t?.message??`invalid field "${i}"`}`)}}function mD(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function mU(t){let r=t.mcpReq.envelope,a=mc(r?.[iB]);if(!a)try{let t,r=mo();a=r.clientInfo??(t=r.headers,mc({name:md(t,"x-mcp-client-name"),version:md(t,"x-mcp-client-version"),title:md(t,"x-mcp-client-title"),websiteUrl:md(t,"x-mcp-client-website-url"),description:md(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mg().clientInfo}catch{}return a}function mV(t){let r=[...t];return(t,a,n)=>(function(t,r,a){let n,i=new Map;if(t.http){let t=mo(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));n=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mh.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:n,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){i.set(t,r)},get:t=>i.get(t),async progress(r,a){let n=t.mcpReq._meta?.progressToken;void 0!==n&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:n,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,mU(a),async()=>{if(0===r.length)return n();let a=Object.freeze({...function(){try{return mh.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),i=-1,o=async t=>{if(t<=i)throw Error("MCP middleware next() can only be called once");i=t;let s=r[t];return s?s(a,()=>o(t+1)):n()};return o(0)})}let mF=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mH(t){return t.endsWith(".tsx")}let mJ=Symbol("Let zodToJsonSchema decide on which parser to use"),mB={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let n of r)a[n]=t[n];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(A||(A={})).mergeShapes=(t,r)=>({...t,...r});let mK=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mG=t=>{switch(typeof t){case"undefined":return mK.undefined;case"string":return mK.string;case"number":return Number.isNaN(t)?mK.nan:mK.number;case"boolean":return mK.boolean;case"function":return mK.function;case"bigint":return mK.bigint;case"symbol":return mK.symbol;case"object":if(Array.isArray(t))return mK.array;if(null===t)return mK.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return mK.promise;if("undefined"!=typeof Map&&t instanceof Map)return mK.map;if("undefined"!=typeof Set&&t instanceof Set)return mK.set;if("undefined"!=typeof Date&&t instanceof Date)return mK.date;return mK.object;default:return mK.unknown}},mW=q.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class mY 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:[]},n=t=>{for(let i of t.issues)if("invalid_union"===i.code)i.unionErrors.map(n);else if("invalid_return_type"===i.code)n(i.returnTypeError);else if("invalid_arguments"===i.code)n(i.argumentsError);else if(0===i.path.length)a._errors.push(r(i));else{let t=a,n=0;for(;n<i.path.length;){let a=i.path[n],o=n===i.path.length-1;if("_errors"===a){o&&t._errors.push(r(i)),n++;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(i)),n++}}};return n(this),a}static assert(t){if(!(t instanceof mY))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let n of this.issues)if(n.path.length>0){let a=n.path[0];r[a]=r[a]||[],r[a].push(t(n))}else a.push(t(n));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}mY.create=t=>new mY(t);let mX=(t,r)=>{let a;switch(t.code){case mW.invalid_type:a=t.received===mK.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case mW.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,q.jsonStringifyReplacer)}`;break;case mW.unrecognized_keys:a=`Unrecognized key(s) in object: ${q.joinValues(t.keys,", ")}`;break;case mW.invalid_union:a="Invalid input";break;case mW.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${q.joinValues(t.options)}`;break;case mW.invalid_enum_value:a=`Invalid enum value. Expected ${q.joinValues(t.options)}, received '${t.received}'`;break;case mW.invalid_arguments:a="Invalid function arguments";break;case mW.invalid_return_type:a="Invalid function return type";break;case mW.invalid_date:a="Invalid date";break;case mW.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:q.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case mW.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 mW.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 mW.custom:a="Invalid input";break;case mW.invalid_intersection_types:a="Intersection results could not be merged";break;case mW.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case mW.not_finite:a="Number must be finite";break;default:a=r.defaultError,q.assertNever(t)}return{message:a}};(j=M||(M={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let mQ=t=>{let{data:r,path:a,errorMaps:n,issueData:i}=t,o=[...a,...i.path||[]],s={...i,path:o};if(void 0!==i.message)return{...i,path:o,message:i.message};let l="";for(let t of n.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...i,path:o,message:l}};function m0(t,r){let a=mQ({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mX,void 0].filter(t=>!!t)});t.common.issues.push(a)}class m1{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 n of r){if("aborted"===n.status)return m2;"dirty"===n.status&&t.dirty(),a.push(n.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,n=await t.value;a.push({key:r,value:n})}return m1.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let n of r){let{key:r,value:i}=n;if("aborted"===r.status||"aborted"===i.status)return m2;"dirty"===r.status&&t.dirty(),"dirty"===i.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==i.value||n.alwaysSet)&&(a[r.value]=i.value)}return{status:t.value,value:a}}}let m2=Object.freeze({status:"aborted"}),m9=t=>({status:"dirty",value:t}),m4=t=>({status:"valid",value:t}),m3=t=>"undefined"!=typeof Promise&&t instanceof Promise;class m6{constructor(t,r,a,n){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=n}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 m5=(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 mY(t.common.issues);return this._error=r,this._error}}};function m7(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:n,description:i}=t;if(r&&(a||n))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:i}:{errorMap:(r,i)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??i.defaultError}:void 0===i.data?{message:o??n??i.defaultError}:"invalid_type"!==r.code?{message:i.defaultError}:{message:o??a??i.defaultError}},description:i}}class m8{get description(){return this._def.description}_getType(t){return mG(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:mG(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new m1,ctx:{common:t.parent.common,data:t.data,parsedType:mG(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(m3(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:mG(t)},n=this._parseSync({data:t,path:a.path,parent:a});return m5(a,n)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mG(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:mG(t)},n=this._parse({data:t,path:a.path,parent:a});return m5(a,await (m3(n)?n:Promise.resolve(n)))}refine(t,r){return this._refinement((a,n)=>{let i=t(a),o=()=>n.addIssue({code:mW.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&i instanceof Promise?i.then(t=>!!t||(o(),!1)):!!i||(o(),!1)})}refinement(t,r){return this._refinement((a,n)=>!!t(a)||(n.addIssue("function"==typeof r?r(a,n):r),!1))}_refinement(t){return new hJ({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 hB.create(this,this._def)}nullable(){return hK.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hT.create(this)}promise(){return hH.create(this,this._def)}or(t){return hO.create([this,t],this._def)}and(t){return hN.create(this,t,this._def)}transform(t){return new hJ({...m7(this._def),schema:this,typeName:z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new hG({...m7(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:z.ZodDefault})}brand(){return new hX({typeName:z.ZodBranded,type:this,...m7(this._def)})}catch(t){return new hW({...m7(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 hQ.create(this,t)}readonly(){return h0.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let he=/^c[^\s-]{8,}$/i,ht=/^[0-9a-z]+$/,hr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ha=/^[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,hn=/^[a-z0-9_-]{21}$/i,hi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ho=/^[-+]?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)?)??$/,hs=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,hl=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,hc=/^(?:(?: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])$/,hu=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hd=/^(([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])$/,hp=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hm=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hh="((\\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])))",hf=RegExp(`^${hh}$`);function hg(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 hy extends m8{_parse(t){var r,a,n,i;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==mK.string){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.string,received:r.parsedType}),m2}let s=new m1;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(m0(o=this._getOrReturnCtx(t,o),{code:mW.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&&(m0(o=this._getOrReturnCtx(t,o),{code:mW.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?m0(o,{code:mW.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&m0(o,{code:mW.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)hs.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"email",code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:mW.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)ha.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:mW.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)hn.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:mW.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)he.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:mW.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)ht.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:mW.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)hr.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:mW.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{m0(o=this._getOrReturnCtx(t,o),{validation:"url",code:mW.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"regex",code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hh}T${hg(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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hf.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hg(l)}$`).test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?ho.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"duration",code:mW.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hl.test(r)||("v6"===a||!a)&&hu.test(r))&&1&&(m0(o=this._getOrReturnCtx(t,o),{validation:"ip",code:mW.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hi.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let n=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),i=JSON.parse(atob(n));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||r&&i.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(m0(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:mW.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(n=t.data,!(("v4"===(i=l.version)||!i)&&hc.test(n)||("v6"===i||!i)&&hd.test(n))&&1&&(m0(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:mW.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hp.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"base64",code:mW.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hm.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:mW.invalid_string,message:l.message}),s.dirty()):q.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:mW.invalid_string,...M.errToObj(a)})}_addCheck(t){return new hy({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...M.errToObj(t)})}url(t){return this._addCheck({kind:"url",...M.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...M.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...M.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...M.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...M.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...M.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...M.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...M.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...M.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...M.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...M.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...M.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...M.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...M.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...M.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...M.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...M.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...M.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...M.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...M.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...M.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...M.errToObj(r)})}nonempty(t){return this.min(1,M.errToObj(t))}trim(){return new hy({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hy({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hy({...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}}hy.create=t=>new hy({checks:[],typeName:z.ZodString,coerce:t?.coerce??!1,...m7(t)});class hv extends m8{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)!==mK.number){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.number,received:r.parsedType}),m2}let a=new m1;for(let n of this._def.checks)"int"===n.kind?q.isInteger(t.data)||(m0(r=this._getOrReturnCtx(t,r),{code:mW.invalid_type,expected:"integer",received:"float",message:n.message}),a.dirty()):"min"===n.kind?(n.inclusive?t.data<n.value:t.data<=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),a.dirty()):"max"===n.kind?(n.inclusive?t.data>n.value:t.data>=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),a.dirty()):"multipleOf"===n.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,n=(r.toString().split(".")[1]||"").length,i=a>n?a:n;return Number.parseInt(t.toFixed(i).replace(".",""))%Number.parseInt(r.toFixed(i).replace(".",""))/10**i}(t.data,n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_multiple_of,multipleOf:n.value,message:n.message}),a.dirty()):"finite"===n.kind?Number.isFinite(t.data)||(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_finite,message:n.message}),a.dirty()):q.assertNever(n);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,n){return new hv({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(n)}]})}_addCheck(t){return new hv({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:M.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:M.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:M.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:M.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&q.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hv.create=t=>new hv({checks:[],typeName:z.ZodNumber,coerce:t?.coerce||!1,...m7(t)});class h_ extends m8{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)!==mK.bigint)return this._getInvalidInput(t);let a=new m1;for(let n of this._def.checks)"min"===n.kind?(n.inclusive?t.data<n.value:t.data<=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),a.dirty()):"max"===n.kind?(n.inclusive?t.data>n.value:t.data>=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),a.dirty()):"multipleOf"===n.kind?t.data%n.value!==BigInt(0)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_multiple_of,multipleOf:n.value,message:n.message}),a.dirty()):q.assertNever(n);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.bigint,received:r.parsedType}),m2}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,n){return new h_({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(n)}]})}_addCheck(t){return new h_({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}h_.create=t=>new h_({checks:[],typeName:z.ZodBigInt,coerce:t?.coerce??!1,...m7(t)});class hb extends m8{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==mK.boolean){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.boolean,received:r.parsedType}),m2}return m4(t.data)}}hb.create=t=>new hb({typeName:z.ZodBoolean,coerce:t?.coerce||!1,...m7(t)});class hS extends m8{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==mK.date){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.date,received:r.parsedType}),m2}if(Number.isNaN(t.data.getTime()))return m0(this._getOrReturnCtx(t),{code:mW.invalid_date}),m2;let a=new m1;for(let n of this._def.checks)"min"===n.kind?t.data.getTime()<n.value&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),a.dirty()):"max"===n.kind?t.data.getTime()>n.value&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),a.dirty()):q.assertNever(n);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hS({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:M.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:M.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hS.create=t=>new hS({checks:[],coerce:t?.coerce||!1,typeName:z.ZodDate,...m7(t)});class h$ extends m8{_parse(t){if(this._getType(t)!==mK.symbol){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.symbol,received:r.parsedType}),m2}return m4(t.data)}}h$.create=t=>new h$({typeName:z.ZodSymbol,...m7(t)});class hw extends m8{_parse(t){if(this._getType(t)!==mK.undefined){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.undefined,received:r.parsedType}),m2}return m4(t.data)}}hw.create=t=>new hw({typeName:z.ZodUndefined,...m7(t)});class hR extends m8{_parse(t){if(this._getType(t)!==mK.null){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.null,received:r.parsedType}),m2}return m4(t.data)}}hR.create=t=>new hR({typeName:z.ZodNull,...m7(t)});class hk extends m8{constructor(){super(...arguments),this._any=!0}_parse(t){return m4(t.data)}}hk.create=t=>new hk({typeName:z.ZodAny,...m7(t)});class hx extends m8{constructor(){super(...arguments),this._unknown=!0}_parse(t){return m4(t.data)}}hx.create=t=>new hx({typeName:z.ZodUnknown,...m7(t)});class hP extends m8{_parse(t){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.never,received:r.parsedType}),m2}}hP.create=t=>new hP({typeName:z.ZodNever,...m7(t)});class hE extends m8{_parse(t){if(this._getType(t)!==mK.undefined){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.void,received:r.parsedType}),m2}return m4(t.data)}}hE.create=t=>new hE({typeName:z.ZodVoid,...m7(t)});class hT extends m8{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),n=this._def;if(r.parsedType!==mK.array)return m0(r,{code:mW.invalid_type,expected:mK.array,received:r.parsedType}),m2;if(null!==n.exactLength){let t=r.data.length>n.exactLength.value,i=r.data.length<n.exactLength.value;(t||i)&&(m0(r,{code:t?mW.too_big:mW.too_small,minimum:i?n.exactLength.value:void 0,maximum:t?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),a.dirty())}if(null!==n.minLength&&r.data.length<n.minLength.value&&(m0(r,{code:mW.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),a.dirty()),null!==n.maxLength&&r.data.length>n.maxLength.value&&(m0(r,{code:mW.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>n.type._parseAsync(new m6(r,t,r.path,a)))).then(t=>m1.mergeArray(a,t));let i=[...r.data].map((t,a)=>n.type._parseSync(new m6(r,t,r.path,a)));return m1.mergeArray(a,i)}get element(){return this._def.type}min(t,r){return new hT({...this._def,minLength:{value:t,message:M.toString(r)}})}max(t,r){return new hT({...this._def,maxLength:{value:t,message:M.toString(r)}})}length(t,r){return new hT({...this._def,exactLength:{value:t,message:M.toString(r)}})}nonempty(t){return this.min(1,t)}}hT.create=(t,r)=>new hT({type:t,minLength:null,maxLength:null,exactLength:null,typeName:z.ZodArray,...m7(r)});class hj extends m8{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=q.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==mK.object){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.object,received:r.parsedType}),m2}let{status:r,ctx:a}=this._processInputParams(t),{shape:n,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof hP&&"strip"===this._def.unknownKeys))for(let t in a.data)i.includes(t)||o.push(t);let s=[];for(let t of i){let r=n[t],i=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new m6(a,i,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hP){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&&(m0(a,{code:mW.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 n=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new m6(a,n,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,n=await r.value;t.push({key:a,value:n,alwaysSet:r.alwaysSet})}return t}).then(t=>m1.mergeObjectSync(r,t)):m1.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return M.errToObj,new hj({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let n=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:M.errToObj(t).message??n}:{message:n}}}:{}})}strip(){return new hj({...this._def,unknownKeys:"strip"})}passthrough(){return new hj({...this._def,unknownKeys:"passthrough"})}extend(t){return new hj({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hj({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 hj({...this._def,catchall:t})}pick(t){let r={};for(let a of q.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hj({...this._def,shape:()=>r})}omit(t){let r={};for(let a of q.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hj({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hj){let a={};for(let n in r.shape){let i=r.shape[n];a[n]=hB.create(t(i))}return new hj({...r._def,shape:()=>a})}if(r instanceof hT)return new hT({...r._def,type:t(r.element)});if(r instanceof hB)return hB.create(t(r.unwrap()));if(r instanceof hK)return hK.create(t(r.unwrap()));if(r instanceof hq)return hq.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of q.objectKeys(this.shape)){let n=this.shape[a];t&&!t[a]?r[a]=n:r[a]=n.optional()}return new hj({...this._def,shape:()=>r})}required(t){let r={};for(let a of q.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof hB;)t=t._def.innerType;r[a]=t}return new hj({...this._def,shape:()=>r})}keyof(){return hU(q.objectKeys(this.shape))}}hj.create=(t,r)=>new hj({shape:()=>t,unknownKeys:"strip",catchall:hP.create(),typeName:z.ZodObject,...m7(r)}),hj.strictCreate=(t,r)=>new hj({shape:()=>t,unknownKeys:"strict",catchall:hP.create(),typeName:z.ZodObject,...m7(r)}),hj.lazycreate=(t,r)=>new hj({shape:t,unknownKeys:"strip",catchall:hP.create(),typeName:z.ZodObject,...m7(r)});class hO extends m8{_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 mY(t.ctx.common.issues));return m0(r,{code:mW.invalid_union,unionErrors:a}),m2});{let t,n=[];for(let i of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=i._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&&n.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let i=n.map(t=>new mY(t));return m0(r,{code:mW.invalid_union,unionErrors:i}),m2}}get options(){return this._def.options}}hO.create=(t,r)=>new hO({options:t,typeName:z.ZodUnion,...m7(r)});let hC=t=>{if(t instanceof hZ)return hC(t.schema);if(t instanceof hJ)return hC(t.innerType());if(t instanceof hD)return[t.value];if(t instanceof hV)return t.options;if(t instanceof hF)return q.objectValues(t.enum);else if(t instanceof hG)return hC(t._def.innerType);else if(t instanceof hw)return[void 0];else if(t instanceof hR)return[null];else if(t instanceof hB)return[void 0,...hC(t.unwrap())];else if(t instanceof hK)return[null,...hC(t.unwrap())];else if(t instanceof hX)return hC(t.unwrap());else if(t instanceof h0)return hC(t.unwrap());else if(t instanceof hW)return hC(t._def.innerType);else return[]};class hI extends m8{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mK.object)return m0(r,{code:mW.invalid_type,expected:mK.object,received:r.parsedType}),m2;let a=this.discriminator,n=r.data[a],i=this.optionsMap.get(n);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(m0(r,{code:mW.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),m2)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let n=new Map;for(let a of r){let r=hC(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let i of r){if(n.has(i))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(i)}`);n.set(i,a)}}return new hI({typeName:z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:n,...m7(a)})}}class hN extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),n=(t,n)=>{if("aborted"===t.status||"aborted"===n.status)return m2;let i=function t(r,a){let n=mG(r),i=mG(a);if(r===a)return{valid:!0,data:r};if(n===mK.object&&i===mK.object){let n=q.objectKeys(a),i=q.objectKeys(r).filter(t=>-1!==n.indexOf(t)),o={...r,...a};for(let n of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,i)){if("__proto__"===n)continue;let i=t(r[n],a[n]);if(!i.valid)return{valid:!1};o[n]=i.data}return{valid:!0,data:o}}if(n===mK.array&&i===mK.array){if(r.length!==a.length)return{valid:!1};let n=[];for(let i=0;i<r.length;i++){let o=t(r[i],a[i]);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}if(n===mK.date&&i===mK.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,n.value);return i.valid?(("dirty"===t.status||"dirty"===n.status)&&r.dirty(),{status:r.value,value:i.data}):(m0(a,{code:mW.invalid_intersection_types}),m2)};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])=>n(t,r)):n(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}hN.create=(t,r,a)=>new hN({left:t,right:r,typeName:z.ZodIntersection,...m7(a)});class hq extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mK.array)return m0(a,{code:mW.invalid_type,expected:mK.array,received:a.parsedType}),m2;if(a.data.length<this._def.items.length)return m0(a,{code:mW.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),m2;!this._def.rest&&a.data.length>this._def.items.length&&(m0(a,{code:mW.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let n=[...a.data].map((t,r)=>{let n=this._def.items[r]||this._def.rest;return n?n._parse(new m6(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(n).then(t=>m1.mergeArray(r,t)):m1.mergeArray(r,n)}get items(){return this._def.items}rest(t){return new hq({...this._def,rest:t})}}hq.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hq({items:t,typeName:z.ZodTuple,rest:null,...m7(r)})};class hA extends m8{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!==mK.object)return m0(a,{code:mW.invalid_type,expected:mK.object,received:a.parsedType}),m2;let n=[],i=this._def.keyType,o=this._def.valueType;for(let t in a.data)n.push({key:i._parse(new m6(a,t,a.path,t)),value:o._parse(new m6(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?m1.mergeObjectAsync(r,n):m1.mergeObjectSync(r,n)}get element(){return this._def.valueType}static create(t,r,a){return new hA(r instanceof m8?{keyType:t,valueType:r,typeName:z.ZodRecord,...m7(a)}:{keyType:hy.create(),valueType:t,typeName:z.ZodRecord,...m7(r)})}}class hM extends m8{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!==mK.map)return m0(a,{code:mW.invalid_type,expected:mK.map,received:a.parsedType}),m2;let n=this._def.keyType,i=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:n._parse(new m6(a,t,a.path,[o,"key"])),value:i._parse(new m6(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 n=await a.key,i=await a.value;if("aborted"===n.status||"aborted"===i.status)return m2;("dirty"===n.status||"dirty"===i.status)&&r.dirty(),t.set(n.value,i.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let n=a.key,i=a.value;if("aborted"===n.status||"aborted"===i.status)return m2;("dirty"===n.status||"dirty"===i.status)&&r.dirty(),t.set(n.value,i.value)}return{status:r.value,value:t}}}}hM.create=(t,r,a)=>new hM({valueType:r,keyType:t,typeName:z.ZodMap,...m7(a)});class hz extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mK.set)return m0(a,{code:mW.invalid_type,expected:mK.set,received:a.parsedType}),m2;let n=this._def;null!==n.minSize&&a.data.size<n.minSize.value&&(m0(a,{code:mW.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),r.dirty()),null!==n.maxSize&&a.data.size>n.maxSize.value&&(m0(a,{code:mW.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),r.dirty());let i=this._def.valueType;function o(t){let a=new Set;for(let n of t){if("aborted"===n.status)return m2;"dirty"===n.status&&r.dirty(),a.add(n.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>i._parse(new m6(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new hz({...this._def,minSize:{value:t,message:M.toString(r)}})}max(t,r){return new hz({...this._def,maxSize:{value:t,message:M.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}hz.create=(t,r)=>new hz({valueType:t,minSize:null,maxSize:null,typeName:z.ZodSet,...m7(r)});class hL extends m8{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mK.function)return m0(r,{code:mW.invalid_type,expected:mK.function,received:r.parsedType}),m2;function a(t,a){return mQ({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mX,mX].filter(t=>!!t),issueData:{code:mW.invalid_arguments,argumentsError:a}})}function n(t,a){return mQ({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mX,mX].filter(t=>!!t),issueData:{code:mW.invalid_return_type,returnTypeError:a}})}let i={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof hH){let t=this;return m4(async function(...r){let s=new mY([]),l=await t._def.args.parseAsync(r,i).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,i).catch(t=>{throw s.addIssue(n(c,t)),s})})}{let t=this;return m4(function(...r){let s=t._def.args.safeParse(r,i);if(!s.success)throw new mY([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,i);if(!c.success)throw new mY([n(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new hL({...this._def,args:hq.create(t).rest(hx.create())})}returns(t){return new hL({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new hL({args:t||hq.create([]).rest(hx.create()),returns:r||hx.create(),typeName:z.ZodFunction,...m7(a)})}}class hZ extends m8{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})}}hZ.create=(t,r)=>new hZ({getter:t,typeName:z.ZodLazy,...m7(r)});class hD extends m8{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return m0(r,{received:r.data,code:mW.invalid_literal,expected:this._def.value}),m2}return{status:"valid",value:t.data}}get value(){return this._def.value}}function hU(t,r){return new hV({values:t,typeName:z.ZodEnum,...m7(r)})}hD.create=(t,r)=>new hD({value:t,typeName:z.ZodLiteral,...m7(r)});class hV extends m8{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return m0(r,{expected:q.joinValues(a),received:r.parsedType,code:mW.invalid_type}),m2}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 m0(r,{received:r.data,code:mW.invalid_enum_value,options:a}),m2}return m4(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return hV.create(t,{...this._def,...r})}exclude(t,r=this._def){return hV.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}hV.create=hU;class hF extends m8{_parse(t){let r=q.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==mK.string&&a.parsedType!==mK.number){let t=q.objectValues(r);return m0(a,{expected:q.joinValues(t),received:a.parsedType,code:mW.invalid_type}),m2}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=q.objectValues(r);return m0(a,{received:a.data,code:mW.invalid_enum_value,options:t}),m2}return m4(t.data)}get enum(){return this._def.values}}hF.create=(t,r)=>new hF({values:t,typeName:z.ZodNativeEnum,...m7(r)});class hH extends m8{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==mK.promise&&!1===r.common.async?(m0(r,{code:mW.invalid_type,expected:mK.promise,received:r.parsedType}),m2):m4((r.parsedType===mK.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}hH.create=(t,r)=>new hH({type:t,typeName:z.ZodPromise,...m7(r)});class hJ extends m8{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),n=this._def.effect||null,i={addIssue:t=>{m0(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===n.type){let t=n.transform(a.data,i);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return m2;let n=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===n.status?m2:"dirty"===n.status||"dirty"===r.value?m9(n.value):n});{if("aborted"===r.value)return m2;let n=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===n.status?m2:"dirty"===n.status||"dirty"===r.value?m9(n.value):n}}if("refinement"===n.type){let t=t=>{let r=n.refinement(t,i);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?m2:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let n=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===n.status?m2:("dirty"===n.status&&r.dirty(),t(n.value),{status:r.value,value:n.value})}}if("transform"===n.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?m2:Promise.resolve(n.transform(t.value,i)).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 m2;let o=n.transform(t.value,i);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}q.assertNever(n)}}hJ.create=(t,r,a)=>new hJ({schema:t,typeName:z.ZodEffects,effect:r,...m7(a)}),hJ.createWithPreprocess=(t,r,a)=>new hJ({schema:r,effect:{type:"preprocess",transform:t},typeName:z.ZodEffects,...m7(a)});class hB extends m8{_parse(t){return this._getType(t)===mK.undefined?m4(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hB.create=(t,r)=>new hB({innerType:t,typeName:z.ZodOptional,...m7(r)});class hK extends m8{_parse(t){return this._getType(t)===mK.null?m4(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hK.create=(t,r)=>new hK({innerType:t,typeName:z.ZodNullable,...m7(r)});class hG extends m8{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===mK.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}hG.create=(t,r)=>new hG({innerType:t,typeName:z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...m7(r)});class hW extends m8{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},n=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return m3(n)?n.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new mY(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===n.status?n.value:this._def.catchValue({get error(){return new mY(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}hW.create=(t,r)=>new hW({innerType:t,typeName:z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...m7(r)});class hY extends m8{_parse(t){if(this._getType(t)!==mK.nan){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.nan,received:r.parsedType}),m2}return{status:"valid",value:t.data}}}hY.create=t=>new hY({typeName:z.ZodNaN,...m7(t)}),Symbol("zod_brand");class hX extends m8{_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 hQ extends m8{_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?m2:"dirty"===t.status?(r.dirty(),m9(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?m2:"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 hQ({in:t,out:r,typeName:z.ZodPipeline})}}class h0 extends m8{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return m3(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}h0.create=(t,r)=>new h0({innerType:t,typeName:z.ZodReadonly,...m7(r)}),hj.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",hy.create,hv.create,hY.create,h_.create,hb.create,hS.create,h$.create,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create,hT.create,hj.create,hj.strictCreate,hO.create,hI.create,hN.create,hq.create,hA.create,hM.create,hz.create,hL.create,hZ.create,hD.create,hV.create,hF.create,hH.create,hJ.create,hB.create,hK.create,hJ.createWithPreprocess,hQ.create;let h1=(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 h2(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?h1(r,t.currentPath):r.join("/")}}function h9(t,r,a,n){n?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function h4(t,r,a,n,i){t[r]=a,h9(t,r,n,i)}function h3(t,r){return fg(t.type._def,r)}let h6=/^[cC][^\s-]{8,}$/,h5=/^[0-9a-z]+$/,h7=/^[0-9A-HJKMNP-TV-Z]{26}$/,h8=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,fe=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),ft=/^(?:(?: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])$/,fr=/^(([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])$/,fa=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fi=/^[a-zA-Z0-9_-]{21}$/,fo=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fs(t,r){let a={type:"string"};if(t.checks)for(let n of t.checks)switch(n.kind){case"min":h4(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,n.value):n.value,n.message,r);break;case"max":h4(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,n.value):n.value,n.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fu(a,"email",n.message,r);break;case"format:idn-email":fu(a,"idn-email",n.message,r);break;case"pattern:zod":fd(a,h8,n.message,r)}break;case"url":fu(a,"uri",n.message,r);break;case"uuid":fu(a,"uuid",n.message,r);break;case"regex":fd(a,n.regex,n.message,r);break;case"cuid":fd(a,h6,n.message,r);break;case"cuid2":fd(a,h5,n.message,r);break;case"startsWith":fd(a,RegExp(`^${fl(n.value,r)}`),n.message,r);break;case"endsWith":fd(a,RegExp(`${fl(n.value,r)}$`),n.message,r);break;case"datetime":fu(a,"date-time",n.message,r);break;case"date":fu(a,"date",n.message,r);break;case"time":fu(a,"time",n.message,r);break;case"duration":fu(a,"duration",n.message,r);break;case"length":h4(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,n.value):n.value,n.message,r),h4(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,n.value):n.value,n.message,r);break;case"includes":fd(a,RegExp(fl(n.value,r)),n.message,r);break;case"ip":"v6"!==n.version&&fu(a,"ipv4",n.message,r),"v4"!==n.version&&fu(a,"ipv6",n.message,r);break;case"base64url":fd(a,fn,n.message,r);break;case"jwt":fd(a,fo,n.message,r);break;case"cidr":"v6"!==n.version&&fd(a,ft,n.message,r),"v4"!==n.version&&fd(a,fr,n.message,r);break;case"emoji":fd(a,fe(),n.message,r);break;case"ulid":fd(a,h7,n.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fu(a,"binary",n.message,r);break;case"contentEncoding:base64":h4(a,"contentEncoding","base64",n.message,r);break;case"pattern:zod":fd(a,fa,n.message,r)}break;case"nanoid":fd(a,fi,n.message,r)}return a}function fl(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 fu(t,r,a,n){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&n.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&&n.errorMessages&&{errorMessage:{format:a}}})):h4(t,"format",r,a,n)}function fd(t,r,a,n){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&n.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:fp(r,n),...a&&n.errorMessages&&{errorMessage:{pattern:a}}})):h4(t,"pattern",fp(r,n),a,n)}function fp(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")},n=a.i?t.source.toLowerCase():t.source,i="",o=!1,s=!1,l=!1;for(let t=0;t<n.length;t++){if(o){i+=n[t],o=!1;continue}if(a.i){if(s){if(n[t].match(/[a-z]/)){l?(i+=n[t],i+=`${n[t-2]}-${n[t]}`.toUpperCase(),l=!1):"-"===n[t+1]&&n[t+2]?.match(/[a-z]/)?(i+=n[t],l=!0):i+=`${n[t]}${n[t].toUpperCase()}`;continue}}else if(n[t].match(/[a-z]/)){i+=`[${n[t]}${n[t].toUpperCase()}]`;continue}}if(a.m){if("^"===n[t]){i+=`(^|(?<=[\r
|
|
77
|
+
`,t.enqueue(r.encode(i)),!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,n,i,o,s,l=t.headers.get("accept");if(!l?.includes("application/json")||!l.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(t.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(r?.parsedBody===void 0)try{let r=await p0(t,this._maxRequestBodySize);if(r.tooLarge){let t=pX(this._maxRequestBodySize);return this.onerror?.(Error(t)),this.createJsonErrorResponse(413,-32e3,t)}a=JSON.parse(r.text)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else a=r.parsedBody;if(Array.isArray(a)&&a.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{n=Array.isArray(a)?a.map(t=>ol.parse(t)):[ol.parse(a)]}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let c=n.some(t=>ow.safeParse(t).success);if(c){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(n.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{i=await this._checkScopeChallenge(n,r?.authInfo)}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!n.some(t=>cK(t))){for(let a of n)this.onmessage?.(a,{authInfo:r?.authInfo,request:t});return new Response(null,{status:202})}let u=crypto.randomUUID(),d=n.find(t=>ow.safeParse(t).success),p=d?d.params.protocolVersion:t.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(a=>{for(let t of(this._streamMapping.set(u,{resolveJson:a,cleanup:()=>{this._streamMapping.delete(u)}}),n))cK(t)&&this._requestToStreamMapping.set(t.id,u);for(let a of n)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),n))cK(t)&&(this._streamMapping.set(u,{controller:o,encoder:m,cleanup:()=>{void 0!==s&&clearInterval(s),this._streamMapping.delete(u);try{o.close()}catch{}}}),this._requestToStreamMapping.set(t.id,u));for(let a of(await this.writePrimingEvent(o,m,u,p),n)){let n,i;cK(a)&&this._eventStore&&this.supportsEmptySSEData(p)&&(n=()=>{this.closeSSEStream(a.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(a,{authInfo:r?.authInfo,request:t,closeSSEStream:n,closeStandaloneSSEStream:i})}return this._streamMapping.get(u)?.controller===o&&(s=this.startKeepAlive(o,m)),new Response(h,{status:200,headers:f})}catch(t){return this.onerror?.(t),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(t)})}}async handleDeleteRequest(t){let r=this.validateSession(t);if(r)return r;let a=this.validateProtocolVersion(t);if(a)return a;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(t){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let r=t.headers.get("mcp-session-id");return r?r!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(t){let r=t.headers.get("mcp-protocol-version");if(null!==r&&!this._supportedProtocolVersions.includes(r)){let t=`Bad Request: Unsupported protocol version: ${r} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(t)),this.createJsonErrorResponse(400,-32e3,t)}}async close(){if(!this._closed){for(let{cleanup:t}of(this._closed=!0,this._streamMapping.values()))t();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(t){let r=this._requestToStreamMapping.get(t);if(!r)return;let a=this._streamMapping.get(r);a&&a.cleanup()}closeStandaloneSSEStream(){let t=this._streamMapping.get(this._standaloneSseStreamId);t&&t.cleanup()}async send(t,r){let a=r?.relatedRequestId;if((cW(t)||cY(t))&&(a=t.id),void 0===a){let r;if(cW(t)||cY(t))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(r=await this._eventStore.storeEvent(this._standaloneSseStreamId,t));let a=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===a)return;a.controller&&a.encoder&&(void 0===r||!a.replayedEventIds?.has(r))&&this.writeSSEEvent(a.controller,a.encoder,t,r);return}let n=this._requestToStreamMapping.get(a);if(!n)throw Error(`No connection established for request ID: ${String(a)}`);let i=this._streamMapping.get(n);if(!this._enableJsonResponse){let r;this._eventStore&&(r=await this._eventStore.storeEvent(n,t),i=this._streamMapping.get(n)),i?.controller&&i?.encoder&&(void 0===r||!i.replayedEventIds?.has(r))&&this.writeSSEEvent(i.controller,i.encoder,t,r)}if(cW(t)||cY(t)){this._requestResponseMap.set(a,t);let r=[...this._requestToStreamMapping.entries()].filter(([t,r])=>r===n).map(([t])=>t);if(r.every(t=>this._requestResponseMap.has(t))){if(!i){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&&i.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?i.resolveJson(Response.json(a[0],{status:200,headers:t})):i.resolveJson(Response.json(a,{status:200,headers:t})),i.cleanup()}else i.cleanup();for(let t of r)this._requestResponseMap.delete(t),this._requestToStreamMapping.delete(t)}}}};function p2(t){if(null===t||"object"!=typeof t||Array.isArray(t))return null;let{method:r,id:a}=t;return"string"!=typeof r?null:"string"==typeof a||"number"==typeof a?a:null}function p9(t,r,a,n,i=null){return Response.json({jsonrpc:"2.0",error:{code:r,message:a,...void 0!==n&&{data:n}},id:i},{status:t})}function p4(t,r=null){return p9(t.httpStatus,t.code,t.message,t.data,r)}function p3(t){return t instanceof Error?t:Error(String(t))}function p6(t=null){return p9(500,-32603,"Internal server error",void 0,t)}function p5(t){if(void 0!==t.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p7(t){return{protocolVersionHeader:t.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:t.headers.get("mcp-method")??void 0,mcpNameHeader:t.headers.get("mcp-name")??void 0}}async function p8(t,r,a=!0,n=4194304){let i,o=t.method.toUpperCase(),s=r,l=t,c=!1;if("POST"===o){if(void 0===s){let r;a&&(l=t.clone());try{let a=await p0(t,n);if(a.tooLarge)return{step:"body-too-large"};r=a.text}catch{return{step:"unreadable-body"}}try{i=0===r.length?void 0:JSON.parse(r)}catch{c=!0}c||void 0===i||(s=i)}else i=s;if(c||void 0===i)return{step:"no-json-body",forwardRequest:l}}return{step:"classified",outcome:function(t){if("POST"!==(t={...t,...void 0!==t.protocolVersionHeader&&{protocolVersionHeader:ui(t.protocolVersionHeader)},...void 0!==t.mcpMethodHeader&&{mcpMethodHeader:ui(t.mcpMethodHeader)},...void 0!==t.mcpNameHeader&&{mcpNameHeader:ui(t.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let r=t.body;if(Array.isArray(r)){if(0===r.length)return ur("jsonrpc-shape","empty-batch",400,new cg(cf.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let t of r){if(cF(uo(t)?t.params:void 0))return ur("jsonrpc-shape","batch-with-modern-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cK(t)||cG(t)||cW(t)||cY(t)))return ur("jsonrpc-shape","batch-with-invalid-element",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cW(r)||cY(r)?{kind:"legacy",reason:"response"}:uo(r)&&cK(r)?function(t,r){let a=r.params,n=r.method,i=t.protocolVersionHeader,o=void 0!==i&&i>=lW;if("initialize"===n&&!function(t){if(!cF(t))return!1;let r=cH(t);if(void 0===r||!(r>=lW))return!1;let a=cV(t);return void 0!==a&&0===cJ(a).length}(a)){if(o)return ua("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let t=uo(a)&&"string"==typeof a.protocolVersion?a.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==t&&{requestedVersion:t}}}if(cF(a)){let o=cV(a),s=(void 0===o?[]:cJ(o))[0];if(void 0!==s)return ur("envelope","envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${s.key}: ${s.problem}`,{envelope:s}),!0);let l=cH(a);return void 0!==i&&void 0!==l&&i!==l?ua("header-body-version-mismatch",i,`the body envelope names protocol version ${l} but the MCP-Protocol-Version header names ${i}`):void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("method-header-mismatch",t.mcpMethodHeader,`the body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:r,classification:us(l)}}if(o){let t=cV(a),r=cJ(t??{}).filter(t=>"missing"===t.problem).map(t=>t.key),n=void 0===t?["_meta"]:r.length>0?r:[iJ];return ur("envelope","modern-header-without-claim",400,new cg(cf.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${n.join(", ")}`,{envelope:{missing:n}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(t,r):uo(r)&&cG(r)?function(t,r){let a=r.params,n=r.method,i=t.protocolVersionHeader,o=void 0!==i&&i>=lW;if(cF(a)){let o=cH(a);if(void 0===o){let t=cV(a),r=(void 0===t?[]:cJ(t)).find(t=>t.key===iJ)??{key:iJ,problem:"expected a protocol version string"};return ur("envelope","notification-envelope-invalid",400,new cg(cf.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${r.key}: ${r.problem}`,{envelope:r}),!0)}if(void 0!==i&&i!==o)return ua("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${o} but the MCP-Protocol-Version header names ${i}`);let s=us(o);return"modern"===s.era&&void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:s}}return o?void 0!==t.mcpMethodHeader&&t.mcpMethodHeader!==n?ua("notification-method-header-mismatch",t.mcpMethodHeader,`the notification body names method ${n} but the Mcp-Method header names ${t.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:r,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(t,r):ur("jsonrpc-shape","invalid-json-rpc-body",400,new cg(cf.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:o,...p7(t),...void 0!==i&&{body:i}}),body:i,parsedBody:s,forwardRequest:l}}let me=require("async_hooks"),mt=(t,r)=>{globalThis[t]=r},mr=t=>globalThis[t];function ma({name:t,fallback:r=!0}){let a=Symbol.for(`xmcp-context-${t}`),n=Symbol.for(`xmcp-context-${t}-fallback-store`);if(mr(a))return mr(a);let i=new me.AsyncLocalStorage,o=globalThis[n]??{current:null};mt(n,o);let s={provider:(t,a)=>(r&&(o.current=t),i.run(t,a)),getContext:()=>{let a=i.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 n=i.getStore()??(r?o.current:null);if(!n)throw Error(`setContext() can only be used within the ${t} context.`);Object.assign(n,a)}};return mt(a,s),s}let mn=ma({name:"http-request-context"}),mi=mn.setContext,mo=mn.getContext,ms=mn.provider,ml=t=>"object"==typeof t&&null!==t&&!Array.isArray(t),mc=t=>{if(!ml(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},mu=t=>{if(t&&"initialize"===t.method&&ml(t.params))return mc(t.params.clientInfo)},md=(t,r)=>{let a=r.toLowerCase();for(let[r,n]of Object.entries(t)){if(r.toLowerCase()!==a)continue;let t=Array.isArray(n)?n[0]:n;if("string"!=typeof t)break;let i=t.trim();return i.length>0?i:void 0}};function mp(t){let{tags:r,enabled:a,...n}=t;return{...n,_meta:void 0===r?n._meta:{...n._meta,"xmcp/tags":r}}}let mm=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)}},mh=ma({name:"request-context",fallback:!1}),mf=ma({name:"client-info-context"});mf.setContext;let mg=mf.getContext;mf.provider;let my=new Set(["message","mode","requestedSchema"]),mv=new Set(["elicitationId","message","mode","url"]),m_=new Set(["properties","required","type"]),mb=new Set(["default","description","format","maxLength","minLength","title","type"]),mS=new Set(["default","description","enum","enumNames","title","type"]),m$=new Set(["default","description","title","type"]),mw=new Set(["default","description","maximum","minimum","title","type"]),mR=new Set(["date","date-time","email","uri"]);async function mk(t,r,a){let n=function(t){let r=t.mode??"form";if("url"===r)return function(t){let r;mP(t,"Elicitation request must be a plain object."),mx(t,mv,"URL elicitation"),mE(t.message,"URL elicitation requires a string message."),mT(t.elicitationId,"URL elicitation requires a non-empty elicitationId."),mT(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){mP(t,"Elicitation request must be a plain object."),mx(t,my,"Form elicitation"),mE(t.message,"Form elicitation requires a string message.");let r=t.requestedSchema;if(mP(r,"Form elicitation requires a flat object schema."),mx(r,m_,"Form elicitation schema"),"object"!==r.type)throw Error('Form elicitation schema must use type "object".');for(let[t,a]of(mP(r.properties,"Form elicitation schema requires a properties object."),Object.entries(r.properties)))!function(t,r){if(mP(r,`Form elicitation field "${t}" must be a plain object.`),mj(r.title,`Form elicitation field "${t}" title must be a string.`),mj(r.description,`Form elicitation field "${t}" description must be a string.`),"string"===r.type&&"enum"in r){var a,n;if(mx(r,mS,`Form elicitation field "${t}"`),mC(r.enum,`Form elicitation field "${t}" enum values must be strings.`),a=r.enumNames,n=`Form elicitation field "${t}" enumNames must be strings.`,void 0!==a&&mC(a,n),void 0!==r.enumNames&&r.enumNames.length!==r.enum.length)throw Error(`Form elicitation field "${t}" enumNames length must match enum length.`);if(mj(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)){mx(r,mb,`Form elicitation field "${t}"`),mO(r.minLength,`Form elicitation field "${t}" minLength must be a number.`),mO(r.maxLength,`Form elicitation field "${t}" maxLength must be a number.`),mj(r.default,`Form elicitation field "${t}" default must be a string.`);let a=r.format;if(mj(a,`Form elicitation field "${t}" format must be a string.`),void 0!==a&&!mR.has(a))throw Error(`Form elicitation field "${t}" format must be one of: ${Array.from(mR).join(", ")}.`);return}if("boolean"===r.type){if(mx(r,m$,`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){mx(r,mw,`Form elicitation field "${t}"`),mO(r.minimum,`Form elicitation field "${t}" minimum must be a number.`),mO(r.maximum,`Form elicitation field "${t}" maximum must be a number.`),mO(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(n,a);return{...r,content:r.content??void 0}}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mx(t,r,a){let n=Object.keys(t).filter(t=>!r.has(t));if(0!==n.length)throw Error(`${a} includes unsupported key(s): ${n.join(", ")}.`)}function mP(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}function mE(t,r){if("string"!=typeof t)throw Error(r)}function mT(t,r){if("string"!=typeof t||0===t.trim().length)throw Error(r)}function mj(t,r){if(void 0!==t&&"string"!=typeof t)throw Error(r)}function mO(t,r){if(void 0!==t&&"number"!=typeof t)throw Error(r)}function mC(t,r){if(!Array.isArray(t)||t.some(t=>"string"!=typeof t))throw Error(r)}let mI=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mN=new Set(["task","toolChoice","tools"]),mq=new Set(["text","image","audio"]);async function mA(t,r,a){let n=function(t){mM(t,"Sampling request must be a plain object.");let r=Object.keys(t),a=r.filter(t=>mN.has(t));if(a.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${a.join(", ")}.`);let n=r.filter(t=>!mI.has(t));if(n.length>0)throw Error(`Sampling request includes unsupported key(s): ${n.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(mM(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;mM(a,`Sampling message at index ${t} requires a content object.`);let n=a.type;if("string"!=typeof n||!mq.has(n))throw Error(`Sampling message at index ${t} uses unsupported content type "${String(n)}". Supported types are text, image, and audio.`);if("text"===n&&"string"!=typeof a.text)throw Error(`Sampling message at index ${t} requires string text content.`);if(("image"===n||"audio"===n)&&("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(n,a)}catch(t){if(t instanceof lJ&&t.code===lH.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw t}}function mM(t,r){if("object"!=typeof t||null===t||Array.isArray(t))throw Error(r)}let mz={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 mL(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=mz[t.type];return r?r(t):{valid:!0}}function mZ(t,r,a,n){if(null===t||"object"!=typeof t||Array.isArray(t))throw Error(`Tool "${a}" ${n}: expected a plain object.`);let i=new Set(Object.keys(r)),o=Object.keys(t).filter(t=>!i.has(t));if(o.length>0)throw Error(`Tool "${a}" ${n}: unrecognized key(s): ${o.join(", ")}`);for(let[i,o]of Object.entries(r))try{o.parse(t[i])}catch(t){throw Error(`Tool "${a}" ${n}: ${t?.message??`invalid field "${i}"`}`)}}function mD(t){return!!(t&&"object"==typeof t&&Object.keys(t).some(t=>t.startsWith("ui/")))}function mU(t){let r=t.mcpReq.envelope,a=mc(r?.[iB]);if(!a)try{let t,r=mo();a=r.clientInfo??(t=r.headers,mc({name:md(t,"x-mcp-client-name"),version:md(t,"x-mcp-client-version"),title:md(t,"x-mcp-client-title"),websiteUrl:md(t,"x-mcp-client-website-url"),description:md(t,"x-mcp-client-description")}))}catch{}if(!a)try{a=mg().clientInfo}catch{}return a}function mV(t){let r=[...t];return(t,a,n)=>(function(t,r,a){let n,i=new Map;if(t.http){let t=mo(),r=Object.fromEntries(Object.entries(t.headers).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):r]));n=Object.freeze({id:t.id,headers:Object.freeze(r)})}return mh.provider(Object.freeze({clientInfo:r?Object.freeze({...r}):void 0,http:n,authInfo:t.http?.authInfo,signal:t.mcpReq.signal,set(t,r){i.set(t,r)},get:t=>i.get(t),async progress(r,a){let n=t.mcpReq._meta?.progressToken;void 0!==n&&await t.mcpReq.notify({method:"notifications/progress",params:{progressToken:n,progress:r,...void 0===a?{}:{total:a}}})},log:(r,a)=>t.mcpReq.log(r,a)}),a)})(a,mU(a),async()=>{if(0===r.length)return n();let a=Object.freeze({...function(){try{return mh.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...t,params:Object.freeze({...t.params})}),i=-1,o=async t=>{if(t<=i)throw Error("MCP middleware next() can only be called once");i=t;let s=r[t];return s?s(a,()=>o(t+1)):n()};return o(0)})}let mF=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mH(t){return t.endsWith(".tsx")}let mJ=Symbol("Let zodToJsonSchema decide on which parser to use"),mB={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=t=>{},T.assertIs=function(t){},T.assertNever=function(t){throw Error()},T.arrayToEnum=t=>{let r={};for(let a of t)r[a]=a;return r},T.getValidEnumValues=t=>{let r=T.objectKeys(t).filter(r=>"number"!=typeof t[t[r]]),a={};for(let n of r)a[n]=t[n];return T.objectValues(a)},T.objectValues=t=>T.objectKeys(t).map(function(r){return t[r]}),T.objectKeys="function"==typeof Object.keys?t=>Object.keys(t):t=>{let r=[];for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&r.push(a);return r},T.find=(t,r)=>{for(let a of t)if(r(a))return a},T.isInteger="function"==typeof Number.isInteger?t=>Number.isInteger(t):t=>"number"==typeof t&&Number.isFinite(t)&&Math.floor(t)===t,T.joinValues=function(t,r=" | "){return t.map(t=>"string"==typeof t?`'${t}'`:t).join(r)},T.jsonStringifyReplacer=(t,r)=>"bigint"==typeof r?r.toString():r,(A||(A={})).mergeShapes=(t,r)=>({...t,...r});let mK=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mG=t=>{switch(typeof t){case"undefined":return mK.undefined;case"string":return mK.string;case"number":return Number.isNaN(t)?mK.nan:mK.number;case"boolean":return mK.boolean;case"function":return mK.function;case"bigint":return mK.bigint;case"symbol":return mK.symbol;case"object":if(Array.isArray(t))return mK.array;if(null===t)return mK.null;if(t.then&&"function"==typeof t.then&&t.catch&&"function"==typeof t.catch)return mK.promise;if("undefined"!=typeof Map&&t instanceof Map)return mK.map;if("undefined"!=typeof Set&&t instanceof Set)return mK.set;if("undefined"!=typeof Date&&t instanceof Date)return mK.date;return mK.object;default:return mK.unknown}},mW=q.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class mY 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:[]},n=t=>{for(let i of t.issues)if("invalid_union"===i.code)i.unionErrors.map(n);else if("invalid_return_type"===i.code)n(i.returnTypeError);else if("invalid_arguments"===i.code)n(i.argumentsError);else if(0===i.path.length)a._errors.push(r(i));else{let t=a,n=0;for(;n<i.path.length;){let a=i.path[n],o=n===i.path.length-1;if("_errors"===a){o&&t._errors.push(r(i)),n++;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(i)),n++}}};return n(this),a}static assert(t){if(!(t instanceof mY))throw Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(t=t=>t.message){let r=Object.create(null),a=[];for(let n of this.issues)if(n.path.length>0){let a=n.path[0];r[a]=r[a]||[],r[a].push(t(n))}else a.push(t(n));return{formErrors:a,fieldErrors:r}}get formErrors(){return this.flatten()}}mY.create=t=>new mY(t);let mX=(t,r)=>{let a;switch(t.code){case mW.invalid_type:a=t.received===mK.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case mW.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,q.jsonStringifyReplacer)}`;break;case mW.unrecognized_keys:a=`Unrecognized key(s) in object: ${q.joinValues(t.keys,", ")}`;break;case mW.invalid_union:a="Invalid input";break;case mW.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${q.joinValues(t.options)}`;break;case mW.invalid_enum_value:a=`Invalid enum value. Expected ${q.joinValues(t.options)}, received '${t.received}'`;break;case mW.invalid_arguments:a="Invalid function arguments";break;case mW.invalid_return_type:a="Invalid function return type";break;case mW.invalid_date:a="Invalid date";break;case mW.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:q.assertNever(t.validation):a="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case mW.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 mW.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 mW.custom:a="Invalid input";break;case mW.invalid_intersection_types:a="Intersection results could not be merged";break;case mW.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case mW.not_finite:a="Number must be finite";break;default:a=r.defaultError,q.assertNever(t)}return{message:a}};(j=M||(M={})).errToObj=t=>"string"==typeof t?{message:t}:t||{},j.toString=t=>"string"==typeof t?t:t?.message;let mQ=t=>{let{data:r,path:a,errorMaps:n,issueData:i}=t,o=[...a,...i.path||[]],s={...i,path:o};if(void 0!==i.message)return{...i,path:o,message:i.message};let l="";for(let t of n.filter(t=>!!t).slice().reverse())l=t(s,{data:r,defaultError:l}).message;return{...i,path:o,message:l}};function m0(t,r){let a=mQ({issueData:r,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mX,void 0].filter(t=>!!t)});t.common.issues.push(a)}class m1{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 n of r){if("aborted"===n.status)return m2;"dirty"===n.status&&t.dirty(),a.push(n.value)}return{status:t.value,value:a}}static async mergeObjectAsync(t,r){let a=[];for(let t of r){let r=await t.key,n=await t.value;a.push({key:r,value:n})}return m1.mergeObjectSync(t,a)}static mergeObjectSync(t,r){let a={};for(let n of r){let{key:r,value:i}=n;if("aborted"===r.status||"aborted"===i.status)return m2;"dirty"===r.status&&t.dirty(),"dirty"===i.status&&t.dirty(),"__proto__"!==r.value&&(void 0!==i.value||n.alwaysSet)&&(a[r.value]=i.value)}return{status:t.value,value:a}}}let m2=Object.freeze({status:"aborted"}),m9=t=>({status:"dirty",value:t}),m4=t=>({status:"valid",value:t}),m3=t=>"undefined"!=typeof Promise&&t instanceof Promise;class m6{constructor(t,r,a,n){this._cachedPath=[],this.parent=t,this.data=r,this._path=a,this._key=n}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 m5=(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 mY(t.common.issues);return this._error=r,this._error}}};function m7(t){if(!t)return{};let{errorMap:r,invalid_type_error:a,required_error:n,description:i}=t;if(r&&(a||n))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return r?{errorMap:r,description:i}:{errorMap:(r,i)=>{let{message:o}=t;return"invalid_enum_value"===r.code?{message:o??i.defaultError}:void 0===i.data?{message:o??n??i.defaultError}:"invalid_type"!==r.code?{message:i.defaultError}:{message:o??a??i.defaultError}},description:i}}class m8{get description(){return this._def.description}_getType(t){return mG(t.data)}_getOrReturnCtx(t,r){return r||{common:t.parent.common,data:t.data,parsedType:mG(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new m1,ctx:{common:t.parent.common,data:t.data,parsedType:mG(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let r=this._parse(t);if(m3(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:mG(t)},n=this._parseSync({data:t,path:a.path,parent:a});return m5(a,n)}"~validate"(t){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:mG(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:mG(t)},n=this._parse({data:t,path:a.path,parent:a});return m5(a,await (m3(n)?n:Promise.resolve(n)))}refine(t,r){return this._refinement((a,n)=>{let i=t(a),o=()=>n.addIssue({code:mW.custom,..."string"==typeof r||void 0===r?{message:r}:"function"==typeof r?r(a):r});return"undefined"!=typeof Promise&&i instanceof Promise?i.then(t=>!!t||(o(),!1)):!!i||(o(),!1)})}refinement(t,r){return this._refinement((a,n)=>!!t(a)||(n.addIssue("function"==typeof r?r(a,n):r),!1))}_refinement(t){return new hJ({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 hB.create(this,this._def)}nullable(){return hK.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hT.create(this)}promise(){return hH.create(this,this._def)}or(t){return hO.create([this,t],this._def)}and(t){return hN.create(this,t,this._def)}transform(t){return new hJ({...m7(this._def),schema:this,typeName:z.ZodEffects,effect:{type:"transform",transform:t}})}default(t){return new hG({...m7(this._def),innerType:this,defaultValue:"function"==typeof t?t:()=>t,typeName:z.ZodDefault})}brand(){return new hX({typeName:z.ZodBranded,type:this,...m7(this._def)})}catch(t){return new hW({...m7(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 hQ.create(this,t)}readonly(){return h0.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let he=/^c[^\s-]{8,}$/i,ht=/^[0-9a-z]+$/,hr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ha=/^[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,hn=/^[a-z0-9_-]{21}$/i,hi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ho=/^[-+]?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)?)??$/,hs=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,hl=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,hc=/^(?:(?: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])$/,hu=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hd=/^(([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])$/,hp=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hm=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hh="((\\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])))",hf=RegExp(`^${hh}$`);function hg(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 hy extends m8{_parse(t){var r,a,n,i;let o;if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==mK.string){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.string,received:r.parsedType}),m2}let s=new m1;for(let l of this._def.checks)if("min"===l.kind)t.data.length<l.value&&(m0(o=this._getOrReturnCtx(t,o),{code:mW.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&&(m0(o=this._getOrReturnCtx(t,o),{code:mW.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?m0(o,{code:mW.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):a&&m0(o,{code:mW.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),s.dirty())}else if("email"===l.kind)hs.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"email",code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{validation:"emoji",code:mW.invalid_string,message:l.message}),s.dirty());else if("uuid"===l.kind)ha.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"uuid",code:mW.invalid_string,message:l.message}),s.dirty());else if("nanoid"===l.kind)hn.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"nanoid",code:mW.invalid_string,message:l.message}),s.dirty());else if("cuid"===l.kind)he.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"cuid",code:mW.invalid_string,message:l.message}),s.dirty());else if("cuid2"===l.kind)ht.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"cuid2",code:mW.invalid_string,message:l.message}),s.dirty());else if("ulid"===l.kind)hr.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"ulid",code:mW.invalid_string,message:l.message}),s.dirty());else if("url"===l.kind)try{new URL(t.data)}catch{m0(o=this._getOrReturnCtx(t,o),{validation:"url",code:mW.invalid_string,message:l.message}),s.dirty()}else"regex"===l.kind?(l.regex.lastIndex=0,l.regex.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"regex",code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:{startsWith:l.value},message:l.message}),s.dirty()):"endsWith"===l.kind?t.data.endsWith(l.value)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:{endsWith:l.value},message:l.message}),s.dirty()):"datetime"===l.kind?(function(t){let r=`${hh}T${hg(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)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"datetime",message:l.message}),s.dirty()):"date"===l.kind?hf.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"date",message:l.message}),s.dirty()):"time"===l.kind?RegExp(`^${hg(l)}$`).test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{code:mW.invalid_string,validation:"time",message:l.message}),s.dirty()):"duration"===l.kind?ho.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"duration",code:mW.invalid_string,message:l.message}),s.dirty()):"ip"===l.kind?(r=t.data,!(("v4"===(a=l.version)||!a)&&hl.test(r)||("v6"===a||!a)&&hu.test(r))&&1&&(m0(o=this._getOrReturnCtx(t,o),{validation:"ip",code:mW.invalid_string,message:l.message}),s.dirty())):"jwt"===l.kind?!function(t,r){if(!hi.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let n=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),i=JSON.parse(atob(n));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||r&&i.alg!==r)return!1;return!0}catch{return!1}}(t.data,l.alg)&&(m0(o=this._getOrReturnCtx(t,o),{validation:"jwt",code:mW.invalid_string,message:l.message}),s.dirty()):"cidr"===l.kind?(n=t.data,!(("v4"===(i=l.version)||!i)&&hc.test(n)||("v6"===i||!i)&&hd.test(n))&&1&&(m0(o=this._getOrReturnCtx(t,o),{validation:"cidr",code:mW.invalid_string,message:l.message}),s.dirty())):"base64"===l.kind?hp.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"base64",code:mW.invalid_string,message:l.message}),s.dirty()):"base64url"===l.kind?hm.test(t.data)||(m0(o=this._getOrReturnCtx(t,o),{validation:"base64url",code:mW.invalid_string,message:l.message}),s.dirty()):q.assertNever(l);return{status:s.value,value:t.data}}_regex(t,r,a){return this.refinement(r=>t.test(r),{validation:r,code:mW.invalid_string,...M.errToObj(a)})}_addCheck(t){return new hy({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...M.errToObj(t)})}url(t){return this._addCheck({kind:"url",...M.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...M.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...M.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...M.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...M.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...M.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...M.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...M.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...M.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...M.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...M.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...M.errToObj(t)})}datetime(t){return"string"==typeof t?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:void 0===t?.precision?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...M.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return"string"==typeof t?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:void 0===t?.precision?null:t?.precision,...M.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...M.errToObj(t)})}regex(t,r){return this._addCheck({kind:"regex",regex:t,...M.errToObj(r)})}includes(t,r){return this._addCheck({kind:"includes",value:t,position:r?.position,...M.errToObj(r?.message)})}startsWith(t,r){return this._addCheck({kind:"startsWith",value:t,...M.errToObj(r)})}endsWith(t,r){return this._addCheck({kind:"endsWith",value:t,...M.errToObj(r)})}min(t,r){return this._addCheck({kind:"min",value:t,...M.errToObj(r)})}max(t,r){return this._addCheck({kind:"max",value:t,...M.errToObj(r)})}length(t,r){return this._addCheck({kind:"length",value:t,...M.errToObj(r)})}nonempty(t){return this.min(1,M.errToObj(t))}trim(){return new hy({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hy({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hy({...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}}hy.create=t=>new hy({checks:[],typeName:z.ZodString,coerce:t?.coerce??!1,...m7(t)});class hv extends m8{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)!==mK.number){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.number,received:r.parsedType}),m2}let a=new m1;for(let n of this._def.checks)"int"===n.kind?q.isInteger(t.data)||(m0(r=this._getOrReturnCtx(t,r),{code:mW.invalid_type,expected:"integer",received:"float",message:n.message}),a.dirty()):"min"===n.kind?(n.inclusive?t.data<n.value:t.data<=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),a.dirty()):"max"===n.kind?(n.inclusive?t.data>n.value:t.data>=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),a.dirty()):"multipleOf"===n.kind?0!==function(t,r){let a=(t.toString().split(".")[1]||"").length,n=(r.toString().split(".")[1]||"").length,i=a>n?a:n;return Number.parseInt(t.toFixed(i).replace(".",""))%Number.parseInt(r.toFixed(i).replace(".",""))/10**i}(t.data,n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_multiple_of,multipleOf:n.value,message:n.message}),a.dirty()):"finite"===n.kind?Number.isFinite(t.data)||(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_finite,message:n.message}),a.dirty()):q.assertNever(n);return{status:a.value,value:t.data}}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,n){return new hv({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(n)}]})}_addCheck(t){return new hv({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:M.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}finite(t){return this._addCheck({kind:"finite",message:M.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:M.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:M.toString(t)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&q.isInteger(t.value))}get isFinite(){let t=null,r=null;for(let a of this._def.checks)if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;else"min"===a.kind?(null===r||a.value>r)&&(r=a.value):"max"===a.kind&&(null===t||a.value<t)&&(t=a.value);return Number.isFinite(r)&&Number.isFinite(t)}}hv.create=t=>new hv({checks:[],typeName:z.ZodNumber,coerce:t?.coerce||!1,...m7(t)});class h_ extends m8{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)!==mK.bigint)return this._getInvalidInput(t);let a=new m1;for(let n of this._def.checks)"min"===n.kind?(n.inclusive?t.data<n.value:t.data<=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),a.dirty()):"max"===n.kind?(n.inclusive?t.data>n.value:t.data>=n.value)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),a.dirty()):"multipleOf"===n.kind?t.data%n.value!==BigInt(0)&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.not_multiple_of,multipleOf:n.value,message:n.message}),a.dirty()):q.assertNever(n);return{status:a.value,value:t.data}}_getInvalidInput(t){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.bigint,received:r.parsedType}),m2}gte(t,r){return this.setLimit("min",t,!0,M.toString(r))}gt(t,r){return this.setLimit("min",t,!1,M.toString(r))}lte(t,r){return this.setLimit("max",t,!0,M.toString(r))}lt(t,r){return this.setLimit("max",t,!1,M.toString(r))}setLimit(t,r,a,n){return new h_({...this._def,checks:[...this._def.checks,{kind:t,value:r,inclusive:a,message:M.toString(n)}]})}_addCheck(t){return new h_({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:M.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:M.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:M.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:M.toString(t)})}multipleOf(t,r){return this._addCheck({kind:"multipleOf",value:t,message:M.toString(r)})}get minValue(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return t}get maxValue(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return t}}h_.create=t=>new h_({checks:[],typeName:z.ZodBigInt,coerce:t?.coerce??!1,...m7(t)});class hb extends m8{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==mK.boolean){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.boolean,received:r.parsedType}),m2}return m4(t.data)}}hb.create=t=>new hb({typeName:z.ZodBoolean,coerce:t?.coerce||!1,...m7(t)});class hS extends m8{_parse(t){let r;if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==mK.date){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.date,received:r.parsedType}),m2}if(Number.isNaN(t.data.getTime()))return m0(this._getOrReturnCtx(t),{code:mW.invalid_date}),m2;let a=new m1;for(let n of this._def.checks)"min"===n.kind?t.data.getTime()<n.value&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),a.dirty()):"max"===n.kind?t.data.getTime()>n.value&&(m0(r=this._getOrReturnCtx(t,r),{code:mW.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),a.dirty()):q.assertNever(n);return{status:a.value,value:new Date(t.data.getTime())}}_addCheck(t){return new hS({...this._def,checks:[...this._def.checks,t]})}min(t,r){return this._addCheck({kind:"min",value:t.getTime(),message:M.toString(r)})}max(t,r){return this._addCheck({kind:"max",value:t.getTime(),message:M.toString(r)})}get minDate(){let t=null;for(let r of this._def.checks)"min"===r.kind&&(null===t||r.value>t)&&(t=r.value);return null!=t?new Date(t):null}get maxDate(){let t=null;for(let r of this._def.checks)"max"===r.kind&&(null===t||r.value<t)&&(t=r.value);return null!=t?new Date(t):null}}hS.create=t=>new hS({checks:[],coerce:t?.coerce||!1,typeName:z.ZodDate,...m7(t)});class h$ extends m8{_parse(t){if(this._getType(t)!==mK.symbol){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.symbol,received:r.parsedType}),m2}return m4(t.data)}}h$.create=t=>new h$({typeName:z.ZodSymbol,...m7(t)});class hw extends m8{_parse(t){if(this._getType(t)!==mK.undefined){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.undefined,received:r.parsedType}),m2}return m4(t.data)}}hw.create=t=>new hw({typeName:z.ZodUndefined,...m7(t)});class hR extends m8{_parse(t){if(this._getType(t)!==mK.null){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.null,received:r.parsedType}),m2}return m4(t.data)}}hR.create=t=>new hR({typeName:z.ZodNull,...m7(t)});class hk extends m8{constructor(){super(...arguments),this._any=!0}_parse(t){return m4(t.data)}}hk.create=t=>new hk({typeName:z.ZodAny,...m7(t)});class hx extends m8{constructor(){super(...arguments),this._unknown=!0}_parse(t){return m4(t.data)}}hx.create=t=>new hx({typeName:z.ZodUnknown,...m7(t)});class hP extends m8{_parse(t){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.never,received:r.parsedType}),m2}}hP.create=t=>new hP({typeName:z.ZodNever,...m7(t)});class hE extends m8{_parse(t){if(this._getType(t)!==mK.undefined){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.void,received:r.parsedType}),m2}return m4(t.data)}}hE.create=t=>new hE({typeName:z.ZodVoid,...m7(t)});class hT extends m8{_parse(t){let{ctx:r,status:a}=this._processInputParams(t),n=this._def;if(r.parsedType!==mK.array)return m0(r,{code:mW.invalid_type,expected:mK.array,received:r.parsedType}),m2;if(null!==n.exactLength){let t=r.data.length>n.exactLength.value,i=r.data.length<n.exactLength.value;(t||i)&&(m0(r,{code:t?mW.too_big:mW.too_small,minimum:i?n.exactLength.value:void 0,maximum:t?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),a.dirty())}if(null!==n.minLength&&r.data.length<n.minLength.value&&(m0(r,{code:mW.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),a.dirty()),null!==n.maxLength&&r.data.length>n.maxLength.value&&(m0(r,{code:mW.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),a.dirty()),r.common.async)return Promise.all([...r.data].map((t,a)=>n.type._parseAsync(new m6(r,t,r.path,a)))).then(t=>m1.mergeArray(a,t));let i=[...r.data].map((t,a)=>n.type._parseSync(new m6(r,t,r.path,a)));return m1.mergeArray(a,i)}get element(){return this._def.type}min(t,r){return new hT({...this._def,minLength:{value:t,message:M.toString(r)}})}max(t,r){return new hT({...this._def,maxLength:{value:t,message:M.toString(r)}})}length(t,r){return new hT({...this._def,exactLength:{value:t,message:M.toString(r)}})}nonempty(t){return this.min(1,t)}}hT.create=(t,r)=>new hT({type:t,minLength:null,maxLength:null,exactLength:null,typeName:z.ZodArray,...m7(r)});class hj extends m8{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let t=this._def.shape(),r=q.objectKeys(t);return this._cached={shape:t,keys:r},this._cached}_parse(t){if(this._getType(t)!==mK.object){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.object,received:r.parsedType}),m2}let{status:r,ctx:a}=this._processInputParams(t),{shape:n,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof hP&&"strip"===this._def.unknownKeys))for(let t in a.data)i.includes(t)||o.push(t);let s=[];for(let t of i){let r=n[t],i=a.data[t];s.push({key:{status:"valid",value:t},value:r._parse(new m6(a,i,a.path,t)),alwaysSet:t in a.data})}if(this._def.catchall instanceof hP){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&&(m0(a,{code:mW.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 n=a.data[r];s.push({key:{status:"valid",value:r},value:t._parse(new m6(a,n,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,n=await r.value;t.push({key:a,value:n,alwaysSet:r.alwaysSet})}return t}).then(t=>m1.mergeObjectSync(r,t)):m1.mergeObjectSync(r,s)}get shape(){return this._def.shape()}strict(t){return M.errToObj,new hj({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(r,a)=>{let n=this._def.errorMap?.(r,a).message??a.defaultError;return"unrecognized_keys"===r.code?{message:M.errToObj(t).message??n}:{message:n}}}:{}})}strip(){return new hj({...this._def,unknownKeys:"strip"})}passthrough(){return new hj({...this._def,unknownKeys:"passthrough"})}extend(t){return new hj({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new hj({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 hj({...this._def,catchall:t})}pick(t){let r={};for(let a of q.objectKeys(t))t[a]&&this.shape[a]&&(r[a]=this.shape[a]);return new hj({...this._def,shape:()=>r})}omit(t){let r={};for(let a of q.objectKeys(this.shape))t[a]||(r[a]=this.shape[a]);return new hj({...this._def,shape:()=>r})}deepPartial(){return function t(r){if(r instanceof hj){let a={};for(let n in r.shape){let i=r.shape[n];a[n]=hB.create(t(i))}return new hj({...r._def,shape:()=>a})}if(r instanceof hT)return new hT({...r._def,type:t(r.element)});if(r instanceof hB)return hB.create(t(r.unwrap()));if(r instanceof hK)return hK.create(t(r.unwrap()));if(r instanceof hq)return hq.create(r.items.map(r=>t(r)));else return r}(this)}partial(t){let r={};for(let a of q.objectKeys(this.shape)){let n=this.shape[a];t&&!t[a]?r[a]=n:r[a]=n.optional()}return new hj({...this._def,shape:()=>r})}required(t){let r={};for(let a of q.objectKeys(this.shape))if(t&&!t[a])r[a]=this.shape[a];else{let t=this.shape[a];for(;t instanceof hB;)t=t._def.innerType;r[a]=t}return new hj({...this._def,shape:()=>r})}keyof(){return hU(q.objectKeys(this.shape))}}hj.create=(t,r)=>new hj({shape:()=>t,unknownKeys:"strip",catchall:hP.create(),typeName:z.ZodObject,...m7(r)}),hj.strictCreate=(t,r)=>new hj({shape:()=>t,unknownKeys:"strict",catchall:hP.create(),typeName:z.ZodObject,...m7(r)}),hj.lazycreate=(t,r)=>new hj({shape:t,unknownKeys:"strip",catchall:hP.create(),typeName:z.ZodObject,...m7(r)});class hO extends m8{_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 mY(t.ctx.common.issues));return m0(r,{code:mW.invalid_union,unionErrors:a}),m2});{let t,n=[];for(let i of a){let a={...r,common:{...r.common,issues:[]},parent:null},o=i._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&&n.push(a.common.issues)}if(t)return r.common.issues.push(...t.ctx.common.issues),t.result;let i=n.map(t=>new mY(t));return m0(r,{code:mW.invalid_union,unionErrors:i}),m2}}get options(){return this._def.options}}hO.create=(t,r)=>new hO({options:t,typeName:z.ZodUnion,...m7(r)});let hC=t=>{if(t instanceof hZ)return hC(t.schema);if(t instanceof hJ)return hC(t.innerType());if(t instanceof hD)return[t.value];if(t instanceof hV)return t.options;if(t instanceof hF)return q.objectValues(t.enum);else if(t instanceof hG)return hC(t._def.innerType);else if(t instanceof hw)return[void 0];else if(t instanceof hR)return[null];else if(t instanceof hB)return[void 0,...hC(t.unwrap())];else if(t instanceof hK)return[null,...hC(t.unwrap())];else if(t instanceof hX)return hC(t.unwrap());else if(t instanceof h0)return hC(t.unwrap());else if(t instanceof hW)return hC(t._def.innerType);else return[]};class hI extends m8{_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mK.object)return m0(r,{code:mW.invalid_type,expected:mK.object,received:r.parsedType}),m2;let a=this.discriminator,n=r.data[a],i=this.optionsMap.get(n);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(m0(r,{code:mW.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),m2)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,r,a){let n=new Map;for(let a of r){let r=hC(a.shape[t]);if(!r.length)throw Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(let i of r){if(n.has(i))throw Error(`Discriminator property ${String(t)} has duplicate value ${String(i)}`);n.set(i,a)}}return new hI({typeName:z.ZodDiscriminatedUnion,discriminator:t,options:r,optionsMap:n,...m7(a)})}}class hN extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t),n=(t,n)=>{if("aborted"===t.status||"aborted"===n.status)return m2;let i=function t(r,a){let n=mG(r),i=mG(a);if(r===a)return{valid:!0,data:r};if(n===mK.object&&i===mK.object){let n=q.objectKeys(a),i=q.objectKeys(r).filter(t=>-1!==n.indexOf(t)),o={...r,...a};for(let n of(Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__,i)){if("__proto__"===n)continue;let i=t(r[n],a[n]);if(!i.valid)return{valid:!1};o[n]=i.data}return{valid:!0,data:o}}if(n===mK.array&&i===mK.array){if(r.length!==a.length)return{valid:!1};let n=[];for(let i=0;i<r.length;i++){let o=t(r[i],a[i]);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}if(n===mK.date&&i===mK.date&&+r==+a)return{valid:!0,data:r};return{valid:!1}}(t.value,n.value);return i.valid?(("dirty"===t.status||"dirty"===n.status)&&r.dirty(),{status:r.value,value:i.data}):(m0(a,{code:mW.invalid_intersection_types}),m2)};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])=>n(t,r)):n(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}hN.create=(t,r,a)=>new hN({left:t,right:r,typeName:z.ZodIntersection,...m7(a)});class hq extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mK.array)return m0(a,{code:mW.invalid_type,expected:mK.array,received:a.parsedType}),m2;if(a.data.length<this._def.items.length)return m0(a,{code:mW.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),m2;!this._def.rest&&a.data.length>this._def.items.length&&(m0(a,{code:mW.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let n=[...a.data].map((t,r)=>{let n=this._def.items[r]||this._def.rest;return n?n._parse(new m6(a,t,a.path,r)):null}).filter(t=>!!t);return a.common.async?Promise.all(n).then(t=>m1.mergeArray(r,t)):m1.mergeArray(r,n)}get items(){return this._def.items}rest(t){return new hq({...this._def,rest:t})}}hq.create=(t,r)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hq({items:t,typeName:z.ZodTuple,rest:null,...m7(r)})};class hA extends m8{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!==mK.object)return m0(a,{code:mW.invalid_type,expected:mK.object,received:a.parsedType}),m2;let n=[],i=this._def.keyType,o=this._def.valueType;for(let t in a.data)n.push({key:i._parse(new m6(a,t,a.path,t)),value:o._parse(new m6(a,a.data[t],a.path,t)),alwaysSet:t in a.data});return a.common.async?m1.mergeObjectAsync(r,n):m1.mergeObjectSync(r,n)}get element(){return this._def.valueType}static create(t,r,a){return new hA(r instanceof m8?{keyType:t,valueType:r,typeName:z.ZodRecord,...m7(a)}:{keyType:hy.create(),valueType:t,typeName:z.ZodRecord,...m7(r)})}}class hM extends m8{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!==mK.map)return m0(a,{code:mW.invalid_type,expected:mK.map,received:a.parsedType}),m2;let n=this._def.keyType,i=this._def.valueType,o=[...a.data.entries()].map(([t,r],o)=>({key:n._parse(new m6(a,t,a.path,[o,"key"])),value:i._parse(new m6(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 n=await a.key,i=await a.value;if("aborted"===n.status||"aborted"===i.status)return m2;("dirty"===n.status||"dirty"===i.status)&&r.dirty(),t.set(n.value,i.value)}return{status:r.value,value:t}})}{let t=new Map;for(let a of o){let n=a.key,i=a.value;if("aborted"===n.status||"aborted"===i.status)return m2;("dirty"===n.status||"dirty"===i.status)&&r.dirty(),t.set(n.value,i.value)}return{status:r.value,value:t}}}}hM.create=(t,r,a)=>new hM({valueType:r,keyType:t,typeName:z.ZodMap,...m7(a)});class hz extends m8{_parse(t){let{status:r,ctx:a}=this._processInputParams(t);if(a.parsedType!==mK.set)return m0(a,{code:mW.invalid_type,expected:mK.set,received:a.parsedType}),m2;let n=this._def;null!==n.minSize&&a.data.size<n.minSize.value&&(m0(a,{code:mW.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),r.dirty()),null!==n.maxSize&&a.data.size>n.maxSize.value&&(m0(a,{code:mW.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),r.dirty());let i=this._def.valueType;function o(t){let a=new Set;for(let n of t){if("aborted"===n.status)return m2;"dirty"===n.status&&r.dirty(),a.add(n.value)}return{status:r.value,value:a}}let s=[...a.data.values()].map((t,r)=>i._parse(new m6(a,t,a.path,r)));return a.common.async?Promise.all(s).then(t=>o(t)):o(s)}min(t,r){return new hz({...this._def,minSize:{value:t,message:M.toString(r)}})}max(t,r){return new hz({...this._def,maxSize:{value:t,message:M.toString(r)}})}size(t,r){return this.min(t,r).max(t,r)}nonempty(t){return this.min(1,t)}}hz.create=(t,r)=>new hz({valueType:t,minSize:null,maxSize:null,typeName:z.ZodSet,...m7(r)});class hL extends m8{constructor(){super(...arguments),this.validate=this.implement}_parse(t){let{ctx:r}=this._processInputParams(t);if(r.parsedType!==mK.function)return m0(r,{code:mW.invalid_type,expected:mK.function,received:r.parsedType}),m2;function a(t,a){return mQ({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mX,mX].filter(t=>!!t),issueData:{code:mW.invalid_arguments,argumentsError:a}})}function n(t,a){return mQ({data:t,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,mX,mX].filter(t=>!!t),issueData:{code:mW.invalid_return_type,returnTypeError:a}})}let i={errorMap:r.common.contextualErrorMap},o=r.data;if(this._def.returns instanceof hH){let t=this;return m4(async function(...r){let s=new mY([]),l=await t._def.args.parseAsync(r,i).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,i).catch(t=>{throw s.addIssue(n(c,t)),s})})}{let t=this;return m4(function(...r){let s=t._def.args.safeParse(r,i);if(!s.success)throw new mY([a(r,s.error)]);let l=Reflect.apply(o,this,s.data),c=t._def.returns.safeParse(l,i);if(!c.success)throw new mY([n(l,c.error)]);return c.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new hL({...this._def,args:hq.create(t).rest(hx.create())})}returns(t){return new hL({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,r,a){return new hL({args:t||hq.create([]).rest(hx.create()),returns:r||hx.create(),typeName:z.ZodFunction,...m7(a)})}}class hZ extends m8{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})}}hZ.create=(t,r)=>new hZ({getter:t,typeName:z.ZodLazy,...m7(r)});class hD extends m8{_parse(t){if(t.data!==this._def.value){let r=this._getOrReturnCtx(t);return m0(r,{received:r.data,code:mW.invalid_literal,expected:this._def.value}),m2}return{status:"valid",value:t.data}}get value(){return this._def.value}}function hU(t,r){return new hV({values:t,typeName:z.ZodEnum,...m7(r)})}hD.create=(t,r)=>new hD({value:t,typeName:z.ZodLiteral,...m7(r)});class hV extends m8{_parse(t){if("string"!=typeof t.data){let r=this._getOrReturnCtx(t),a=this._def.values;return m0(r,{expected:q.joinValues(a),received:r.parsedType,code:mW.invalid_type}),m2}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 m0(r,{received:r.data,code:mW.invalid_enum_value,options:a}),m2}return m4(t.data)}get options(){return this._def.values}get enum(){let t={};for(let r of this._def.values)t[r]=r;return t}get Values(){let t={};for(let r of this._def.values)t[r]=r;return t}get Enum(){let t={};for(let r of this._def.values)t[r]=r;return t}extract(t,r=this._def){return hV.create(t,{...this._def,...r})}exclude(t,r=this._def){return hV.create(this.options.filter(r=>!t.includes(r)),{...this._def,...r})}}hV.create=hU;class hF extends m8{_parse(t){let r=q.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==mK.string&&a.parsedType!==mK.number){let t=q.objectValues(r);return m0(a,{expected:q.joinValues(t),received:a.parsedType,code:mW.invalid_type}),m2}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let t=q.objectValues(r);return m0(a,{received:a.data,code:mW.invalid_enum_value,options:t}),m2}return m4(t.data)}get enum(){return this._def.values}}hF.create=(t,r)=>new hF({values:t,typeName:z.ZodNativeEnum,...m7(r)});class hH extends m8{unwrap(){return this._def.type}_parse(t){let{ctx:r}=this._processInputParams(t);return r.parsedType!==mK.promise&&!1===r.common.async?(m0(r,{code:mW.invalid_type,expected:mK.promise,received:r.parsedType}),m2):m4((r.parsedType===mK.promise?r.data:Promise.resolve(r.data)).then(t=>this._def.type.parseAsync(t,{path:r.path,errorMap:r.common.contextualErrorMap})))}}hH.create=(t,r)=>new hH({type:t,typeName:z.ZodPromise,...m7(r)});class hJ extends m8{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),n=this._def.effect||null,i={addIssue:t=>{m0(a,t),t.fatal?r.abort():r.dirty()},get path(){return a.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===n.type){let t=n.transform(a.data,i);if(a.common.async)return Promise.resolve(t).then(async t=>{if("aborted"===r.value)return m2;let n=await this._def.schema._parseAsync({data:t,path:a.path,parent:a});return"aborted"===n.status?m2:"dirty"===n.status||"dirty"===r.value?m9(n.value):n});{if("aborted"===r.value)return m2;let n=this._def.schema._parseSync({data:t,path:a.path,parent:a});return"aborted"===n.status?m2:"dirty"===n.status||"dirty"===r.value?m9(n.value):n}}if("refinement"===n.type){let t=t=>{let r=n.refinement(t,i);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?m2:("dirty"===a.status&&r.dirty(),t(a.value).then(()=>({status:r.value,value:a.value}))));{let n=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===n.status?m2:("dirty"===n.status&&r.dirty(),t(n.value),{status:r.value,value:n.value})}}if("transform"===n.type)if(!1!==a.common.async)return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(t=>"valid"!==t.status?m2:Promise.resolve(n.transform(t.value,i)).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 m2;let o=n.transform(t.value,i);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}q.assertNever(n)}}hJ.create=(t,r,a)=>new hJ({schema:t,typeName:z.ZodEffects,effect:r,...m7(a)}),hJ.createWithPreprocess=(t,r,a)=>new hJ({schema:r,effect:{type:"preprocess",transform:t},typeName:z.ZodEffects,...m7(a)});class hB extends m8{_parse(t){return this._getType(t)===mK.undefined?m4(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hB.create=(t,r)=>new hB({innerType:t,typeName:z.ZodOptional,...m7(r)});class hK extends m8{_parse(t){return this._getType(t)===mK.null?m4(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}hK.create=(t,r)=>new hK({innerType:t,typeName:z.ZodNullable,...m7(r)});class hG extends m8{_parse(t){let{ctx:r}=this._processInputParams(t),a=r.data;return r.parsedType===mK.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:r.path,parent:r})}removeDefault(){return this._def.innerType}}hG.create=(t,r)=>new hG({innerType:t,typeName:z.ZodDefault,defaultValue:"function"==typeof r.default?r.default:()=>r.default,...m7(r)});class hW extends m8{_parse(t){let{ctx:r}=this._processInputParams(t),a={...r,common:{...r.common,issues:[]}},n=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return m3(n)?n.then(t=>({status:"valid",value:"valid"===t.status?t.value:this._def.catchValue({get error(){return new mY(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===n.status?n.value:this._def.catchValue({get error(){return new mY(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}hW.create=(t,r)=>new hW({innerType:t,typeName:z.ZodCatch,catchValue:"function"==typeof r.catch?r.catch:()=>r.catch,...m7(r)});class hY extends m8{_parse(t){if(this._getType(t)!==mK.nan){let r=this._getOrReturnCtx(t);return m0(r,{code:mW.invalid_type,expected:mK.nan,received:r.parsedType}),m2}return{status:"valid",value:t.data}}}hY.create=t=>new hY({typeName:z.ZodNaN,...m7(t)}),Symbol("zod_brand");class hX extends m8{_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 hQ extends m8{_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?m2:"dirty"===t.status?(r.dirty(),m9(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?m2:"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 hQ({in:t,out:r,typeName:z.ZodPipeline})}}class h0 extends m8{_parse(t){let r=this._def.innerType._parse(t),a=t=>("valid"===t.status&&(t.value=Object.freeze(t.value)),t);return m3(r)?r.then(t=>a(t)):a(r)}unwrap(){return this._def.innerType}}h0.create=(t,r)=>new h0({innerType:t,typeName:z.ZodReadonly,...m7(r)}),hj.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 h1=hy.create;hv.create,hY.create,h_.create,hb.create,hS.create,h$.create,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create,hT.create;let h2=hj.create;hj.strictCreate,hO.create,hI.create,hN.create,hq.create,hA.create,hM.create,hz.create,hL.create,hZ.create,hD.create,hV.create,hF.create,hH.create,hJ.create,hB.create,hK.create,hJ.createWithPreprocess,hQ.create;let h9=(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 h4(t){if("openAi"!==t.target)return{};let r=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===t.$refStrategy?h9(r,t.currentPath):r.join("/")}}function h3(t,r,a,n){n?.errorMessages&&a&&(t.errorMessage={...t.errorMessage,[r]:a})}function h6(t,r,a,n,i){t[r]=a,h3(t,r,n,i)}function h5(t,r){return fv(t.type._def,r)}let h7=/^[cC][^\s-]{8,}$/,h8=/^[0-9a-z]+$/,fe=/^[0-9A-HJKMNP-TV-Z]{26}$/,ft=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,fr=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),fa=/^(?:(?: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])$/,fn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,fo=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,fs=/^[a-zA-Z0-9_-]{21}$/,fl=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function fc(t,r){let a={type:"string"};if(t.checks)for(let n of t.checks)switch(n.kind){case"min":h6(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,n.value):n.value,n.message,r);break;case"max":h6(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,n.value):n.value,n.message,r);break;case"email":switch(r.emailStrategy){case"format:email":fp(a,"email",n.message,r);break;case"format:idn-email":fp(a,"idn-email",n.message,r);break;case"pattern:zod":fm(a,ft,n.message,r)}break;case"url":fp(a,"uri",n.message,r);break;case"uuid":fp(a,"uuid",n.message,r);break;case"regex":fm(a,n.regex,n.message,r);break;case"cuid":fm(a,h7,n.message,r);break;case"cuid2":fm(a,h8,n.message,r);break;case"startsWith":fm(a,RegExp(`^${fu(n.value,r)}`),n.message,r);break;case"endsWith":fm(a,RegExp(`${fu(n.value,r)}$`),n.message,r);break;case"datetime":fp(a,"date-time",n.message,r);break;case"date":fp(a,"date",n.message,r);break;case"time":fp(a,"time",n.message,r);break;case"duration":fp(a,"duration",n.message,r);break;case"length":h6(a,"minLength","number"==typeof a.minLength?Math.max(a.minLength,n.value):n.value,n.message,r),h6(a,"maxLength","number"==typeof a.maxLength?Math.min(a.maxLength,n.value):n.value,n.message,r);break;case"includes":fm(a,RegExp(fu(n.value,r)),n.message,r);break;case"ip":"v6"!==n.version&&fp(a,"ipv4",n.message,r),"v4"!==n.version&&fp(a,"ipv6",n.message,r);break;case"base64url":fm(a,fo,n.message,r);break;case"jwt":fm(a,fl,n.message,r);break;case"cidr":"v6"!==n.version&&fm(a,fa,n.message,r),"v4"!==n.version&&fm(a,fn,n.message,r);break;case"emoji":fm(a,fr(),n.message,r);break;case"ulid":fm(a,fe,n.message,r);break;case"base64":switch(r.base64Strategy){case"format:binary":fp(a,"binary",n.message,r);break;case"contentEncoding:base64":h6(a,"contentEncoding","base64",n.message,r);break;case"pattern:zod":fm(a,fi,n.message,r)}break;case"nanoid":fm(a,fs,n.message,r)}return a}function fu(t,r){return"escape"===r.patternStrategy?function(t){let r="";for(let a=0;a<t.length;a++)fd.has(t[a])||(r+="\\"),r+=t[a];return r}(t):t}let fd=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fp(t,r,a,n){t.format||t.anyOf?.some(t=>t.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&n.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&&n.errorMessages&&{errorMessage:{format:a}}})):h6(t,"format",r,a,n)}function fm(t,r,a,n){t.pattern||t.allOf?.some(t=>t.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&n.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:fh(r,n),...a&&n.errorMessages&&{errorMessage:{pattern:a}}})):h6(t,"pattern",fh(r,n),a,n)}function fh(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")},n=a.i?t.source.toLowerCase():t.source,i="",o=!1,s=!1,l=!1;for(let t=0;t<n.length;t++){if(o){i+=n[t],o=!1;continue}if(a.i){if(s){if(n[t].match(/[a-z]/)){l?(i+=n[t],i+=`${n[t-2]}-${n[t]}`.toUpperCase(),l=!1):"-"===n[t+1]&&n[t+2]?.match(/[a-z]/)?(i+=n[t],l=!0):i+=`${n[t]}${n[t].toUpperCase()}`;continue}}else if(n[t].match(/[a-z]/)){i+=`[${n[t]}${n[t].toUpperCase()}]`;continue}}if(a.m){if("^"===n[t]){i+=`(^|(?<=[\r
|
|
78
78
|
]))`;continue}else if("$"===n[t]){i+=`($|(?=[\r
|
|
79
79
|
]))`;continue}}if(a.s&&"."===n[t]){i+=s?`${n[t]}\r
|
|
80
80
|
`:`[${n[t]}\r
|
|
81
|
-
]`;continue}i+=n[t],"\\"===n[t]?o=!0:s&&"]"===n[t]?s=!1:s||"["!==n[t]||(s=!0)}try{new RegExp(i)}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 i}function fm(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,n)=>({...a,[n]:fg(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",n]})??h2(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:fg(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:n,...i}=fs(t.keyType._def,r);return{...a,propertyNames:i}}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:n,...i}=h3(t.keyType._def,r);return{...a,propertyNames:i}}return a}let fh={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},ff=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>fg(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 fg(t,r,a=!1){let n=r.seen.get(t);if(r.override){let i=r.override?.(t,r,n,a);if(i!==mJ)return i}if(n&&!a){let t=fy(n,r);if(void 0!==t)return t}let i={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,i);let o=((t,r,a)=>{switch(r){case z.ZodString:return fs(t,a);case z.ZodNumber:let n={type:"number"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"int":n.type="integer",h9(n,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?h4(n,"minimum",r.value,r.message,a):h4(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),h4(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h4(n,"maximum",r.value,r.message,a):h4(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),h4(n,"maximum",r.value,r.message,a));break;case"multipleOf":h4(n,"multipleOf",r.value,r.message,a)}return n;case z.ZodObject:return function(t,r){let a="openAi"===r.target,n={type:"object",properties:{}},i=[],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=fg(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(n.properties[t]=c,l||i.push(t))}i.length&&(n.required=i);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return fg(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&&(n.additionalProperties=s),n}(t,a);case z.ZodBigInt:let i={type:"integer",format:"int64"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?h4(i,"minimum",r.value,r.message,a):h4(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),h4(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h4(i,"maximum",r.value,r.message,a):h4(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),h4(i,"maximum",r.value,r.message,a));break;case"multipleOf":h4(i,"multipleOf",r.value,r.message,a)}return i;case z.ZodBoolean:return{type:"boolean"};case z.ZodDate:return function t(r,a,n){let i=n??a.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((n,i)=>t(r,a,n))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var 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":h4(l,"minimum",t.value,t.message,s);break;case"max":h4(l,"maximum",t.value,t.message,s)}return l}}(t,a);case z.ZodUndefined:return{not:h2(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=fg(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&h4(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&h4(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(h4(o,"minItems",t.exactLength.value,t.exactLength.message,a),h4(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case z.ZodUnion:case z.ZodDiscriminatedUnion:if("openApi3"===a.target)return ff(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in fh&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=fh[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 ff(t,a);case z.ZodIntersection:let l,c,u;return l=[fg(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),fg(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,...n}=t;r=n}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)=>fg(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:fg(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>fg(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case z.ZodRecord:return fm(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:fh[t.innerType._def.typeName],nullable:!0}:{type:[fh[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=fg(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=fg(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 fg(t.innerType._def,a);let g=fg(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return g?{anyOf:[{not:h2(a)},g]}:h2(a);case z.ZodMap:if("record"===a.mapStrategy)return fm(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[fg(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||h2(a),fg(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||h2(a)],minItems:2,maxItems:2}};case z.ZodSet:let y;return y={type:"array",uniqueItems:!0,items:fg(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&h4(y,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&h4(y,"maxItems",t.maxSize.value,t.maxSize.message,a),y;case z.ZodLazy:return()=>t.getter()._def;case z.ZodPromise:return fg(t.type._def,a);case z.ZodNaN:case z.ZodNever:return"openAi"===a.target?void 0:{not:h2({...a,currentPath:[...a.currentPath,"not"]})};case z.ZodEffects:return"input"===a.effectStrategy?fg(t.schema._def,a):h2(a);case z.ZodAny:case z.ZodUnknown:return h2(a);case z.ZodDefault:return{...fg(t.innerType._def,a),default:t.defaultValue()};case z.ZodBranded:return h3(t,a);case z.ZodReadonly:case z.ZodCatch:return fg(t.innerType._def,a);case z.ZodPipeline:if("input"===a.pipeStrategy)return fg(t.in._def,a);if("output"===a.pipeStrategy)return fg(t.out._def,a);let v=fg(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=fg(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?fg(o(),r):o;if(s&&fv(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return i.jsonSchema=s,a}return i.jsonSchema=s,s}let fy=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:h1(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`),h2(r);return"seen"===r.$refStrategy?h2(r):void 0}},fv=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function f_(t,r={}){let{strict:a=!1}=r,n=Object.entries(t),i=t=>({target:r})=>{let i={},o=[];for(let[a,s]of n)i[a]=function(t,r,a){let n=t["~standard"];if(n.jsonSchema)return n.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,n,i=(n=void 0!==(a="string"==typeof r?{...mB,name:r}:{...mB,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:n,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]:fg(a._def,{...i,currentPath:[...i.basePath,i.definitionPath,r]},!0)??h2(i)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=fg(t._def,void 0===s?i:{...i,currentPath:[...i.basePath,i.definitionPath,s]},!1)??h2(i),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),i.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[i.openAiAnyTypeName]||(o[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[i.definitionPath]:o}:l:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,s].join("/"),[i.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===i.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.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"===n.vendor&&"_zod"in t)try{let r=a8(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${n.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:i};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 i={},o=[];for(let[t,a]of n){let n=await a["~standard"].validate(r[t]);if(n.issues)for(let r of n.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==n.value)&&(i[t]=n.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:i}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:i("input"),output:i("output")}}}}function fb(t){let r={};return!function t(a,n=""){if(a&&"object"==typeof a)for(let[i,o]of Object.entries(a)){let a=n?`${n}/${i}`:i;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let fS=["ui/resourceUri","resourceUri","visibility"],f$=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fw(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 fR(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 fx(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let n=a?.name??fR(t),i=a?.tags??[];return(!r.include||fk(r.include,n,i))&&(!r.exclude||!fk(r.exclude,n,i))})):t}function fP(t){return Error(`[xmcp] Invalid prompt file: ${t}
|
|
82
|
-
-> Default export must be a prompt handler function.`)}async function
|
|
83
|
-
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function
|
|
84
|
-
-> Default export must be a resource handler function.`)}async function
|
|
85
|
-
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function
|
|
86
|
-
-> Default export must be a tool handler function.`)}async function
|
|
87
|
-
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),
|
|
81
|
+
]`;continue}i+=n[t],"\\"===n[t]?o=!0:s&&"]"===n[t]?s=!1:s||"["!==n[t]||(s=!0)}try{new RegExp(i)}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 i}function ff(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,n)=>({...a,[n]:fv(t.valueType._def,{...r,currentPath:[...r.currentPath,"properties",n]})??h4(r)}),{}),additionalProperties:r.rejectedAdditionalProperties};let a={type:"object",additionalProperties:fv(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:n,...i}=fc(t.keyType._def,r);return{...a,propertyNames:i}}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:n,...i}=h5(t.keyType._def,r);return{...a,propertyNames:i}}return a}let fg={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fy=(t,r)=>{let a=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((t,a)=>fv(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 fv(t,r,a=!1){let n=r.seen.get(t);if(r.override){let i=r.override?.(t,r,n,a);if(i!==mJ)return i}if(n&&!a){let t=f_(n,r);if(void 0!==t)return t}let i={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,i);let o=((t,r,a)=>{switch(r){case z.ZodString:return fc(t,a);case z.ZodNumber:let n={type:"number"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"int":n.type="integer",h3(n,"type",r.message,a);break;case"min":"jsonSchema7"===a.target?r.inclusive?h6(n,"minimum",r.value,r.message,a):h6(n,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(n.exclusiveMinimum=!0),h6(n,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h6(n,"maximum",r.value,r.message,a):h6(n,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(n.exclusiveMaximum=!0),h6(n,"maximum",r.value,r.message,a));break;case"multipleOf":h6(n,"multipleOf",r.value,r.message,a)}return n;case z.ZodObject:return function(t,r){let a="openAi"===r.target,n={type:"object",properties:{}},i=[],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=fv(s._def,{...r,currentPath:[...r.currentPath,"properties",t],propertyPath:[...r.currentPath,"properties",t]});void 0!==c&&(n.properties[t]=c,l||i.push(t))}i.length&&(n.required=i);let s=function(t,r){if("ZodNever"!==t.catchall._def.typeName)return fv(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&&(n.additionalProperties=s),n}(t,a);case z.ZodBigInt:let i={type:"integer",format:"int64"};if(!t.checks)return i;for(let r of t.checks)switch(r.kind){case"min":"jsonSchema7"===a.target?r.inclusive?h6(i,"minimum",r.value,r.message,a):h6(i,"exclusiveMinimum",r.value,r.message,a):(r.inclusive||(i.exclusiveMinimum=!0),h6(i,"minimum",r.value,r.message,a));break;case"max":"jsonSchema7"===a.target?r.inclusive?h6(i,"maximum",r.value,r.message,a):h6(i,"exclusiveMaximum",r.value,r.message,a):(r.inclusive||(i.exclusiveMaximum=!0),h6(i,"maximum",r.value,r.message,a));break;case"multipleOf":h6(i,"multipleOf",r.value,r.message,a)}return i;case z.ZodBoolean:return{type:"boolean"};case z.ZodDate:return function t(r,a,n){let i=n??a.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((n,i)=>t(r,a,n))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var 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":h6(l,"minimum",t.value,t.message,s);break;case"max":h6(l,"maximum",t.value,t.message,s)}return l}}(t,a);case z.ZodUndefined:return{not:h4(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=fv(t.type._def,{...a,currentPath:[...a.currentPath,"items"]})),t.minLength&&h6(o,"minItems",t.minLength.value,t.minLength.message,a),t.maxLength&&h6(o,"maxItems",t.maxLength.value,t.maxLength.message,a),t.exactLength&&(h6(o,"minItems",t.exactLength.value,t.exactLength.message,a),h6(o,"maxItems",t.exactLength.value,t.exactLength.message,a)),o;case z.ZodUnion:case z.ZodDiscriminatedUnion:if("openApi3"===a.target)return fy(t,a);let s=t.options instanceof Map?Array.from(t.options.values()):t.options;if(s.every(t=>t._def.typeName in fg&&(!t._def.checks||!t._def.checks.length))){let t=s.reduce((t,r)=>{let a=fg[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 fy(t,a);case z.ZodIntersection:let l,c,u;return l=[fv(t.left._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),fv(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,...n}=t;r=n}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)=>fv(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[]),additionalItems:fv(t.rest._def,{...a,currentPath:[...a.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((t,r)=>fv(t._def,{...a,currentPath:[...a.currentPath,"items",`${r}`]})).reduce((t,r)=>void 0===r?t:[...t,r],[])};case z.ZodRecord:return ff(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:fg[t.innerType._def.typeName],nullable:!0}:{type:[fg[t.innerType._def.typeName],"null"]};if("openApi3"===a.target){let r=fv(t.innerType._def,{...a,currentPath:[...a.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let f=fv(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 fv(t.innerType._def,a);let g=fv(t.innerType._def,{...a,currentPath:[...a.currentPath,"anyOf","1"]});return g?{anyOf:[{not:h4(a)},g]}:h4(a);case z.ZodMap:if("record"===a.mapStrategy)return ff(t,a);return{type:"array",maxItems:125,items:{type:"array",items:[fv(t.keyType._def,{...a,currentPath:[...a.currentPath,"items","items","0"]})||h4(a),fv(t.valueType._def,{...a,currentPath:[...a.currentPath,"items","items","1"]})||h4(a)],minItems:2,maxItems:2}};case z.ZodSet:let y;return y={type:"array",uniqueItems:!0,items:fv(t.valueType._def,{...a,currentPath:[...a.currentPath,"items"]})},t.minSize&&h6(y,"minItems",t.minSize.value,t.minSize.message,a),t.maxSize&&h6(y,"maxItems",t.maxSize.value,t.maxSize.message,a),y;case z.ZodLazy:return()=>t.getter()._def;case z.ZodPromise:return fv(t.type._def,a);case z.ZodNaN:case z.ZodNever:return"openAi"===a.target?void 0:{not:h4({...a,currentPath:[...a.currentPath,"not"]})};case z.ZodEffects:return"input"===a.effectStrategy?fv(t.schema._def,a):h4(a);case z.ZodAny:case z.ZodUnknown:return h4(a);case z.ZodDefault:return{...fv(t.innerType._def,a),default:t.defaultValue()};case z.ZodBranded:return h5(t,a);case z.ZodReadonly:case z.ZodCatch:return fv(t.innerType._def,a);case z.ZodPipeline:if("input"===a.pipeStrategy)return fv(t.in._def,a);if("output"===a.pipeStrategy)return fv(t.out._def,a);let v=fv(t.in._def,{...a,currentPath:[...a.currentPath,"allOf","0"]}),_=fv(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?fv(o(),r):o;if(s&&fb(t,r,s),r.postProcess){let a=r.postProcess(s,t,r);return i.jsonSchema=s,a}return i.jsonSchema=s,s}let f_=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:h9(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`),h4(r);return"seen"===r.$refStrategy?h4(r):void 0}},fb=(t,r,a)=>(t.description&&(a.description=t.description,r.markdownDescription&&(a.markdownDescription=t.description)),a);function fS(t,r={}){let{strict:a=!1}=r,n=Object.entries(t),i=t=>({target:r})=>{let i={},o=[];for(let[a,s]of n)i[a]=function(t,r,a){let n=t["~standard"];if(n.jsonSchema)return n.jsonSchema[a]({target:r});if("zod"===t["~standard"].vendor&&!("_zod"in t)&&"_def"in t){let a=((t,r)=>{let a,n,i=(n=void 0!==(a="string"==typeof r?{...mB,name:r}:{...mB,...r}).name?[...a.basePath,a.definitionPath,a.name]:a.basePath,{...a,flags:{hasReferencedOpenAiAnyType:!1},currentPath:n,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]:fv(a._def,{...i,currentPath:[...i.basePath,i.definitionPath,r]},!0)??h4(i)}),{}):void 0,s="string"==typeof r?r:r?.nameStrategy==="title"?void 0:r?.name,l=fv(t._def,void 0===s?i:{...i,currentPath:[...i.basePath,i.definitionPath,s]},!1)??h4(i),c="object"==typeof r&&void 0!==r.name&&"title"===r.nameStrategy?r.name:void 0;void 0!==c&&(l.title=c),i.flags.hasReferencedOpenAiAnyType&&(o||(o={}),o[i.openAiAnyTypeName]||(o[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let u=void 0===s?o?{...l,[i.definitionPath]:o}:l:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,s].join("/"),[i.definitionPath]:{...o,[s]:l}};return"jsonSchema7"===i.target?u.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(u.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.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"===n.vendor&&"_zod"in t)try{let r=a8(t);return delete r.$schema,r}catch(t){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${t instanceof Error?t.message:String(t)}`)}throw Error(`Schema library "${n.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:i};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 i={},o=[];for(let[t,a]of n){let n=await a["~standard"].validate(r[t]);if(n.issues)for(let r of n.issues)o.push({message:r.message,path:[t,...r.path??[]]});else(t in r||void 0!==n.value)&&(i[t]=n.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:i}};return{shape:t,"~standard":{version:1,vendor:"xmcp",validate:o,jsonSchema:{input:i("input"),output:i("output")}}}}function f$(t){let r={};return!function t(a,n=""){if(a&&"object"==typeof a)for(let[i,o]of Object.entries(a)){let a=n?`${n}/${i}`:i;!o||"object"!=typeof o||Array.isArray(o)||o instanceof Date||o instanceof RegExp?r[a]=o:t(o,a)}}(t),r}let fw=["ui/resourceUri","resourceUri","visibility"],fR=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fk(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 fx(t){return(t.split("/").pop()||t).replace(/\.[^/.]+$/,"")}function fP(t,r,a){return t.names?.includes(r)===!0||t.tags?.some(t=>a.includes(t))===!0}function fE(t,r){return r?new Map([...t].filter(([t,{metadata:a}])=>{if(a?.enabled===!1)return!1;let n=a?.name??fx(t),i=a?.tags??[];return(!r.include||fP(r.include,n,i))&&(!r.exclude||!fP(r.exclude,n,i))})):t}function fT(t){return Error(`[xmcp] Invalid prompt file: ${t}
|
|
82
|
+
-> Default export must be a prompt handler function.`)}async function fj(t){let r=new Map,a=[];for(let n of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),n=function(t,r){if("object"!=typeof t||null===t)throw fT(r);let a=Object.keys(t),n=t.default,i=a.filter(t=>"__esModule"!==t);if(0===a.length||1===i.length&&"default"===i[0]&&"object"==typeof n&&null!==n&&0===Object.keys(n).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fT(r);return"valid"}(a,t);return"empty"===n?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===n?{skipped:!0,issue:{path:t,message:"File does not export a default prompt handler."}}:{skipped:!1,path:t,promptModule:a}})))){if(n.skipped){a.push(n.issue);continue}r.set(n.path,n.promptModule)}return{promptModules:r,skippedPrompts:a}}let fO=function(t=console){let r="";return a=>{let n=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(n===r||(r=n,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load prompt file: ${r}
|
|
83
|
+
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fC(t){return Error(`[xmcp] Invalid resource file: ${t}
|
|
84
|
+
-> Default export must be a resource handler function.`)}async function fI(t){let r=new Map,a=[];for(let n of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),n=function(t,r){if("object"!=typeof t||null===t)throw fC(r);let a=Object.keys(t),n=t.default,i=a.filter(t=>"__esModule"!==t);if(0===a.length||1===i.length&&"default"===i[0]&&"object"==typeof n&&null!==n&&0===Object.keys(n).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fC(r);return"valid"}(a,t);return"empty"===n?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===n?{skipped:!0,issue:{path:t,message:"File does not export a default resource handler."}}:{skipped:!1,path:t,resourceModule:a}})))){if(n.skipped){a.push(n.issue);continue}r.set(n.path,n.resourceModule)}return{resourceModules:r,skippedResources:a}}let fN=function(t=console){let r="";return a=>{let n=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(n===r||(r=n,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load resource file: ${r}
|
|
85
|
+
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fq(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 fA(t){let r=t.split("/").filter(t=>""!==t),a=r.findIndex(t=>t.match(/^\(.+\)$/));if(-1===a)return null;let n=r[r.length-1];if(n&&n.match(/^\[.+\]\.ts$/))return null;let i=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=`${i}://${u.join("/")}`,p=l.length>0?"template":"direct";return{filePath:t,uriTemplate:d,scheme:i,parameters:l,pathSegments:c,type:p}}let fM={ttlMs:0,cacheScope:"private"},fz=h2({cursor:h1().optional()}).passthrough().optional(),fL=h2({uri:h1()}).passthrough();function fZ({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 fD(t){return Error(`[xmcp] Invalid tool file: ${t}
|
|
86
|
+
-> Default export must be a tool handler function.`)}async function fU(t){let r=new Map,a=[];for(let n of(await Promise.all(Object.entries(t).map(async([t,r])=>{let a=await r(),n=function(t,r){if("object"!=typeof t||null===t)throw fD(r);let a=Object.keys(t),n=t.default,i=a.filter(t=>"__esModule"!==t);if(0===a.length||1===i.length&&"default"===i[0]&&"object"==typeof n&&null!==n&&0===Object.keys(n).length)return"empty";if(!("default"in t)||void 0===t.default)return"missing-default";if("function"!=typeof t.default)throw fD(r);return"valid"}(a,t);return"empty"===n?{skipped:!0,issue:{path:t,message:"File is empty."}}:"missing-default"===n?{skipped:!0,issue:{path:t,message:"File does not export a default tool handler."}}:{skipped:!1,path:t,toolModule:a}})))){if(n.skipped){a.push(n.issue);continue}r.set(n.path,n.toolModule)}return{toolModules:r,skippedTools:a}}let fV=function(t=console){let r="";return a=>{let n=a.map(({path:t,message:r})=>`${t}:${r}`).sort().join("|");if(n===r||(r=n,0===a.length))return;a.forEach(({path:r,message:a})=>{t.warn(`[xmcp] Failed to load tool file: ${r}
|
|
87
|
+
-> ${a}`)});let i=a.length;t.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fF=INJECTED_TOOLS,fH=INJECTED_PROMPTS,fJ=INJECTED_RESOURCES,fB="undefined"==typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],fK=SERVER_INFO;async function fG(t,r,n,i){let o=await INJECTED_MIDDLEWARE?.(),s=function(t){if(void 0===t)return[];let r=Array.isArray(t)?[...t]:[t];if(!r.every(t=>"function"==typeof t))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return r}(o?.mcp),l="undefined"!=typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(t=t=>console.error(t)){let r=new Map,a=[];function n(r){try{t(JSON.stringify({"@timestamp":new Date().toISOString(),...r}))}catch{}}return{middleware:async(t,i)=>{let o,s,l;if("tools/call"!==t.method&&"prompts/get"!==t.method&&"resources/read"!==t.method)return i();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 n=new URL(t).href;return r.get(n)??a.find(({template:t})=>t.uriTemplate.match(n))?.name??"unknown"}catch{return"unknown"}}(t.params.uri):t.params.name}}}catch{return i()}n({...o,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let c="unknown";try{let r=await i();try{c=t.signal.aborted?"cancelled":cX(r)?"input_required":"isError"in r&&!0===r.isError?"failure":"success","failure"===c&&(l={message:"Operation returned an error result"})}catch{}return r}catch(r){throw l={message:"cancelled"==(c=t.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},r}finally{try{n({...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,n){try{"string"==typeof n?r.set(new URL(n).href,t):a.push({name:t,template:n})}catch{}}}}():void 0;l&&s.unshift(l.middleware),mm.clear();let c="undefined"==typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(t,r,a){let n=t.server,i=n.setRequestHandler,o=mV(r);n.setRequestHandler=(t,...r)=>{if(mF.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(i,n,[t,...r])};try{a()}finally{n.setRequestHandler=i}}(t,s,()=>{var o,u;!function(t,r,a=[]){r.forEach((r,n)=>{var i,o;let s,l,c,u,d={name:fx(n),description:"No description provided"},{default:p,metadata:m,schema:h,outputSchema:f}=r;if("object"==typeof m&&null!==m&&Object.assign(d,m),!1===d.enabled)return;if("function"==typeof p&&"__x402"in p){let t=global.__XMCP_X402_REGISTRY;t&&t.set(d.name,p.__x402)}let g={};if(fk(h)?g=h:null!=h&&console.warn(`Invalid schema for tool "${d.name}" at ${n}. Expected Record<string, z.ZodType>`),null!=f)if(fk(f))s=f;else throw Error(`Invalid outputSchema for tool "${d.name}" at ${n}. Expected Record<string, z.ZodType>`);d.annotations={...d.annotations??{}},void 0===d.annotations.title&&(d.annotations.title=d.name),d._meta={...mp(d)._meta};let y=mH(n),v=!!(i=d._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||y,_=d._meta;if(v){let t=`ui://app/${d.name}.html`;d._meta.ui||(d._meta.ui={}),d._meta.ui.resourceUri||(d._meta.ui.resourceUri=t);let r=function(t){let r={},a={};if(t.ui&&"object"==typeof t.ui){let n=t.ui,i={},o={};for(let[t,r]of Object.entries(n))fw.includes(t)?i[t]=r:fR.includes(t)?o[t]=r:i[t]=r;Object.keys(i).length>0&&(r.ui=i),Object.keys(o).length>0&&(a.ui=o)}for(let[a,n]of Object.entries(t))"ui"!==a&&(r[a]=n);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"),mm.add(d.name,{name:d.name,uri:t,handler:p,mimeType:"text/html;profile=mcp-app",_meta:a,toolPath:y?n:void 0})}let b=f$(_),S=v?b:void 0;l=mH(n)&&v?async(t,r)=>({content:[{type:"text",text:""}],_meta:S,structuredContent:{args:t}}):function(t,r,a,n="unknown-tool"){return async(i,o)=>{let s,l,c=t(i,(s=mU(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)=>mk(o,t,r),sample:(t,r)=>mA(o,t,r),inputResponses:o.mcpReq.inputResponses,requestState:o.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),cX(c))return c;if("string"==typeof c||"number"==typeof c){if(a){let t=Object.entries(a);if(1===t.length){let[r,a]=t[0];try{return a.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[r]:c}}}catch{}}}return mD(r)?{content:[{type:"text",text:""}],structuredContent:{args:i},_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||(mZ(c,a,n,"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(mD(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:
|
|
154
|
+
}`)}}return c}}(p,S,s,d.name);let $={title:d.annotations?.title,description:d.description,inputSchema:fS(g),outputSchema:s?fS(s,{strict:!0}):void 0,annotations:d.annotations,icons:d.icons,_meta:b};t.registerTool(d.name,$,(o={name:d.name,description:$.description,annotations:$.annotations,icons:$.icons,tags:d.tags,_meta:$._meta},c=mV(a),u=Object.freeze({metadata:function t(r,a=new WeakMap){if(null===r||"object"!=typeof r)return r;let n=Object.getPrototypeOf(r);if(!Array.isArray(r)&&n!==Object.prototype&&null!==n)return r;if(a.has(r))return a.get(r);let i=Array.isArray(r)?[]:Object.create(n);for(let[n,o]of(a.set(r,i),Object.entries(r)))Object.defineProperty(i,n,{value:t(o,a),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(i)}(o)}),(t,r)=>c({method:"tools/call",params:{name:u.metadata.name,arguments:t},tool:u},r,()=>l(t,r))))})}(t,fE(r,c),s),fE(n,c).forEach((r,a)=>{let n=fx(a),i={name:n,title:n,description:"No description provided"},o={},{default:s,metadata:l,schema:c}=r;if("object"==typeof l&&null!==l&&Object.assign(i,l),!1===i.enabled)return;let u=function(t,r="assistant"){return async(a,n)=>{let i,o=t(a,n);if(o instanceof Promise&&(o=await o),Array.isArray(o)||null!==o&&"object"==typeof o&&"messages"in o){let t=Array.isArray(o)?{messages:o}:o,r=await uR.GetPromptResult["~standard"].validate(t);if(r.issues){let t=r.issues.map(t=>{let r=t.path?.map(t=>"object"==typeof t?t.key:t).join(".");return`${r||"result"}: ${t.message}`});throw Error(`Invalid prompt result: ${t.join("; ")}`)}return t}if("string"==typeof o||"number"==typeof o)i={type:"text",text:"number"==typeof o?`${o}`:o};else{let t=mL(o);if(t.valid)i=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:i}]}}}(s,i.role||"assistant");
|
|
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:i}]}}}(s,i.role||"assistant");fk(c)?Object.assign(o,c):null!=c&&console.warn(`Invalid schema for prompt "${i.name}" at ${a}. Expected Record<string, z.ZodType>`),t.registerPrompt(i.name,{title:i.title,description:i.description,icons:i.icons,_meta:mp(i)._meta,argsSchema:fS(o)},u)}),o=fE(i,c),u=l?.registerResource,[...mm.getAll()].forEach(([r,n])=>{let i=n.mimeType||"text/html;profile=mcp-app",o=n?._meta?f$(n._meta):void 0,s={name:n.name,description:`Auto-generated resource for ${n.name} tool`,mimeType:n.mimeType,_meta:o},l=async(t,r)=>{if(n.mimeType&&n.toolPath)try{var o;let t,r,s=(o=n.toolPath,IS_CLOUDFLARE?function(t){let{normalizedPath:r,baseName:a}=fq(t),n=5381;for(let t=0;t<r.length;t++)n=Math.imul(n,33)+r.charCodeAt(t)>>>0;let i=n.toString(16).slice(0,6).padStart(6,"0");return`${a}_${i}`}(o):function(t){let{normalizedPath:r,baseName:n}=fq(t),i=a(6982).createHash("md5").update(r).digest("hex").slice(0,6);return`${n}_${i}`}(o)),l=function(t){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[t]||null;if(!IS_CLOUDFLARE)try{let r=a(9896),n=a(6928);for(let a of[n.join(process.cwd(),"dist","client"),n.join(process.cwd(),"client")]){let i=n.join(a,`${t}.bundle.js`),o=n.join(a,`${t}.bundle.css`);if(r.existsSync(i)){let t,a=r.readFileSync(i,"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 "${n.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:n.uri,text:d,mimeType:i,_meta:n._meta}]}}catch(t){throw console.error(`React failed for ${n.name}:`,t),t}let s=n.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:n.uri,text:s,mimeType:i,_meta:n._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:n.uri,text:"",mimeType:i,_meta:n._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:n.uri,text:t.text,mimeType:i,_meta:n._meta}]}}return{contents:[{uri:n.uri,text:"",mimeType:i,_meta:n._meta}]}};u?.(n.name,n.uri),t.registerResource(n.name,n.uri,s,l)}),o.forEach((r,a)=>{let n={name:
|
|
222
|
+
</html>`);return{contents:[{uri:n.uri,text:d,mimeType:i,_meta:n._meta}]}}catch(t){throw console.error(`React failed for ${n.name}:`,t),t}let s=n.handler({},r);if(s instanceof Promise&&(s=await s),"string"==typeof s)return{contents:[{uri:n.uri,text:s,mimeType:i,_meta:n._meta}]};if(s&&"object"==typeof s&&"_meta"in s&&!("content"in s))return{contents:[{uri:n.uri,text:"",mimeType:i,_meta:n._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:n.uri,text:t.text,mimeType:i,_meta:n._meta}]}}return{contents:[{uri:n.uri,text:"",mimeType:i,_meta:n._meta}]}};u?.(n.name,n.uri),t.registerResource(n.name,n.uri,s,l)}),o.forEach((r,a)=>{let n={name:fx(a),description:"No description provided"},{default:i,metadata:o,schema:s,complete:l}=r;if("object"==typeof o&&null!==o&&Object.assign(n,o),!1===n.enabled)return;let c={};fk(s)?c=s:null!=s&&console.warn(`Invalid schema for resource "${n.name}" at ${a}. Expected Record<string, z.ZodType>`);let d=fA(a);if(!d)return void console.warn(`Skipping resource "${n.name}" at ${a}: Invalid file path format`);let p=d.uriTemplate;n.mimeType&&n.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let m=function(t,r,a={}){let n=fA(r);if(!n)throw Error(`Invalid resource file path: ${r}. Must follow (scheme)/path/[param] convention.`);return async(r,i)=>{let o=t(function(t,r,a){let n={},i={};if(0===r.parameters.length)return i;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],i=r.match(/^\{(.+)\}$/);i&&(n[i[1]]=a)}for(let t of r.parameters){let r=n[t],o=a[t];if(void 0===r)throw Error(`Missing required parameter: ${t}`);if(!o){i[t]=r;continue}try{i[t]=o.parse(r)}catch(a){throw Error(`Invalid parameter "${t}": ${r}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return i}(r.href,n,a),i);if(o instanceof Promise&&(o=await o),cX(o))return o;if("string"==typeof o)return{contents:[{uri:r.href,text:o}]};if(!o||"object"!=typeof o||!Array.isArray(o.contents)){let t=null===o?"null":typeof o,r=void 0===o?"undefined":null===o?"null":"object"==typeof o?JSON.stringify(o,null,2):String(o);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${t}: ${r}
|
|
223
223
|
|
|
224
224
|
Expected ReadResourceResult format:
|
|
225
225
|
{
|
|
@@ -228,10 +228,10 @@ Expected ReadResourceResult format:
|
|
|
228
228
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
229
229
|
{ uri: "resource://uri", blob: base64data }
|
|
230
230
|
]
|
|
231
|
-
}`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(i,a,c);if("direct"===d.type)u?.(n.name,p),t.registerResource(n.name,p,mp(n),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pD(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let n={};for(let t of d.parameters){let a=r[t],i=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);i?n[t]=i.parse(a):n[t]=a}let o=i(n,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(n.name,a),t.registerResource(n.name,a,mp(n),o)}})}),t}async function
|
|
231
|
+
}`)}return o.contents.forEach(t=>{t.uri||(t.uri=r.href)}),o}}(i,a,c);if("direct"===d.type)u?.(n.name,p),t.registerResource(n.name,p,mp(n),m);else{let r=Object.create(null);for(let t of d.parameters)l&&Object.hasOwn(l,t)&&(r[t]=l[t]);let a=new pD(p,{list:void 0,complete:r}),o=async(t,r,a)=>{let n={};for(let t of d.parameters){let a=r[t],i=c[t];if(void 0===a)throw Error(`Missing required parameter: ${t}. Available variables: ${Object.keys(r)}`);i?n[t]=i.parse(a):n[t]=a}let o=i(n,a);return o instanceof Promise&&(o=await o),"string"==typeof o?{contents:[{uri:t.href,text:o}]}:o};u?.(n.name,a),t.registerResource(n.name,a,mp(n),o)}}),function(t,r,a,n){let i=[...fE(new Map(r.map(t=>[t.uri,{metadata:{name:t.frontmatter.name},skill:t}])),a).values()].map(({skill:t})=>t);if(0===i.length)return;for(let{frontmatter:r,files:a}of i){let i=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(i.length))}`,p=void 0!==s?{uri:a,mimeType:o,text:s}:{uri:a,mimeType:o,blob:l??""};n?.(d,a),t.registerResource(d,a,u,()=>({contents:[p]}))})}let o=i.map(fZ),s=new Map(o.map(t=>[t.uri,t]));t.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),t.server.setRequestHandler("skills/list",{params:fz},t=>{let r=t?.cursor===void 0?0:function(t,r){let a=NaN;try{a=Number(atob(t))}catch{}if(!Number.isSafeInteger(a)||a<=0||a>=r)throw new cg(cf.InvalidParams,`Invalid cursor: ${t}`);return a}(t.cursor,o.length),a=r+50;return{skills:o.slice(r,a),...a<o.length?{nextCursor:btoa(String(a))}:{},...fM}}),t.server.setRequestHandler("skills/get",{params:fL},({uri:t})=>{let r=s.get(t);if(!r)throw new cg(cf.InvalidParams,`No skill is served at ${t}`);return{skill:r,...fM}})}(t,fB,c,l?.registerResource)}),t}async function fW(){let{toolModules:t,skippedTools:r}=await fU(fF);return fV(r),t}async function fY(){let{promptModules:t,skippedPrompts:r}=await fj(fH);return fO(r),t}async function fX(){let{resourceModules:t,skippedResources:r}=await fI(fJ);return fN(r),t}let fQ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, OPTIONS","Access-Control-Allow-Headers":"*","Access-Control-Max-Age":"86400"};function f0(t,r,a,n,i){let o=new URL(t.url).origin,s=`${o}/.well-known/oauth-protected-resource`;return new Response(JSON.stringify({jsonrpc:"2.0",error:{code:i,message:a},id:null}),{status:n,headers:{"WWW-Authenticate":`Bearer error="${r}", error_description="${a}", resource_metadata="${s}"`,"Content-Type":"application/json"}})}function f1(t,r){return async a=>{var n,i;let o,{verifyToken:s,required:l=!1,requiredScopes:c}=r,u=function(t){let r=t.headers.get("Authorization"),[a,n]=r?.split(" ")||[];return a?.toLowerCase()==="bearer"?n:void 0}(a);try{o=await s(a,u)}catch(t){return console.error("[MCP Auth] Error verifying token:",t),f0(a,"invalid_token","Invalid token",401,-32001)}return l&&!o?f0(a,"invalid_token","No authorization provided",401,-32001):o?void 0!==(n=o).expiresAt&&n.expiresAt<Date.now()/1e3?f0(a,"invalid_token","Token has expired",401,-32001):c?.length&&(i=o,!c.every(t=>i.scopes.includes(t)))?f0(a,"insufficient_scope","Insufficient scope",403,-32002):(a.auth=o,t(a)):t(a)}}function f2(t){return r=>{let a;return new Response(JSON.stringify({resource:((a=new URL(r.url)).pathname=a.pathname.replace(/^\/\.well-known\/[^\/]+/,""),"/"===a.pathname?a.toString().replace(/\/$/,""):a.toString()),authorization_servers:t.authorizationServers}),{headers:{...fQ,"Cache-Control":"max-age=3600","Content-Type":"application/json"}})}}function f9(t){return new Response(null,{status:200,headers:fQ})}let f4=function(t,r={}){var a;let{legacy:n,onerror:i,responseMode:o}=r,s=pQ(r.maxRequestBodySize);if("function"==typeof n)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{i?.(t)}catch{}},f=r.bus??new pP(h),g={toolsChanged:()=>f.publish({kind:"tools_list_changed"}),promptsChanged:()=>f.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>f.publish({kind:"resources_list_changed"}),resourceUpdated:t=>f.publish({kind:"resource_updated",uri:t})},y=function(t){let{bus:r,onerror:a}=t,n=t.maxSubscriptions??1024,i=t.keepAliveMs??15e3,o=new Set;return{serve:function(t,s,l,c){var u,d,p;let m,h,f,g,y,v,_;if(o.size>=n)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${n})`)),pE(t.id,-32603,"Subscription limit reached");let b=(u=t,(y=cA(cq).validateRequest("subscriptions/listen",u)).ok?y.value.params?.notifications:void 0);if(void 0===b)return pE(t.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let S=(d=b,p=l,v={},_=t=>void 0===p||!0===t,!0===d.toolsListChanged&&_(p?.tools?.listChanged)&&(v.toolsListChanged=!0),!0===d.promptsListChanged&&_(p?.prompts?.listChanged)&&(v.promptsListChanged=!0),!0===d.resourcesListChanged&&_(p?.resources?.listChanged)&&(v.resourcesListChanged=!0),void 0!==d.resourceSubscriptions&&d.resourceSubscriptions.length>0&&_(p?.resources?.subscribe)&&(v.resourceSubscriptions=[...d.resourceSubscriptions]),v),$=t.id,w=new TextEncoder,R=!1,k=t=>{if(!R)try{m.enqueue(w.encode(t))}catch(t){a?.(t instanceof Error?t:Error(String(t)))}},x=(t,r)=>{k(`event: message
|
|
232
232
|
data: ${JSON.stringify({jsonrpc:"2.0",method:t,params:r})}
|
|
233
233
|
|
|
234
234
|
`)},P=t=>{if(!R){t&&k(`event: message
|
|
235
235
|
data: ${JSON.stringify({jsonrpc:"2.0",id:$,result:{resultType:"complete",_meta:{[iW]:$,[iK]:c}}})}
|
|
236
236
|
|
|
237
|
-
`),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),g?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pT({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pT(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=px(i,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),g=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror: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"===n?void 0:(a=r.keepAliveMs,async(r,n)=>{if("POST"!==r.method.toUpperCase())return p9(405,-32e3,"Method not allowed.");try{let i=await t({era:"legacy",...n?.authInfo!==void 0&&{authInfo:n.authInfo},requestInfo:r}),o=new p1({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await i.connect(o);let l=()=>{o.close().catch(()=>{}),i.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...n?.authInfo!==void 0&&{authInfo:n.authInfo},...n?.parsedBody!==void 0&&{parsedBody:n.parsedBody}});if(null===c.body||"text/event-stream"!==uq(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{h?.(p3(t))}catch{}return p6(p2(n?.parsedBody))}});async function _(a,n,i){var s,c;let f=a.classification.revision;if(void 0===f||!lY.includes(f)){let t=new c_({supported:[...lY],requested:f??"unknown"});return h(t),p9(400,t.code,t.message,t.data,p2(a.message))}let g=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return ua("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return ua("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let n=function(t,r){let a=Object.hasOwn(un,t)?un[t]:void 0;if(void 0===a)return;let n=uo(r)?r[a]:void 0;return{field:a,value:"string"==typeof n?n:void 0}}(a,r.message.params);if(void 0===n)return;let{field:i,value:o}=n;if(void 0===t.mcpNameHeader){if(void 0===o)return;return ua("name-header-missing","(missing)",`the body carries params.${i}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=ui(t.mcpNameHeader),l=c7(s);return void 0===l?ua("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?ua("name-header-mismatch",s,`the body carries params.${i}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:n.method,...p7(n)},a);if(void 0!==g)return h(Error(`Rejected inbound request (${g.cell}): ${g.message}`)),p4(g,p2(a.message));let v="request"===a.messageKind?cV(a.message.params):void 0,_=v?.[iG];if("request"===a.messageKind){let t=Object.hasOwn(lB,s=a.message.method)?lB[s]:void 0;if(void 0!==t){let r=lG(t,_);if(void 0!==r){let t=new cb({requiredCapabilities:r});return h(t),p9(ut[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:n}),S=b instanceof pZ?b.server:b;if(p5(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=m(S);return b.close().catch(h),y.serve(a.message,n.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pZ){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,i=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==i){let r=c2(i);if(r.valid&&r.declarations.length>0){let i=function(t,r,a){for(let n of t){let t=`Mcp-Param-${n.headerName}`,i=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,n.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===i)return c8("param-header-missing",t,`the body carries ${c3(n.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=c7(i);if(void 0===l)return c8("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===n.type||"number"===n.type)&&c5.test(l)&&"number"==typeof o?Number(l)===o:l===s))return c8("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c3(n.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,n.headers);if(void 0!==i)return b.close().catch(h),h(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p4(i,a.message.id)}}}if("request"===a.messageKind&&b instanceof pZ)try{let t=await pC([a.message],i,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(h),pN(t,pI(i))}catch(t){return b.close().catch(h),h(p3(t)),p6(a.message.id)}p5(S),u(S,f),p(S,lY),void 0!==v&&(c={clientInfo:v[iB],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 pY(b,a.message,{classification:a.classification,request:n,...void 0!==i&&{authInfo:i},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lJ&&t.code===lH.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),h(p3(t)),p6(p2(a.message))}}async function b(t,r,a,n){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==n&&{parsedBody:n}});let i=function(t,r){switch(t.reason){case"http-method":return ur("http-method","modern-only-method-not-allowed",405,new cg(-32e3,"Method not allowed."),!0);case"batch":return ur("jsonrpc-shape","modern-only-batch-not-supported",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ur("jsonrpc-shape","modern-only-response-post",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ur("era-classification","modern-only-missing-envelope",400,void 0===a?new cg(cf.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new c_({supported:[...r],requested:a}),!0)}}}(t,lY);return void 0===i?new Response(null,{status:202}):(h(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p4(i,p2(n)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uA(t.headers.get("content-type")))return h(Error("Unsupported Media Type: Content-Type must be application/json")),p9(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let n=await p8(t,r?.parsedBody,!0,s);if("unreadable-body"===n.step)return p9(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===n.step)return p9(413,-32e3,pX(s));if("no-json-body"===n.step)return void 0!==v?v(n.forwardRequest,{...void 0!==a&&{authInfo:a}}):p9(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:i,body:o,parsedBody:l,forwardRequest:c}=n;try{switch(i.kind){case"reject":return h(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p4(i,p2(o));case"modern":return await _(i,t,a);case"legacy":return await b(i,c,a,l)}}catch(t){return h(p3(t)),p6(p2(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return h(p3(t)),p6(p2(r?.parsedBody))}},notify:g,bus:f,close:async()=>{c=!0,y.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function t(){let t=fV(),r=fF(),a=fH(),[n,i,o]=await Promise.all([t,r,a]),{instructions:s,...l}=fD,c=new pZ(l,{instructions:s});return await fU(c,n,i,o),c},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fX(t){return ms({id:(0,R.randomUUID)(),headers:Object.fromEntries(t.headers.entries()),clientInfo:void 0},async()=>{try{let r;return"POST"===t.method&&(r=await t.json().catch(()=>void 0),mi({clientInfo:(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mu(r);if(t)return t}})(r)})),await fY.fetch(t,{authInfo:t.auth,parsedBody:r})}catch(t){return console.error("[Next.js MCP] Error handling MCP request:",t),Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null},{status:500})}})}function fQ(t){let r=new URL(t.url),a=r.hostname.split(".").reverse().join("."),n={$schema:"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",name:`${a}/mcp`,version:SERVER_INFO.version,description:TEMPLATE_CONFIG.description,title:TEMPLATE_CONFIG.name,remotes:[{type:"streamable-http",url:`${r.origin}${HTTP_CONFIG.endpoint}`}]};return TEMPLATE_CONFIG.icons?.length&&(n.icons=TEMPLATE_CONFIG.icons),Response.json(n,{headers:{"Content-Type":"application/mcp-server-card+json","Cache-Control":"public, max-age=3600, must-revalidate","Access-Control-Allow-Origin":"*"}})}})(),n})());
|
|
237
|
+
`),R=!0;try{h?.()}catch(t){a?.(t instanceof Error?t:Error(String(t)))}void 0!==f&&clearInterval(f),g?.(),o.delete(P);try{m.close()}catch{}}},E=new ReadableStream({start(t){m=t;let a=pT({method:"notifications/subscriptions/acknowledged",params:{notifications:S}},$);(x(a.method,a.params),0===Object.keys(S).length)?P(!0):(h=r.subscribe(t=>{if(R||!function(t,r){switch(r.kind){case"tools_list_changed":return!0===t.toolsListChanged;case"prompts_list_changed":return!0===t.promptsListChanged;case"resources_list_changed":return!0===t.resourcesListChanged;case"resource_updated":return void 0!==t.resourceSubscriptions&&t.resourceSubscriptions.includes(r.uri)}}(S,t))return;let r=pT(function(t){switch(t.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed"};case"prompts_list_changed":return{method:"notifications/prompts/list_changed"};case"resources_list_changed":return{method:"notifications/resources/list_changed"};case"resource_updated":return{method:"notifications/resources/updated",params:{uri:t.uri}}}}(t),$);x(r.method,r.params)}),f=px(i,()=>k(": keepalive\n\n")),o.add(P))},cancel(){P(!1)}});if(void 0!==s)if(s.aborted)P(!1);else{let t=()=>P(!1);s.addEventListener("abort",t,{once:!0}),g=()=>s.removeEventListener("abort",t)}return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let t of o)t(!0)},get openCount(){return o.size}}}({bus:f,maxSubscriptions:r.maxSubscriptions??1024,keepAliveMs:r.keepAliveMs??15e3,onerror: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"===n?void 0:(a=r.keepAliveMs,async(r,n)=>{if("POST"!==r.method.toUpperCase())return p9(405,-32e3,"Method not allowed.");try{let i=await t({era:"legacy",...n?.authInfo!==void 0&&{authInfo:n.authInfo},requestInfo:r}),o=new p1({sessionIdGenerator:void 0,...void 0!==a&&{keepAliveMs:a},...void 0!==s&&{maxRequestBodySize:s}});await i.connect(o);let l=()=>{o.close().catch(()=>{}),i.close().catch(()=>{})};r.signal?.addEventListener("abort",l,{once:!0});let c=await o.handleRequest(r,{...n?.authInfo!==void 0&&{authInfo:n.authInfo},...n?.parsedBody!==void 0&&{parsedBody:n.parsedBody}});if(null===c.body||"text/event-stream"!==uq(c.headers.get("content-type")))return l(),c;let u=c.body.getReader(),d=!1,p=()=>{d||(d=!0,l())},m=new ReadableStream({pull:async t=>{try{let{done:r,value:a}=await u.read();if(r){p(),t.close();return}void 0!==a&&t.enqueue(a)}catch(r){p(),t.error(r)}},cancel:t=>(p(),u.cancel(t).catch(()=>{}))});return new Response(m,{status:c.status,statusText:c.statusText,headers:c.headers})}catch(t){try{h?.(p3(t))}catch{}return p6(p2(n?.parsedBody))}});async function _(a,n,i){var s,c;let f=a.classification.revision;if(void 0===f||!lY.includes(f)){let t=new c_({supported:[...lY],requested:f??"unknown"});return h(t),p9(400,t.code,t.message,t.data,p2(a.message))}let g=function(t,r){if("request"!==r.messageKind)return;let a=r.message.method;if(void 0===t.protocolVersionHeader){let t=r.classification.revision;return ua("version-header-missing","(missing)",void 0===t?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${t} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===t.mcpMethodHeader)return ua("method-header-missing","(missing)",`the body names method ${a} but the required Mcp-Method header is absent`,"standard-header-validation");let n=function(t,r){let a=Object.hasOwn(un,t)?un[t]:void 0;if(void 0===a)return;let n=uo(r)?r[a]:void 0;return{field:a,value:"string"==typeof n?n:void 0}}(a,r.message.params);if(void 0===n)return;let{field:i,value:o}=n;if(void 0===t.mcpNameHeader){if(void 0===o)return;return ua("name-header-missing","(missing)",`the body carries params.${i}="${o}" but the required Mcp-Name header is absent`,"standard-header-validation")}let s=ui(t.mcpNameHeader),l=c7(s);return void 0===l?ua("name-header-invalid-encoding",s,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==o&&l!==o?ua("name-header-mismatch",s,`the body carries params.${i}="${o}" but the Mcp-Name header names "${l}"`,"standard-header-validation"):void 0}({httpMethod:n.method,...p7(n)},a);if(void 0!==g)return h(Error(`Rejected inbound request (${g.cell}): ${g.message}`)),p4(g,p2(a.message));let v="request"===a.messageKind?cV(a.message.params):void 0,_=v?.[iG];if("request"===a.messageKind){let t=Object.hasOwn(lB,s=a.message.method)?lB[s]:void 0;if(void 0!==t){let r=lG(t,_);if(void 0!==r){let t=new cb({requiredCapabilities:r});return h(t),p9(ut[t.code]??400,t.code,t.message,t.data,a.message.id)}}}let b=await t({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:n}),S=b instanceof pZ?b.server:b;if(p5(S),"request"===a.messageKind&&"subscriptions/listen"===a.message.method){let t=S.getCapabilities(),r=m(S);return b.close().catch(h),y.serve(a.message,n.signal,t,r)}if("request"===a.messageKind&&"tools/call"===a.message.method&&b instanceof pZ){let t=a.message.params,r="string"==typeof t?.name?t.name:void 0,i=void 0===r?void 0:b.toolInputSchemaJson(r);if(void 0!==i){let r=c2(i);if(r.valid&&r.declarations.length>0){let i=function(t,r,a){for(let n of t){let t=`Mcp-Param-${n.headerName}`,i=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,n.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===i)return c8("param-header-missing",t,`the body carries ${c3(n.path)}=${JSON.stringify(o)} but the ${t} header is absent`);let l=c7(i);if(void 0===l)return c8("param-header-invalid-encoding",t,`the ${t} header carries an invalid Base64 sentinel value`);if(!(("integer"===n.type||"number"===n.type)&&c5.test(l)&&"number"==typeof o?Number(l)===o:l===s))return c8("param-header-mismatch",t,`the ${t} header decodes to ${JSON.stringify(l)} but the body carries ${c3(n.path)}=${JSON.stringify(o)}`)}}(r.declarations,t?.arguments,n.headers);if(void 0!==i)return b.close().catch(h),h(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p4(i,a.message.id)}}}if("request"===a.messageKind&&b instanceof pZ)try{let t=await pC([a.message],i,t=>b.resolveScopeChallenge(t));if(void 0!==t)return b.close().catch(h),pN(t,pI(i))}catch(t){return b.close().catch(h),h(p3(t)),p6(a.message.id)}p5(S),u(S,f),p(S,lY),void 0!==v&&(c={clientInfo:v[iB],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 pY(b,a.message,{classification:a.classification,request:n,...void 0!==i&&{authInfo:i},...void 0!==o&&{responseMode:o},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return"notification"===a.messageKind&&queueMicrotask(()=>void S.close().catch(()=>{})),t}catch(t){if(t instanceof lJ&&t.code===lH.ConnectionClosed)return new Response(null,{status:499});return await S.close().catch(()=>{}),l.delete(S),h(p3(t)),p6(p2(a.message))}}async function b(t,r,a,n){if(void 0!==v)return v(r,{...void 0!==a&&{authInfo:a},...void 0!==n&&{parsedBody:n}});let i=function(t,r){switch(t.reason){case"http-method":return ur("http-method","modern-only-method-not-allowed",405,new cg(-32e3,"Method not allowed."),!0);case"batch":return ur("jsonrpc-shape","modern-only-batch-not-supported",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ur("jsonrpc-shape","modern-only-response-post",400,new cg(cf.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let a=t.requestedVersion;return ur("era-classification","modern-only-missing-envelope",400,void 0===a?new cg(cf.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...r]}):new c_({supported:[...r],requested:a}),!0)}}}(t,lY);return void 0===i?new Response(null,{status:202}):(h(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p4(i,p2(n)))}async function S(t,r){let a=r?.authInfo;if("POST"===t.method.toUpperCase()&&!uA(t.headers.get("content-type")))return h(Error("Unsupported Media Type: Content-Type must be application/json")),p9(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let n=await p8(t,r?.parsedBody,!0,s);if("unreadable-body"===n.step)return p9(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===n.step)return p9(413,-32e3,pX(s));if("no-json-body"===n.step)return void 0!==v?v(n.forwardRequest,{...void 0!==a&&{authInfo:a}}):p9(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:i,body:o,parsedBody:l,forwardRequest:c}=n;try{switch(i.kind){case"reject":return h(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p4(i,p2(o));case"modern":return await _(i,t,a);case"legacy":return await b(i,c,a,l)}}catch(t){return h(p3(t)),p6(p2(o))}}return{fetch:async(t,r)=>{if(c)throw Error("This MCP handler has been closed");try{return await S(t,r)}catch(t){return h(p3(t)),p6(p2(r?.parsedBody))}},notify:g,bus:f,close:async()=>{c=!0,y.closeAll();let t=[...l].map(t=>t.close().catch(()=>{}));l.clear(),await Promise.all(t)}}}(async function t(){let t=fW(),r=fY(),a=fX(),[n,i,o]=await Promise.all([t,r,a]),{instructions:s,...l}=fK,c=new pZ(l,{instructions:s});return await fG(c,n,i,o),c},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function f3(t){return ms({id:(0,R.randomUUID)(),headers:Object.fromEntries(t.headers.entries()),clientInfo:void 0},async()=>{try{let r;return"POST"===t.method&&(r=await t.json().catch(()=>void 0),mi({clientInfo:(t=>{for(let r of Array.isArray(t)?t:[t]){let t=mu(r);if(t)return t}})(r)})),await f4.fetch(t,{authInfo:t.auth,parsedBody:r})}catch(t){return console.error("[Next.js MCP] Error handling MCP request:",t),Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null},{status:500})}})}function f6(t){let r=new URL(t.url),a=r.hostname.split(".").reverse().join("."),n={$schema:"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",name:`${a}/mcp`,version:SERVER_INFO.version,description:TEMPLATE_CONFIG.description,title:TEMPLATE_CONFIG.name,remotes:[{type:"streamable-http",url:`${r.origin}${HTTP_CONFIG.endpoint}`}]};return TEMPLATE_CONFIG.icons?.length&&(n.icons=TEMPLATE_CONFIG.icons),Response.json(n,{headers:{"Content-Type":"application/mcp-server-card+json","Cache-Control":"public, max-age=3600, must-revalidate","Access-Control-Allow-Origin":"*"}})}})(),n})());
|