xmcp 1.10.4 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/handlers.d.ts +16 -0
- package/dist/client/index.d.ts +6 -1
- package/dist/client/managed.d.ts +3 -9
- package/dist/client.js +2 -2
- package/dist/config/index.d.ts +165 -1
- package/dist/config/schemas/cache-hints.d.ts +119 -0
- package/dist/config/schemas/index.d.ts +1 -0
- package/dist/config.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/runtime/adapter-express.js +16 -24
- package/dist/runtime/adapter-fastify.js +16 -24
- package/dist/runtime/adapter-fetch-cloudflare.js +21 -29
- package/dist/runtime/adapter-fetch.js +16 -24
- package/dist/runtime/adapter-nestjs.js +16 -24
- package/dist/runtime/adapter-nextjs.js +16 -24
- package/dist/runtime/cloudflare-worker.js +28 -36
- package/dist/runtime/contexts/request-context.d.ts +7 -1
- package/dist/runtime/http.js +22 -30
- package/dist/runtime/stdio.js +19 -27
- package/dist/runtime/utils/mcp-authorization.d.ts +33 -0
- package/dist/runtime/utils/mcp-middleware.d.ts +7 -2
- package/dist/runtime/utils/schema-compat.d.ts +26 -0
- package/dist/runtime/utils/server.d.ts +5 -2
- package/dist/runtime/utils/skills.d.ts +6 -1
- package/dist/runtime/utils/transformers/tool.d.ts +4 -3
- package/dist/runtime/vercel.js +23 -31
- package/dist/types/mcp-middleware.d.ts +52 -0
- package/dist/types/resource.d.ts +7 -1
- package/dist/types/tool.d.ts +5 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var a in r)("object"==typeof exports?exports:e)[a]=r[a]}}(this,()=>(()=>{"use strict";var e={6982(e){e.exports=require("crypto")},9896(e){e.exports=require("fs")},6928(e){e.exports=require("path")}},t={};function r(a){var i=t[a];if(void 0!==i)return i.exports;var n=t[a]={exports:{}};return e[a](n,n.exports,r),n.exports}r.d=(e,t,a)=>{var i=(t,a)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,[a]:t[i]})};i(t,"get"),i(a,"value")},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{let e,t,i,n,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w;r.r(a),r.d(a,{resourceMetadataHandler:()=>fL,resourceMetadataOptions:()=>fZ,serverCardHandler:()=>fV,withAuth:()=>fM,xmcpHandler:()=>fU});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,z,M,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),J=(e,t,r)=>(r=null!=e?L(V(e)):{},((e,t,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var a,i=U(t),n=0,o=i.length;n<o;n++)a=i[n],F.call(e,a)||void 0===a||Z(e,a,{get:(e=>t[e]).bind(null,a),enumerable:!(r=D(t,a))||r.enumerable});return e})(!t&&e&&e.__esModule?r:Z(r,"default",{value:e,enumerable:!0}),e));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(e){let t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,r])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function X(e,t="|"){return e.map(e=>eb(e)).join(t)}function Q(e,t){return"bigint"==typeof t?t.toString():t}class ee{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return void 0!==e&&(this._value=e(),this._getter=void 0),this._value}}function et(e){return new ee(e)}function er(e){let t=+!!e.startsWith("^"),r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}let ea=Symbol("evaluating");function ei(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function en(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function eo(e){return en(e._zod.def)??e._zod.def.shape}function es(e,t,r){Object.defineProperty(e,t,{get(){let e=r();return ei(this,t,e),e},enumerable:!0,configurable:!0})}function el(e,t,r){t in e?ei(e,t,r):e[t]=r}function ec(e,t,r,a){let i=eo(t);for(let n of r){let r=Object.getOwnPropertyDescriptor(i,n);r.enumerable&&(r.get?es(e,n,()=>{let e=t._zod.def.shape[n];return a?a(e,n):e}):el(e,n,a?a(r.value,n):r.value))}}function eu(...e){let t={};for(let r of e)Object.assign(t,Object.getOwnPropertyDescriptors(r));return Object.defineProperties({},t)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ep(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let em=et(()=>{if(eB.jitless||"u">typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(e){return!1}});function eh(e){if(!1===ep(e))return!1;let t=e.constructor;if(void 0===t||"function"!=typeof t)return!0;let r=t.prototype;return!1!==ep(r)&&!1!==Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")}function ef(e){return eh(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}let eg=new Set(["string","number","symbol"]);function ey(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(e,t,r){let a=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(a._zod.parent=e),a}function e_(e){if(!e)return{};if("string"==typeof e)return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");e.error=e.message}return(delete e.message,"string"==typeof e.error)?{...e,error:()=>e.error}:e}function eb(e){return"bigint"==typeof e?e.toString()+"n":"string"==typeof e?`"${e}"`:`${e}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(e,t){let r=eo(e),a=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&a.push(e)}return a}function eR(e,t){let r={};ec(r,e,Reflect.ownKeys(eo(e)));for(let e of Reflect.ownKeys(t)){let a=Object.getOwnPropertyDescriptor(t,e);a.enumerable&&(a.get?es(r,e,()=>t[e]):el(r,e,a.value))}return r}function ek(e,t,r,a="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=r?new Set(ew(t,r)):void 0,o={};return ec(o,t,Reflect.ownKeys(eo(t)),e&&((t,r)=>n&&!n.has(r)?t:new e({type:"optional",innerType:t}))),ev(t,eu(t._zod.def,{shape:o,checks:[]}))}function ex(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function eP(e,t){return t.map(t=>(t.path??(t.path=[]),t.path.unshift(e),t))}function eE(e){return"string"==typeof e?e:e?.message}function eT(e){let t=[];for(let r of e??[]){let e=r._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let a=e.maximum??e.length??e.size;a>=0&&t.push([a,r])}return t}function ej(e,t,r){var a;for(let i=t;i<e.length;i++)(a=e[i]).schema??(a.schema=r)}function eO(e,t,r){let a=e.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?e.schema??(e.schema=e.inst):e.schema=e.inst);let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,n=e.message?e.message:eE(e.inst?._zod.def?.error?.(e))??eE(i?.(e))??eE(t?.error?.(e))??eE(r.customError?.(e))??eE(r.localeError?.(e))??"Invalid input",o={};for(let t of Object.keys(e))"inst"!==t&&"schema"!==t&&"continue"!==t&&"input"!==t&&"__proto__"!==t&&(o[t]=e[t]);return o.path??(o.path=[]),o.message=n,t?.reportInput&&(o.input=e.input),o}let eC=/[\uD800-\uDBFF]/;function eI(e){let t=e.length;if(!eC.test(e))return t;let r=t;for(let a=0;a<t-1;a++)(64512&e.charCodeAt(a))==55296&&(64512&e.charCodeAt(a+1))==56320&&(r--,a++);return r}function eN(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function eq(...e){let[t,r,a]=e;return"string"==typeof t?{message:t,code:"custom",input:r,inst:a}:{...t}}function eA(e,t,r,a=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:a,value:r}),r}function ez(e,t){for(let r in e){let a=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return eA(this,r,a(this))},set(e){eA(this,r,e)}})}return t}let eM=!1,eL={configurable:!0,get(){eM=!0}};function eZ(t,r,a){let i=Object.getPrototypeOf(t._zod);if(r in i&&e!==t._zod){e=void 0;return}e=t._zod,Object.defineProperty(i,r,{configurable:!0,get(){Object.defineProperty(this,r,eL);let e=eM;eM=!1;try{let t=a(this);return eM?delete this[r]:Object.defineProperty(this,r,{configurable:!0,writable:!0,value:t}),eM=eM||e,t}catch(t){throw delete this[r],eM=eM||e,t}},set(e){Object.defineProperty(this,r,{configurable:!0,writable:!0,value:e})}})}let eD=Object.freeze({status:"aborted"}),eU={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eF(e,t,r,a){function i(e){this.def=e,this.constr=c,this.traits=new Set}i.prototype={};let n=r&&new WeakSet;function o(a,o){if(a._zod){if(a._zod.traits.has(e))return}else{eU.value=new i(o);try{Object.defineProperty(a,"_zod",eU)}finally{eU.value=void 0}}if(a._zod.traits.add(e),t(a,o),n){let e=Object.getPrototypeOf(a),t=a._zod.constr.prototype,i=e;for(;i&&i!==t;)i=Object.getPrototypeOf(i);let o=i??e;if(!n.has(o)){n.add(o);for(let e in r){let t=Object.getOwnPropertyDescriptor(r,e);t.get?Object.defineProperty(o,e,{...t,enumerable:!1}):function(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:eA(this,t,r.bind(this))},set(e){eA(this,t,e)}})}(o,e,t.value)}}}let s=c.prototype;for(let e in s)Object.prototype.hasOwnProperty.call(s,e)&&(e in a||(a[e]=s[e].bind(a)))}let s=a?.Parent??Object;class l extends s{}function c(e){let t=a?.Parent?function(e){let t=eV;if(t){let r=t.stackTraceLimit;if("number"==typeof r){try{t.stackTraceLimit=0}catch{return eV=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}(l):this;o(t,e);let r=t._zod.deferred;if(r){for(let e of r)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(l,"name",{value:e}),Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:t=>!!a?.Parent&&t instanceof a.Parent||t?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class eH extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eJ extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eB=globalThis.__zod_globalConfig;function eK(e){return e&&Object.assign(eB,e),eB}class eG extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eW="~memo",eY=[];function eX(e){return null!==e&&"object"==typeof e}function eQ(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}let e0=new WeakMap,e1=[],e2={alloc(e,r,a){let i=t;if(!i)return a;t=void 0;let n={value:a,issues:null};return i.set(r.value,n),e1.push(n),a},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,r=(e,r)=>{var a,i;let n;if("backward"!==r.direction&&(a=r,i=e.value,void 0!==(n=a[eW]?.backEdges)&&eX(i)&&n.has(i)))throw new eG;return t(e,r)};e._zod.parse=r,e._zod.run===t&&(e._zod.run=r)})},attach(e){var r;let a,i,n,o=!1;(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,s=(l,c)=>{let u;if(void 0===a){let t=function e(t,r,a){var i,n;let o=e0.get(t);if(void 0!==o)return 2*!!o;if(r.has(t))return 2;r.add(t);let s=0,l=t=>{if(2!==s&&t?._zod){let i=e(t,r,a);i>s&&(s=i)}},c=e=>{e>s&&(s=e)},u=t._zod.def;switch(u.type){case"object":{let t=en(u);c(t?((t,i)=>{let n=0;for(let o of Reflect.ownKeys(t)){let s=Object.getOwnPropertyDescriptor(t,o);if(i&&!s.enumerable)continue;let l=s.get?1:s.value?._zod?e(s.value,r,a):0;l>n&&(n=l)}return n})(t,!0):1),l(u.catchall);break}case"array":l(u.element);break;case"tuple":for(let e of u.items)l(e);l(u.rest);break;case"record":case"map":l(u.keyType),l(u.valueType);break;case"set":l(u.valueType);break;case"union":for(let e of u.options)l(e);break;case"intersection":l(u.left),l(u.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":l(u.innerType);break;case"pipe":l(u.in),l(u.out);break;case"function":l(u.input),l(u.output);break;case"lazy":{let i=u._cachedInner??(a?t._zod.innerType:void 0);c(i?e(i,r,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let e in u){let t=Object.getOwnPropertyDescriptor(u,e);if(!t||t.get)continue;let r=t.value;if(r&&"object"==typeof r){if(r._zod)l(r);else if(Array.isArray(r))for(let e of r)l(e)}}}return r.delete(t),i=t,1!==(n=s)&&e0.set(i,2===n),n}(e,new Set,!1);if(0===t)return e._zod.parse=r,e._zod.run===s&&(e._zod.run=r),r(l,c);2===t||o?a=!0:o=!0}let d=l.value;if(!eX(d))return r(l,c);let p=c[eW];if(p||(p={buckets:new WeakMap,backEdges:void 0},c[eW]=p),i===c)u=n;else{var m;let t;(t=(m=p).buckets.get(e))||(t=new WeakMap,m.buckets.set(e,t)),u=t,i=c,n=u}let h=u.get(d);if(h)return l.value=h.value,h.issues?h.issues.length&&l.issues.push(...eQ(h.issues)):(l.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(h.value)),l;t=u;let f=e1.length,g=r(l,c);t=void 0;let y=e1.length>f?e1.pop():void 0;return g instanceof Promise?g.then(e=>(y&&(y.issues=e.issues.length?eQ(e.issues):eY),e)):(y&&(y.issues=g.issues.length?eQ(g.issues):eY),g)};e._zod.parse=s,e._zod.run===r&&(e._zod.run=s)})}},e9=/^[cC][0-9a-z]{6,}$/,e4=/^[0-9a-z]+$/,e3=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,e8=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,te=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,tt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,ta=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ti=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,tn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tu=RegExp(`^${tc}$`);function td(e){let t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eF("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])}),tb=e=>{let t=e.value;return null!=t&&void 0!==t.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eF("$ZodCheckLessThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value<=t.value:a.value<t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tw=eF("$ZodCheckGreaterThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value>=t.value:a.value>t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tR=eF("$ZodCheckMultipleOf",(e,t)=>{t_.init(e,t),e._zod.check=r=>{let a,i,n;if(typeof r.value!=typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof r.value?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):0==(i=Math.round(a=r.value/t.value),n=4*Number.EPSILON*Math.max(Math.abs(a),1),Math.abs(a-i)<n?0:a-i))||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),tk=eF("$ZodCheckNumberFormat",(e,t)=>{t_.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),a=r?"int":"number",[i,n]=eS[t.format];e._zod.check=o=>{let s=o.value;if(r){if(!Number.isInteger(s))return void o.issues.push({expected:a,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?o.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}))}s<i&&o.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>n&&o.issues.push({origin:"number",input:s,code:"too_big",maximum:n,inclusive:!0,inst:e,continue:!t.abort})}}),tx=eF("$ZodCheckMaxLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>t.maximum?eI(a):i)<=t.maximum)return;let n=eN(a);r.issues.push({origin:n,code:"too_big",maximum:t.maximum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tP=eF("$ZodCheckMinLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>=t.minimum&&i<2*t.minimum?eI(a):i)>=t.minimum)return;let n=eN(a);r.issues.push({origin:n,code:"too_small",minimum:t.minimum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tE=eF("$ZodCheckLengthEquals",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length,n="string"==typeof a&&i>=t.length&&i<=2*t.length?eI(a):i;if(n===t.length)return;let o=eN(a),s=n>t.length;r.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),tT=eF("$ZodCheckStringFormat",(e,t)=>{var r,a;t_.init(e,t),t.pattern?(r=e._zod).check??(r.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(a=e._zod).check??(a.check=()=>{})}),tj=eF("$ZodCheckRegex",(e,t)=>{tT.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),tO=eF("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ty),tT.init(e,t)}),tC=eF("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tv),tT.init(e,t)}),tI=eF("$ZodCheckIncludes",(e,t)=>{t_.init(e,t);let r=ey(t.includes),a=new RegExp("number"==typeof t.position?`^.{${t.position},}${r}`:r);t.pattern=a,e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),tN=eF("$ZodCheckStartsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`^${ey(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),tq=eF("$ZodCheckEndsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`.*${ey(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),tA=eF("$ZodCheckOverwrite",(e,t)=>{t_.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class tz{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if("function"==typeof e){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let t=e.split("\n").filter(e=>e),r=Math.min(...t.map(e=>e.length-e.trimStart().length));for(let e of t.map(e=>e.slice(r)).map(e=>" ".repeat(2*this.indent)+e))this.content.push(e)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var a in r)("object"==typeof exports?exports:e)[a]=r[a]}}(this,()=>(()=>{"use strict";var e={6982(e){e.exports=require("crypto")},9896(e){e.exports=require("fs")},6928(e){e.exports=require("path")}},t={};function r(a){var i=t[a];if(void 0!==i)return i.exports;var n=t[a]={exports:{}};return e[a](n,n.exports,r),n.exports}r.d=(e,t,a)=>{var i=(t,a)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,[a]:t[i]})};i(t,"get"),i(a,"value")},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{let e,t,i,n,o,s,l,c,u,d,p,m,h,f,g,y,v,_,b,S,$,w;r.r(a),r.d(a,{resourceMetadataHandler:()=>fG,resourceMetadataOptions:()=>fW,serverCardHandler:()=>fQ,withAuth:()=>fK,xmcpHandler:()=>fX});let R=require("node:crypto");var k,x,P,E,T,j,O,C,I,N,q,A,z,M,L=Object.create,Z=Object.defineProperty,D=Object.getOwnPropertyDescriptor,U=Object.getOwnPropertyNames,V=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),J=(e,t,r)=>(r=null!=e?L(V(e)):{},((e,t,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var a,i=U(t),n=0,o=i.length;n<o;n++)a=i[n],F.call(e,a)||void 0===a||Z(e,a,{get:(e=>t[e]).bind(null,a),enumerable:!(r=D(t,a))||r.enumerable});return e})(!t&&e&&e.__esModule?r:Z(r,"default",{value:e,enumerable:!0}),e));let B=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),K=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),G=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),W=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function Y(e){let t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,r])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function X(e,t="|"){return e.map(e=>eb(e)).join(t)}function Q(e,t){return"bigint"==typeof t?t.toString():t}class ee{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return void 0!==e&&(this._value=e(),this._getter=void 0),this._value}}function et(e){return new ee(e)}function er(e){let t=+!!e.startsWith("^"),r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}let ea=Symbol("evaluating");function ei(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function en(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function eo(e){return en(e._zod.def)??e._zod.def.shape}function es(e,t,r){Object.defineProperty(e,t,{get(){let e=r();return ei(this,t,e),e},enumerable:!0,configurable:!0})}function el(e,t,r){t in e?ei(e,t,r):e[t]=r}function ec(e,t,r,a){let i=eo(t);for(let n of r){let r=Object.getOwnPropertyDescriptor(i,n);r.enumerable&&(r.get?es(e,n,()=>{let e=t._zod.def.shape[n];return a?a(e,n):e}):el(e,n,a?a(r.value,n):r.value))}}function eu(...e){let t={};for(let r of e)Object.assign(t,Object.getOwnPropertyDescriptors(r));return Object.defineProperties({},t)}let ed="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ep(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let em=et(()=>{if(eB.jitless||"u">typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(e){return!1}});function eh(e){if(!1===ep(e))return!1;let t=e.constructor;if(void 0===t||"function"!=typeof t)return!0;let r=t.prototype;return!1!==ep(r)&&!1!==Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")}function ef(e){return eh(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}let eg=new Set(["string","number","symbol"]);function ey(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ev(e,t,r){let a=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(a._zod.parent=e),a}function e_(e){if(!e)return{};if("string"==typeof e)return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");e.error=e.message}return(delete e.message,"string"==typeof e.error)?{...e,error:()=>e.error}:e}function eb(e){return"bigint"==typeof e?e.toString()+"n":"string"==typeof e?`"${e}"`:`${e}`}let eS={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},e$={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ew(e,t){let r=eo(e),a=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&a.push(e)}return a}function eR(e,t){let r={};ec(r,e,Reflect.ownKeys(eo(e)));for(let e of Reflect.ownKeys(t)){let a=Object.getOwnPropertyDescriptor(t,e);a.enumerable&&(a.get?es(r,e,()=>t[e]):el(r,e,a.value))}return r}function ek(e,t,r,a="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=r?new Set(ew(t,r)):void 0,o={};return ec(o,t,Reflect.ownKeys(eo(t)),e&&((t,r)=>n&&!n.has(r)?t:new e({type:"optional",innerType:t}))),ev(t,eu(t._zod.def,{shape:o,checks:[]}))}function ex(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function eP(e,t){return t.map(t=>(t.path??(t.path=[]),t.path.unshift(e),t))}function eE(e){return"string"==typeof e?e:e?.message}function eT(e){let t=[];for(let r of e??[]){let e=r._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let a=e.maximum??e.length??e.size;a>=0&&t.push([a,r])}return t}function ej(e,t,r){var a;for(let i=t;i<e.length;i++)(a=e[i]).schema??(a.schema=r)}function eO(e,t,r){let a=e.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?e.schema??(e.schema=e.inst):e.schema=e.inst);let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,n=e.message?e.message:eE(e.inst?._zod.def?.error?.(e))??eE(i?.(e))??eE(t?.error?.(e))??eE(r.customError?.(e))??eE(r.localeError?.(e))??"Invalid input",o={};for(let t of Object.keys(e))"inst"!==t&&"schema"!==t&&"continue"!==t&&"input"!==t&&"__proto__"!==t&&(o[t]=e[t]);return o.path??(o.path=[]),o.message=n,t?.reportInput&&(o.input=e.input),o}let eC=/[\uD800-\uDBFF]/;function eI(e){let t=e.length;if(!eC.test(e))return t;let r=t;for(let a=0;a<t-1;a++)(64512&e.charCodeAt(a))==55296&&(64512&e.charCodeAt(a+1))==56320&&(r--,a++);return r}function eN(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function eq(...e){let[t,r,a]=e;return"string"==typeof t?{message:t,code:"custom",input:r,inst:a}:{...t}}function eA(e,t,r,a=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:a,value:r}),r}function ez(e,t){for(let r in e){let a=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return eA(this,r,a(this))},set(e){eA(this,r,e)}})}return t}let eM=!1,eL={configurable:!0,get(){eM=!0}};function eZ(t,r,a){let i=Object.getPrototypeOf(t._zod);if(r in i&&e!==t._zod){e=void 0;return}e=t._zod,Object.defineProperty(i,r,{configurable:!0,get(){Object.defineProperty(this,r,eL);let e=eM;eM=!1;try{let t=a(this);return eM?delete this[r]:Object.defineProperty(this,r,{configurable:!0,writable:!0,value:t}),eM=eM||e,t}catch(t){throw delete this[r],eM=eM||e,t}},set(e){Object.defineProperty(this,r,{configurable:!0,writable:!0,value:e})}})}let eD=Object.freeze({status:"aborted"}),eU={value:void 0,enumerable:!1},eV="captureStackTrace"in Error?Error:null;function eF(e,t,r,a){function i(e){this.def=e,this.constr=c,this.traits=new Set}i.prototype={};let n=r&&new WeakSet;function o(a,o){if(a._zod){if(a._zod.traits.has(e))return}else{eU.value=new i(o);try{Object.defineProperty(a,"_zod",eU)}finally{eU.value=void 0}}if(a._zod.traits.add(e),t(a,o),n){let e=Object.getPrototypeOf(a),t=a._zod.constr.prototype,i=e;for(;i&&i!==t;)i=Object.getPrototypeOf(i);let o=i??e;if(!n.has(o)){n.add(o);for(let e in r){let t=Object.getOwnPropertyDescriptor(r,e);t.get?Object.defineProperty(o,e,{...t,enumerable:!1}):function(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:eA(this,t,r.bind(this))},set(e){eA(this,t,e)}})}(o,e,t.value)}}}let s=c.prototype;for(let e in s)Object.prototype.hasOwnProperty.call(s,e)&&(e in a||(a[e]=s[e].bind(a)))}let s=a?.Parent??Object;class l extends s{}function c(e){let t=a?.Parent?function(e){let t=eV;if(t){let r=t.stackTraceLimit;if("number"==typeof r){try{t.stackTraceLimit=0}catch{return eV=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}(l):this;o(t,e);let r=t._zod.deferred;if(r){for(let e of r)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(l,"name",{value:e}),Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:t=>!!a?.Parent&&t instanceof a.Parent||t?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class eH extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class eJ extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(C=globalThis).__zod_globalConfig??(C.__zod_globalConfig={});let eB=globalThis.__zod_globalConfig;function eK(e){return e&&Object.assign(eB,e),eB}class eG extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eW="~memo",eY=[];function eX(e){return null!==e&&"object"==typeof e}function eQ(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}let e0=new WeakMap,e1=[],e2={alloc(e,r,a){let i=t;if(!i)return a;t=void 0;let n={value:a,issues:null};return i.set(r.value,n),e1.push(n),a},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,r=(e,r)=>{var a,i;let n;if("backward"!==r.direction&&(a=r,i=e.value,void 0!==(n=a[eW]?.backEdges)&&eX(i)&&n.has(i)))throw new eG;return t(e,r)};e._zod.parse=r,e._zod.run===t&&(e._zod.run=r)})},attach(e){var r;let a,i,n,o=!1;(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,s=(l,c)=>{let u;if(void 0===a){let t=function e(t,r,a){var i,n;let o=e0.get(t);if(void 0!==o)return 2*!!o;if(r.has(t))return 2;r.add(t);let s=0,l=t=>{if(2!==s&&t?._zod){let i=e(t,r,a);i>s&&(s=i)}},c=e=>{e>s&&(s=e)},u=t._zod.def;switch(u.type){case"object":{let t=en(u);c(t?((t,i)=>{let n=0;for(let o of Reflect.ownKeys(t)){let s=Object.getOwnPropertyDescriptor(t,o);if(i&&!s.enumerable)continue;let l=s.get?1:s.value?._zod?e(s.value,r,a):0;l>n&&(n=l)}return n})(t,!0):1),l(u.catchall);break}case"array":l(u.element);break;case"tuple":for(let e of u.items)l(e);l(u.rest);break;case"record":case"map":l(u.keyType),l(u.valueType);break;case"set":l(u.valueType);break;case"union":for(let e of u.options)l(e);break;case"intersection":l(u.left),l(u.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":l(u.innerType);break;case"pipe":l(u.in),l(u.out);break;case"function":l(u.input),l(u.output);break;case"lazy":{let i=u._cachedInner??(a?t._zod.innerType:void 0);c(i?e(i,r,!1):1);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let e in u){let t=Object.getOwnPropertyDescriptor(u,e);if(!t||t.get)continue;let r=t.value;if(r&&"object"==typeof r){if(r._zod)l(r);else if(Array.isArray(r))for(let e of r)l(e)}}}return r.delete(t),i=t,1!==(n=s)&&e0.set(i,2===n),n}(e,new Set,!1);if(0===t)return e._zod.parse=r,e._zod.run===s&&(e._zod.run=r),r(l,c);2===t||o?a=!0:o=!0}let d=l.value;if(!eX(d))return r(l,c);let p=c[eW];if(p||(p={buckets:new WeakMap,backEdges:void 0},c[eW]=p),i===c)u=n;else{var m;let t;(t=(m=p).buckets.get(e))||(t=new WeakMap,m.buckets.set(e,t)),u=t,i=c,n=u}let h=u.get(d);if(h)return l.value=h.value,h.issues?h.issues.length&&l.issues.push(...eQ(h.issues)):(l.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(h.value)),l;t=u;let f=e1.length,g=r(l,c);t=void 0;let y=e1.length>f?e1.pop():void 0;return g instanceof Promise?g.then(e=>(y&&(y.issues=e.issues.length?eQ(e.issues):eY),e)):(y&&(y.issues=g.issues.length?eQ(g.issues):eY),g)};e._zod.parse=s,e._zod.run===r&&(e._zod.run=s)})}},e9=/^[cC][0-9a-z]{6,}$/,e4=/^[0-9a-z]+$/,e3=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,e5=/^[0-9a-vA-V]{20}$/,e6=/^[A-Za-z0-9]{27}$/,e7=/^[a-zA-Z0-9_-]{21}$/,e8=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,te=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,tt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,tr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,ta=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ti=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,tn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,to=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ts=/^https?$/,tl=/^\+[1-9]\d{6,14}$/,tc="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tu=RegExp(`^${tc}$`);function td(e){let t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}let tp=/^[\s\S]{0,}$/,tm=/^-?\d+$/,th=/^-?\d+(?:\.\d+)?$/,tf=/^(?:true|false)$/i,tg=/^null$/i,ty=/^[^A-Z]*$/,tv=/^[^a-z]*$/,t_=eF("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])}),tb=e=>{let t=e.value;return null!=t&&void 0!==t.length},tS={number:"number",bigint:"bigint",object:"date"},t$=eF("$ZodCheckLessThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value<=t.value:a.value<t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tw=eF("$ZodCheckGreaterThan",(e,t)=>{t_.init(e,t);let r=tS[typeof t.value];e._zod.check=a=>{(t.inclusive?a.value>=t.value:a.value>t.value)||a.issues.push({origin:tS[typeof a.value]??r,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:a.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tR=eF("$ZodCheckMultipleOf",(e,t)=>{t_.init(e,t),e._zod.check=r=>{let a,i,n;if(typeof r.value!=typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof r.value?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):0==(i=Math.round(a=r.value/t.value),n=4*Number.EPSILON*Math.max(Math.abs(a),1),Math.abs(a-i)<n?0:a-i))||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),tk=eF("$ZodCheckNumberFormat",(e,t)=>{t_.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),a=r?"int":"number",[i,n]=eS[t.format];e._zod.check=o=>{let s=o.value;if(r){if(!Number.isInteger(s))return void o.issues.push({expected:a,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?o.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,inclusive:!0,continue:!t.abort}))}s<i&&o.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>n&&o.issues.push({origin:"number",input:s,code:"too_big",maximum:n,inclusive:!0,inst:e,continue:!t.abort})}}),tx=eF("$ZodCheckMaxLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>t.maximum?eI(a):i)<=t.maximum)return;let n=eN(a);r.issues.push({origin:n,code:"too_big",maximum:t.maximum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tP=eF("$ZodCheckMinLength",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length;if(("string"==typeof a&&i>=t.minimum&&i<2*t.minimum?eI(a):i)>=t.minimum)return;let n=eN(a);r.issues.push({origin:n,code:"too_small",minimum:t.minimum,inclusive:!0,input:a,inst:e,continue:!t.abort})}}),tE=eF("$ZodCheckLengthEquals",(e,t)=>{var r;t_.init(e,t),(r=e._zod.def).when??(r.when=tb),e._zod.check=r=>{let a=r.value,i=a.length,n="string"==typeof a&&i>=t.length&&i<=2*t.length?eI(a):i;if(n===t.length)return;let o=eN(a),s=n>t.length;r.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),tT=eF("$ZodCheckStringFormat",(e,t)=>{var r,a;t_.init(e,t),t.pattern?(r=e._zod).check??(r.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(a=e._zod).check??(a.check=()=>{})}),tj=eF("$ZodCheckRegex",(e,t)=>{tT.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,t.pattern.test(r.value)||r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),tO=eF("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ty),tT.init(e,t)}),tC=eF("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tv),tT.init(e,t)}),tI=eF("$ZodCheckIncludes",(e,t)=>{t_.init(e,t);let r=ey(t.includes),a=new RegExp("number"==typeof t.position?`^.{${t.position},}${r}`:r);t.pattern=a,e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),tN=eF("$ZodCheckStartsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`^${ey(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),tq=eF("$ZodCheckEndsWith",(e,t)=>{t_.init(e,t);let r=RegExp(`.*${ey(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),tA=eF("$ZodCheckOverwrite",(e,t)=>{t_.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class tz{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if("function"==typeof e){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let t=e.split("\n").filter(e=>e),r=Math.min(...t.map(e=>e.length-e.trimStart().length));for(let e of t.map(e=>e.slice(r)).map(e=>" ".repeat(2*this.indent)+e))this.content.push(e)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
2
2
|
${t.join("\n")}
|
|
3
3
|
};`)(...Object.values(this.closed))}}let tM={major:4,minor:6,patch:7},tL=eF("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=tM;let a=e._zod.def.checks,i=e._zod.traits.has("$ZodCheck")?[e,...a??[]]:a?.length?[...a]:[];for(let t of i)for(let r of t._zod.onattach)r(e);if(0===i.length)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,r,a)=>{let i;if(t.memo)return t;let n=ex(t);for(let o of r){if(o._zod.def.when){if(function(e,t=0){if(!0===e.aborted)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}(t)||!o._zod.def.when(t))continue}else if(n)continue;let r=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&a?.async===!1)throw new eH;if(i||s instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await s,t.issues.length!==r&&(ej(t.issues,r,e),n||(n=ex(t,r)))});else{if(t.issues.length===r)continue;ej(t.issues,r,e),n||(n=ex(t,r))}}return i?i.then(()=>t):t},r=(r,a,n)=>{if(ex(r))return r.aborted=!0,r;let o=t(a,i,n);if(o instanceof Promise){if(!1===n.async)throw new eH;return o.then(t=>e._zod.parse(t,n))}return e._zod.parse(o,n)};e._zod.run=(a,n)=>{if(n.skipChecks)return e._zod.parse(a,n);if("backward"===n.direction){let t=e._zod.parse({value:a.value,issues:[]},{...n,skipChecks:!0});return t instanceof Promise?t.then(e=>r(e,a,n)):r(t,a,n)}let o=e._zod.parse(a,n);if(o instanceof Promise){if(!1===n.async)throw new eH;return o.then(e=>t(e,i,n))}return t(o,i,n)}}},{get"~standard"(){return eA(this,"~standard",tD(this),!1)},set"~standard"(e){eA(this,"~standard",e)}}),tZ=(e,t)=>e.issues.length?{issues:e.issues.map(e=>eO(e,t,eK()))}:{value:e.value};function tD(e){return{validate:t=>{let r={async:!1};try{let a=e._zod.run({value:t,issues:[]},r);if(!(a instanceof Promise))return tZ(a,r)}catch(e){}return async function(e,t){let r={async:!0};return tZ(await e._zod.run({value:t,issues:[]},r),r)}(e,t)},vendor:"zod",version:1}}let tU=eF("$ZodString",(e,t)=>{tL.init(e,t),e._zod.pattern=t.pattern??tp,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=String(r.value)}catch(e){}return"string"==typeof r.value||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),tV=eF("$ZodStringFormat",(e,t)=>{tT.init(e,t),tU.init(e,t)}),tF=eF("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=te),tV.init(e,t)}),tH=eF("$ZodUUID",(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=tt(e))}else t.pattern??(t.pattern=tt());tV.init(e,t)}),tJ=eF("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=tr),tV.init(e,t)});function tB(e){try{if("u">typeof URL&&"function"==typeof URL.canParse)return URL.canParse(e);return new URL(e),!0}catch{return!1}}let tK=/[\t\n\r]/g;function tG(e){return e.replace(tK,"")}let tW=eF("$ZodURL",(e,t)=>{tV.init(e,t),e._zod.check=r=>{try{var a,i;let n=r.value.trim(),o="normalize"in t||"hostname"in t||"protocol"in t?function(e,t){if(!t.normalize&&t.protocol?.source===ts.source&&!/^https?:\/\//i.test(e))return 1;try{if("u">typeof URL){let t=URL;if("function"==typeof t.parse)return t.parse(e)??2}return new URL(e)}catch{return 2}}(n,t):tB(n)||2;if(1===o)return void r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});if(2===o)return void r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});if(!0===o){r.value=tG(n);return}t.hostname&&((a=t.hostname).lastIndex=0,!a.test(o.hostname))&&r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort}),t.protocol&&((i=t.protocol).lastIndex=0,!i.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol))&&r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort}),r.value=t.normalize?o.href:tG(n);return}catch(a){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),tY=eF("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=RegExp("^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),tV.init(e,t)}),tX=eF("$ZodNanoID",(e,t)=>{var r;if(void 0!==t.length&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=void 0===t.length?e7:(r=t.length,RegExp(`^[a-zA-Z0-9_-]{${r}}$`))),tV.init(e,t)}),tQ=eF("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=e9),tV.init(e,t)}),t0=eF("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=e4),tV.init(e,t)}),t1=eF("$ZodULID",(e,t)=>{t.pattern??(t.pattern=e3),tV.init(e,t)}),t2=eF("$ZodXID",(e,t)=>{t.pattern??(t.pattern=e5),tV.init(e,t)}),t9=eF("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=e6),tV.init(e,t)}),t4=eF("$ZodISODateTime",(e,t)=>{let r,a,i;t.pattern??(r=["Z"],t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),a=`${td({precision:t.precision,seconds:!0})}(?:${r.join("|")})`,i=t.local?`${a}|${td({precision:t.precision})}`:a,t.pattern=RegExp(`^${tc}T(?:${i})$`)),tV.init(e,t)}),t3=eF("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=tu),tV.init(e,t)}),t5=eF("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=RegExp(`^${td(t)}$`)),tV.init(e,t)}),t6=eF("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=e8),tV.init(e,t)}),t7=eF("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ta),tV.init(e,t)}),t8=/^[0-9a-fA-F:.]+$/;function re(e){return!!t8.test(e)&&tB(`http://[${e}]`)}let rt=eF("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=ti),tV.init(e,t),e._zod.check=r=>{re(r.value)||r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}}),rr=eF("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=tn),tV.init(e,t)}),ra=eF("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=to),tV.init(e,t),e._zod.check=r=>{!function(e){let t=e.split("/");if(2!==t.length)return!1;let[r,a]=t;if(!a)return!1;let i=Number(a);return`${i}`===a&&!(i<0)&&!(i>128)&&re(r)}(r.value)&&r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function ri(e){if(""===e)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}let rn=/^[0-9a-zA-Z+/]*={0,2}$/,ro=eF("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=rn),tV.init(e,t),e._zod.check=r=>{ri(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),rs=/^[A-Za-z0-9_-]*$/,rl=eF("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=rs),tV.init(e,t),e._zod.check=r=>{!function(e){if(!rs.test(e))return!1;let t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return ri(t.padEnd(4*Math.ceil(t.length/4),"="))}(r.value)&&r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),rc=eF("$ZodE164",(e,t)=>{t.pattern??(t.pattern=tl),tV.init(e,t)}),ru=eF("$ZodJWT",(e,t)=>{tV.init(e,t),e._zod.check=r=>{!function(e,t=null){try{let r=e.split(".");if(3!==r.length)return!1;let[a]=r;if(!a)return!1;let i=JSON.parse(atob(a));if("typ"in i&&i?.typ!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))return!1;return!0}catch{return!1}}(r.value,t.alg)&&r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}}),rd=eF("$ZodNumber",(e,t)=>{tL.init(e,t),e._zod.pattern=th,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=Number(r.value)}catch(e){}let i=r.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return r;let n="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:String(i):void 0;return r.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...n?{received:n}:{}}),r}}),rp=eF("$ZodNumberFormat",(e,t)=>{tk.init(e,t),rd.init(e,t)}),rm=eF("$ZodBoolean",(e,t)=>{tL.init(e,t),e._zod.pattern=tf,e._zod.parse=(r,a)=>{if(t.coerce)try{r.value=!!r.value}catch(e){}let i=r.value;return"boolean"==typeof i||r.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),r}}),rh=eF("$ZodNull",(e,t)=>{tL.init(e,t),e._zod.pattern=tg,e._zod.values=new Set([null]),e._zod.parse=(t,r)=>{let a=t.value;return null===a||t.issues.push({expected:"null",code:"invalid_type",input:a,inst:e}),t}}),rf=eF("$ZodAny",(e,t)=>{tL.init(e,t),e._zod.parse=e=>e}),rg=eF("$ZodUnknown",(e,t)=>{tL.init(e,t),e._zod.parse=e=>e}),ry=eF("$ZodNever",(e,t)=>{tL.init(e,t),e._zod.parse=(t,r)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),rv=e=>Array.isArray(e)?e.length:-1;function r_(e,t,r){e.issues.length&&t.issues.push(...eP(r,e.issues)),t.value[r]=e.value}let rb=eF("$ZodArray",(e,t)=>{tL.init(e,t);let r=eB.memoizer;r?.attach(e),e._zod.parse=(a,i)=>{let n=a.value;if(!Array.isArray(n))return a.issues.push({expected:"array",code:"invalid_type",input:n,inst:e}),a;a.value=r?r.alloc(e,a,Array(n.length),i):Array(n.length);let o=[],s=i?.abortEarly;for(let e=0;e<n.length;e++){let r=n[e],l=t.element._zod.run({value:r,issues:[]},i);if(l instanceof Promise)o.push(l.then(t=>r_(t,a,e)));else if(r_(l,a,e),s&&0!==l.issues.length&&ex(l))break}return o.length?Promise.all(o).then(()=>a):a},function(e,t){let r=eT(e._zod.def.checks);if(!r.length)return;let a=Math.min(...r.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(r,n)=>{let o=t(r.value);if(o>a&&!n?.skipChecks&&n?.direction!=="backward"){for(let[t,a]of eT(e._zod.def.checks))if(o>t&&a._zod.def.when(r)){let t=r.issues.length;return a._zod.check(r),r.issues[t].continue=!1,ej(r.issues,t,e),r}}return i(r,n)}}(e,rv)});function rS(e,t,r,a,i,n){let o=r in a,s="optional"===n;if(o||!s||"optional"!==i){if(e.issues.length){if(void 0!==i&&s&&!o)return;t.issues.push(...eP(r,e.issues))}if(!o&&void 0===i){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}void 0===e.value?(o||"defaulted"===i&&!s)&&(t.value[r]=void 0):t.value[r]=e.value}}let r$=[];function rw(e){var t;let r=Object.keys(e.shape),a=Object.getOwnPropertySymbols(e.shape),i=a.length?a:r$,n=i.length?[...r,...i]:r;for(let t of n)if(!e.shape?.[t]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let o=Object.keys(t=e.shape).filter(e=>void 0!==t[e]._zod.optin&&"optional"===t[e]._zod.optout);return{...e,allKeys:n,symbolKeys:i,keySet:new Set(r),numKeys:r.length,optionalKeys:new Set(o)}}function rR(e,t,r,a,i,n,o){let s=[],l=i.keySet,c=i.catchall._zod,u=c.def.type,d=c.optin,p=c.optout,m=0;for(let i in t){if(o&&r.issues.length!==m){if(ex(r,m))break;m=r.issues.length}if(l.has(i))continue;if("__proto__"===i){"never"===u&&s.push(i);continue}if("never"===u){s.push(i);continue}let n=c.run({value:t[i],issues:[]},a);n instanceof Promise?e.push(n.then(e=>rS(e,r,i,t,d,p))):rS(n,r,i,t,d,p)}return(s.length&&r.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:n,continue:!0}),e.length)?Promise.all(e).then(()=>r):r}let rk=eF("$ZodObject",(e,t)=>{let r;tL.init(e,t);let a=Object.getOwnPropertyDescriptor(t,"shape"),i=a?.get?a.get.raw:t.shape??{};if(i){let e=()=>{let r={...i};return Object.defineProperty(t,"shape",{value:r}),e.raw=r,r};e.raw=i,Object.defineProperty(t,"shape",{get:e})}let n=et(()=>rw(t));eZ(e,"propValues",e=>{let t=e.def.shape,r={};for(let e in t){let a=t[e]._zod;if(a.values){for(let t of(Object.prototype.hasOwnProperty.call(r,e)||ei(r,e,new Set),a.values))r[e].add(t);void 0!==a.optin&&r[e].add(void 0)}}return r});let o=t.catchall,s=eB.memoizer;s?.attach(e),e._zod.parse=(t,a)=>{r??(r=n.value);let i=t.value;if(!ep(i))return t.issues.push({expected:"object",code:"invalid_type",input:i,inst:e}),t;t.value=s?s.alloc(e,t,{},a):{};let l=[],c=r.shape,u=a?.abortEarly,d=t.issues.length;for(let e of r.allKeys){if(u&&t.issues.length!==d){if(ex(t,d))break;d=t.issues.length}if("__proto__"===e)continue;let r=c[e],n=r._zod.optin,o=r._zod.optout,s=r._zod.run({value:i[e],issues:[]},a);s instanceof Promise?l.push(s.then(r=>rS(r,t,e,i,n,o))):rS(s,t,e,i,n,o)}return o?rR(l,i,t,a,n.value,e,!0===u):l.length?Promise.all(l).then(()=>t):t}}),rx=eF("$ZodObjectJIT",(e,t)=>{let r,a;rk.init(e,t);let i=e._zod.parse,n=et(()=>rw(t)),o=eB.memoizer,s=!eB.jitless,l=s&&em.value,c=t.catchall;e._zod.parse=(u,d)=>{a??(a=n.value);let p=u.value;return ep(p)?s&&l&&d?.async===!1&&!0!==d.jitless?(r||(r=(t=>{let r=n.value,a=r.symbolKeys,i=new tz(["payload","ctx"],{shape:t,inst:e,memo:o,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,l=(e,t)=>`
|
|
4
4
|
let ${e}_ab = false;
|
|
@@ -74,23 +74,23 @@ data:
|
|
|
74
74
|
`;return a&&(i+=`id: ${a}
|
|
75
75
|
`),i+=`data: ${JSON.stringify(r)}
|
|
76
76
|
|
|
77
|
-
`,e.enqueue(t.encode(i)),!0}catch(e){return this.onerror?.(e),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(e,t){try{let r,a,i,n,o,s=e.headers.get("accept");if(!s?.includes("application/json")||!s.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(e.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(t?.parsedBody===void 0)try{let t=await pX(e,this._maxRequestBodySize);if(t.tooLarge){let e=pW(this._maxRequestBodySize);return this.onerror?.(Error(e)),this.createJsonErrorResponse(413,-32e3,e)}r=JSON.parse(t.text)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else r=t.parsedBody;if(Array.isArray(r)&&r.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{a=Array.isArray(r)?r.map(e=>os.parse(e)):[os.parse(r)]}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let l=a.some(e=>o$.safeParse(e).success);if(l){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(a.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!l){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{i=await this._checkScopeChallenge(a,t?.authInfo)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!a.some(e=>cB(e))){for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e});return new Response(null,{status:202})}let c=crypto.randomUUID(),u=a.find(e=>o$.safeParse(e).success),d=u?u.params.protocolVersion:e.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(r=>{for(let e of(this._streamMapping.set(c,{resolveJson:r,cleanup:()=>{this._streamMapping.delete(c)}}),a))cB(e)&&this._requestToStreamMapping.set(e.id,c);for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e})});let p=new TextEncoder,m=new ReadableStream({start:e=>{n=e},cancel:()=>{void 0!==o&&clearInterval(o),this._streamMapping.get(c)?.controller===n&&this._streamMapping.delete(c)}}),h={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let e of(void 0!==this.sessionId&&(h["mcp-session-id"]=this.sessionId),a))cB(e)&&(this._streamMapping.set(c,{controller:n,encoder:p,cleanup:()=>{void 0!==o&&clearInterval(o),this._streamMapping.delete(c);try{n.close()}catch{}}}),this._requestToStreamMapping.set(e.id,c));for(let r of(await this.writePrimingEvent(n,p,c,d),a)){let a,i;cB(r)&&this._eventStore&&this.supportsEmptySSEData(d)&&(a=()=>{this.closeSSEStream(r.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(r,{authInfo:t?.authInfo,request:e,closeSSEStream:a,closeStandaloneSSEStream:i})}return this._streamMapping.get(c)?.controller===n&&(o=this.startKeepAlive(n,p)),new Response(m,{status:200,headers:h})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(e)})}}async handleDeleteRequest(e){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(e){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let t=e.headers.get("mcp-session-id");return t?t!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(e){let t=e.headers.get("mcp-protocol-version");if(null!==t&&!this._supportedProtocolVersions.includes(t)){let e=`Bad Request: Unsupported protocol version: ${t} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(e)),this.createJsonErrorResponse(400,-32e3,e)}}async close(){if(!this._closed){for(let{cleanup:e}of(this._closed=!0,this._streamMapping.values()))e();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(e){let t=this._requestToStreamMapping.get(e);if(!t)return;let r=this._streamMapping.get(t);r&&r.cleanup()}closeStandaloneSSEStream(){let e=this._streamMapping.get(this._standaloneSseStreamId);e&&e.cleanup()}async send(e,t){let r=t?.relatedRequestId;if((cG(e)||cW(e))&&(r=e.id),void 0===r){let t;if(cG(e)||cW(e))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(t=await this._eventStore.storeEvent(this._standaloneSseStreamId,e));let r=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===r)return;r.controller&&r.encoder&&(void 0===t||!r.replayedEventIds?.has(t))&&this.writeSSEEvent(r.controller,r.encoder,e,t);return}let a=this._requestToStreamMapping.get(r);if(!a)throw Error(`No connection established for request ID: ${String(r)}`);let i=this._streamMapping.get(a);if(!this._enableJsonResponse){let t;this._eventStore&&(t=await this._eventStore.storeEvent(a,e),i=this._streamMapping.get(a)),i?.controller&&i?.encoder&&(void 0===t||!i.replayedEventIds?.has(t))&&this.writeSSEEvent(i.controller,i.encoder,e,t)}if(cG(e)||cW(e)){this._requestResponseMap.set(r,e);let t=[...this._requestToStreamMapping.entries()].filter(([e,t])=>t===a).map(([e])=>e);if(t.every(e=>this._requestResponseMap.has(e))){if(!i){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(r)}`);if(!this._eventStore){for(let e of(this.onerror?.(Error(`Response for request ID ${String(r)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),t))this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}if(this._enableJsonResponse&&i.resolveJson){let e={"Content-Type":"application/json"};void 0!==this.sessionId&&(e["mcp-session-id"]=this.sessionId);let r=t.map(e=>this._requestResponseMap.get(e));1===r.length?i.resolveJson(Response.json(r[0],{status:200,headers:e})):i.resolveJson(Response.json(r,{status:200,headers:e})),i.cleanup()}else i.cleanup();for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e)}}}};function p0(e){if(null===e||"object"!=typeof e||Array.isArray(e))return null;let{method:t,id:r}=e;return"string"!=typeof t?null:"string"==typeof r||"number"==typeof r?r:null}function p1(e,t,r,a,i=null){return Response.json({jsonrpc:"2.0",error:{code:t,message:r,...void 0!==a&&{data:a}},id:i},{status:e,...405===e&&{headers:{Allow:"POST"}}})}function p2(e,t=null){return p1(e.httpStatus,e.code,e.message,e.data,t)}function p9(e){return e instanceof Error?e:Error(String(e))}function p4(e=null){return p1(500,-32603,"Internal server error",void 0,e)}function p3(e){if(void 0!==e.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p5(e){return{protocolVersionHeader:e.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:e.headers.get("mcp-method")??void 0,mcpNameHeader:e.headers.get("mcp-name")??void 0}}let p6=require("async_hooks"),p7=(e,t)=>{globalThis[e]=t},p8=e=>globalThis[e];function me({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(p8(r))return p8(r);let i=new p6.AsyncLocalStorage,n=globalThis[a]??{current:null};p7(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return p7(r,o),o}let mt=me({name:"http-request-context"}),mr=mt.setContext,ma=mt.getContext,mi=mt.provider,mn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),mo=e=>{if(!mn(e)||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},ms=e=>{if(e&&"initialize"===e.method&&mn(e.params))return mo(e.params.clientInfo)},ml=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}};function mc(e){let{tags:t,enabled:r,...a}=e;return{...a,_meta:void 0===t?a._meta:{...a._meta,"xmcp/tags":t}}}let mu=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){var e,t;e="resources",t=new Map,e in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},md=me({name:"request-context",fallback:!1}),mp=me({name:"client-info-context"});mp.setContext;let mm=mp.getContext;mp.provider;let mh=new Set(["message","mode","requestedSchema"]),mf=new Set(["elicitationId","message","mode","url"]),mg=new Set(["properties","required","type"]),my=new Set(["default","description","format","maxLength","minLength","title","type"]),mv=new Set(["default","description","enum","enumNames","title","type"]),m_=new Set(["default","description","title","type"]),mb=new Set(["default","description","maximum","minimum","title","type"]),mS=new Set(["date","date-time","email","uri"]);function m$(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function mw(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mR(e,t){if("string"!=typeof e)throw Error(t)}function mk(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mx(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mP(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mE(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}let mT=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),mj=new Set(["task","toolChoice","tools"]),mO=new Set(["text","image","audio"]);function mC(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mI={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mN(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mI[e.type];return t?t(e):{valid:!0}}function mq(e,t,r,a){if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function mA(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function mz(e){let t=e.mcpReq.envelope,r=mo(t?.[nJ]);if(!r)try{let e,t=ma();r=t.clientInfo??(e=t.headers,mo({name:ml(e,"x-mcp-client-name"),version:ml(e,"x-mcp-client-version"),title:ml(e,"x-mcp-client-title"),websiteUrl:ml(e,"x-mcp-client-website-url"),description:ml(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=mm().clientInfo}catch{}return r}function mM(e){let t=[...e];return(e,r,a)=>(function(e,t,r){let a,i=new Map;if(e.http){let e=ma(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));a=Object.freeze({id:e.id,headers:Object.freeze(t)})}return md.provider(Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:a,authInfo:e.http?.authInfo,signal:e.mcpReq.signal,set(e,t){i.set(e,t)},get:e=>i.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)}),r)})(r,mz(r),async()=>{if(0===t.length)return a();let r=Object.freeze({...function(){try{return md.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),...e,params:Object.freeze({...e.params})}),i=-1,n=async e=>{if(e<=i)throw Error("MCP middleware next() can only be called once");i=e;let o=t[e];return o?o(r,()=>n(e+1)):a()};return n(0)})}let mL=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mZ(e){return e.endsWith(".tsx")}let mD=Symbol("Let zodToJsonSchema decide on which parser to use"),mU={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=e=>{},T.assertIs=function(e){},T.assertNever=function(e){throw Error()},T.arrayToEnum=e=>{let t={};for(let r of e)t[r]=r;return t},T.getValidEnumValues=e=>{let t=T.objectKeys(e).filter(t=>"number"!=typeof e[e[t]]),r={};for(let a of t)r[a]=e[a];return T.objectValues(r)},T.objectValues=e=>T.objectKeys(e).map(function(t){return e[t]}),T.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{let t=[];for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},T.find=(e,t)=>{for(let r of e)if(t(r))return r},T.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,T.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},T.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(A||(A={})).mergeShapes=(e,t)=>({...e,...t});let mV=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mF=e=>{switch(typeof e){case"undefined":return mV.undefined;case"string":return mV.string;case"number":return Number.isNaN(e)?mV.nan:mV.number;case"boolean":return mV.boolean;case"function":return mV.function;case"bigint":return mV.bigint;case"symbol":return mV.symbol;case"object":if(Array.isArray(e))return mV.array;if(null===e)return mV.null;if(e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch)return mV.promise;if("u">typeof Map&&e instanceof Map)return mV.map;if("u">typeof Set&&e instanceof Set)return mV.set;if("u">typeof Date&&e instanceof Date)return mV.date;return mV.object;default:return mV.unknown}},mH=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 mJ extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(e){return e.message},r={_errors:[]},a=e=>{for(let i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(a);else if("invalid_return_type"===i.code)a(i.returnTypeError);else if("invalid_arguments"===i.code)a(i.argumentsError);else if(0===i.path.length)r._errors.push(t(i));else{let e=r,a=0;for(;a<i.path.length;){let r=i.path[a],n=a===i.path.length-1;if("_errors"===r){n&&e._errors.push(t(i)),a++;continue}Object.prototype.hasOwnProperty.call(e,r)||("__proto__"===r?Object.defineProperty(e,r,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):e[r]={_errors:[]}),e=e[r],n&&e._errors.push(t(i)),a++}}};return a(this),r}static assert(e){if(!(e instanceof mJ))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){let t=Object.create(null),r=[];for(let a of this.issues)if(a.path.length>0){let r=a.path[0];t[r]=t[r]||[],t[r].push(e(a))}else r.push(e(a));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}mJ.create=e=>new mJ(e);let mB=(e,t)=>{let r;switch(e.code){case mH.invalid_type:r=e.received===mV.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case mH.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,q.jsonStringifyReplacer)}`;break;case mH.unrecognized_keys:r=`Unrecognized key(s) in object: ${q.joinValues(e.keys,", ")}`;break;case mH.invalid_union:r="Invalid input";break;case mH.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${q.joinValues(e.options)}`;break;case mH.invalid_enum_value:r=`Invalid enum value. Expected ${q.joinValues(e.options)}, received '${e.received}'`;break;case mH.invalid_arguments:r="Invalid function arguments";break;case mH.invalid_return_type:r="Invalid function return type";break;case mH.invalid_date:r="Invalid date";break;case mH.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(r=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(r=`${r} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?r=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?r=`Invalid input: must end with "${e.validation.endsWith}"`:q.assertNever(e.validation):r="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case mH.too_small:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case mH.too_big:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case mH.custom:r="Invalid input";break;case mH.invalid_intersection_types:r="Intersection results could not be merged";break;case mH.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case mH.not_finite:r="Number must be finite";break;default:r=t.defaultError,q.assertNever(e)}return{message:r}};(j=z||(z={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},j.toString=e=>"string"==typeof e?e:e?.message;function mK(e,t){let r=(e=>{let{data:t,path:r,errorMaps:a,issueData:i}=e,n=[...r,...i.path||[]],o={...i,path:n};if(void 0!==i.message)return{...i,path:n,message:i.message};let s="";for(let e of a.filter(e=>!!e).slice().reverse())s=e(o,{data:t,defaultError:s}).message;return{...i,path:n,message:s}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,mB,void 0].filter(e=>!!e)});e.common.issues.push(r)}class mG{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){let r=[];for(let a of t){if("aborted"===a.status)return mW;"dirty"===a.status&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let e of t){let t=await e.key,a=await e.value;r.push({key:t,value:a})}return mG.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let a of t){let{key:t,value:i}=a;if("aborted"===t.status||"aborted"===i.status)return mW;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"!==t.value&&(void 0!==i.value||a.alwaysSet)&&(r[t.value]=i.value)}return{status:e.value,value:r}}}let mW=Object.freeze({status:"aborted"}),mY=e=>({status:"dirty",value:e}),mX=e=>({status:"valid",value:e}),mQ=e=>"u">typeof Promise&&e instanceof Promise;class m0{constructor(e,t,r,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let m1=(e,t)=>{if("valid"===t.status)return{success:!0,data:t.value};if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let t=new mJ(e.common.issues);return this._error=t,this._error}}};function m2(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:a,description:i}=e;if(t&&(r||a))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:i}:{errorMap:(t,i)=>{let{message:n}=e;return"invalid_enum_value"===t.code?{message:n??i.defaultError}:void 0===i.data?{message:n??a??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:n??r??i.defaultError}},description:i}}class m9{get description(){return this._def.description}_getType(e){return mF(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:mF(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new mG,ctx:{common:e.parent.common,data:e.data,parsedType:mF(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(mQ(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){return Promise.resolve(this._parse(e))}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mF(e)},a=this._parseSync({data:e,path:r.path,parent:r});return m1(r,a)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mF(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return"valid"===r.status?{value:r.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>"valid"===e.status?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mF(e)},a=this._parse({data:e,path:r.path,parent:r});return m1(r,await (mQ(a)?a:Promise.resolve(a)))}refine(e,t){return this._refinement((r,a)=>{let i=e(r),n=()=>a.addIssue({code:mH.custom,..."string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(r):t});return"u">typeof Promise&&i instanceof Promise?i.then(e=>!!e||(n(),!1)):!!i||(n(),!1)})}refinement(e,t){return this._refinement((r,a)=>!!e(r)||(a.addIssue("function"==typeof t?t(r,a):t),!1))}_refinement(e){return new hA({schema:this,typeName:M.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return hz.create(this,this._def)}nullable(){return hM.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hw.create(this)}promise(){return hq.create(this,this._def)}or(e){return hk.create([this,e],this._def)}and(e){return hx.create(this,e,this._def)}transform(e){return new hA({...m2(this._def),schema:this,typeName:M.ZodEffects,effect:{type:"transform",transform:e}})}default(e){return new hL({...m2(this._def),innerType:this,defaultValue:"function"==typeof e?e:()=>e,typeName:M.ZodDefault})}brand(){return new hU({typeName:M.ZodBranded,type:this,...m2(this._def)})}catch(e){return new hZ({...m2(this._def),innerType:this,catchValue:"function"==typeof e?e:()=>e,typeName:M.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return hV.create(this,e)}readonly(){return hF.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m4=/^c[^\s-]{8,}$/i,m3=/^[0-9a-z]+$/,m5=/^[0-9A-HJKMNP-TV-Z]{26}$/i,m6=/^[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,m7=/^[a-z0-9_-]{21}$/i,m8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,he=/^[-+]?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)?)??$/,ht=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,hr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ha=/^(?:(?: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])$/,hi=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hn=/^(([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])$/,ho=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hs=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,hl="((\\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])))",hc=RegExp(`^${hl}$`);function hu(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}class hd extends m9{_parse(e){var t,r,a,i;let n;if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==mV.string){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.string,received:t.parsedType}),mW}let o=new mG;for(let s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(mK(n=this._getOrReturnCtx(e,n),{code:mH.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("max"===s.kind)e.data.length>s.value&&(mK(n=this._getOrReturnCtx(e,n),{code:mH.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("length"===s.kind){let t=e.data.length>s.value,r=e.data.length<s.value;(t||r)&&(n=this._getOrReturnCtx(e,n),t?mK(n,{code:mH.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&mK(n,{code:mH.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),o.dirty())}else if("email"===s.kind)ht.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"email",code:mH.invalid_string,message:s.message}),o.dirty());else if("emoji"===s.kind)h||(h=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),h.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"emoji",code:mH.invalid_string,message:s.message}),o.dirty());else if("uuid"===s.kind)m6.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"uuid",code:mH.invalid_string,message:s.message}),o.dirty());else if("nanoid"===s.kind)m7.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"nanoid",code:mH.invalid_string,message:s.message}),o.dirty());else if("cuid"===s.kind)m4.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"cuid",code:mH.invalid_string,message:s.message}),o.dirty());else if("cuid2"===s.kind)m3.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"cuid2",code:mH.invalid_string,message:s.message}),o.dirty());else if("ulid"===s.kind)m5.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"ulid",code:mH.invalid_string,message:s.message}),o.dirty());else if("url"===s.kind)try{new URL(e.data)}catch{mK(n=this._getOrReturnCtx(e,n),{validation:"url",code:mH.invalid_string,message:s.message}),o.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"regex",code:mH.invalid_string,message:s.message}),o.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),o.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:{startsWith:s.value},message:s.message}),o.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:{endsWith:s.value},message:s.message}),o.dirty()):"datetime"===s.kind?(function(e){let t=`${hl}T${hu(e)}`,r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,RegExp(`^${t}$`)})(s).test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:"datetime",message:s.message}),o.dirty()):"date"===s.kind?hc.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:"date",message:s.message}),o.dirty()):"time"===s.kind?RegExp(`^${hu(s)}$`).test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{code:mH.invalid_string,validation:"time",message:s.message}),o.dirty()):"duration"===s.kind?he.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"duration",code:mH.invalid_string,message:s.message}),o.dirty()):"ip"===s.kind?(t=e.data,!(("v4"===(r=s.version)||!r)&&hr.test(t)||("v6"===r||!r)&&hi.test(t))&&1&&(mK(n=this._getOrReturnCtx(e,n),{validation:"ip",code:mH.invalid_string,message:s.message}),o.dirty())):"jwt"===s.kind?!function(e,t){if(!m8.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let a=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),i=JSON.parse(atob(a));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||t&&i.alg!==t)return!1;return!0}catch{return!1}}(e.data,s.alg)&&(mK(n=this._getOrReturnCtx(e,n),{validation:"jwt",code:mH.invalid_string,message:s.message}),o.dirty()):"cidr"===s.kind?(a=e.data,!(("v4"===(i=s.version)||!i)&&ha.test(a)||("v6"===i||!i)&&hn.test(a))&&1&&(mK(n=this._getOrReturnCtx(e,n),{validation:"cidr",code:mH.invalid_string,message:s.message}),o.dirty())):"base64"===s.kind?ho.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"base64",code:mH.invalid_string,message:s.message}),o.dirty()):"base64url"===s.kind?hs.test(e.data)||(mK(n=this._getOrReturnCtx(e,n),{validation:"base64url",code:mH.invalid_string,message:s.message}),o.dirty()):q.assertNever(s);return{status:o.value,value:e.data}}_regex(e,t,r){return this.refinement(t=>e.test(t),{validation:t,code:mH.invalid_string,...z.errToObj(r)})}_addCheck(e){return new hd({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...z.errToObj(e)})}url(e){return this._addCheck({kind:"url",...z.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...z.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...z.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...z.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...z.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...z.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...z.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...z.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...z.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...z.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...z.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...z.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...z.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...z.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...z.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...z.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...z.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...z.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...z.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...z.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...z.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...z.errToObj(t)})}nonempty(e){return this.min(1,z.errToObj(e))}trim(){return new hd({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hd({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hd({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hd.create=e=>new hd({checks:[],typeName:M.ZodString,coerce:e?.coerce??!1,...m2(e)});class hp extends m9{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){let t;if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==mV.number){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.number,received:t.parsedType}),mW}let r=new mG;for(let a of this._def.checks)"int"===a.kind?q.isInteger(e.data)||(mK(t=this._getOrReturnCtx(e,t),{code:mH.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"multipleOf"===a.kind?0!==function(e,t){let r=(e.toString().split(".")[1]||"").length,a=(t.toString().split(".")[1]||"").length,i=r>a?r:a;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(e.data,a.value)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(e.data)||(mK(t=this._getOrReturnCtx(e,t),{code:mH.not_finite,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hp({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hp({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:z.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:z.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:z.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:z.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&q.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;else"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value);return Number.isFinite(t)&&Number.isFinite(e)}}hp.create=e=>new hp({checks:[],typeName:M.ZodNumber,coerce:e?.coerce||!1,...m2(e)});class hm extends m9{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){let t;if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==mV.bigint)return this._getInvalidInput(e);let r=new mG;for(let a of this._def.checks)"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"multipleOf"===a.kind?e.data%a.value!==BigInt(0)&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.bigint,received:t.parsedType}),mW}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hm({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hm({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hm.create=e=>new hm({checks:[],typeName:M.ZodBigInt,coerce:e?.coerce??!1,...m2(e)});class hh extends m9{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==mV.boolean){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.boolean,received:t.parsedType}),mW}return mX(e.data)}}hh.create=e=>new hh({typeName:M.ZodBoolean,coerce:e?.coerce||!1,...m2(e)});class hf extends m9{_parse(e){let t;if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==mV.date){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.date,received:t.parsedType}),mW}if(Number.isNaN(e.data.getTime()))return mK(this._getOrReturnCtx(e),{code:mH.invalid_date}),mW;let r=new mG;for(let a of this._def.checks)"min"===a.kind?e.data.getTime()<a.value&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):"max"===a.kind?e.data.getTime()>a.value&&(mK(t=this._getOrReturnCtx(e,t),{code:mH.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):q.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new hf({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:z.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:z.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}hf.create=e=>new hf({checks:[],coerce:e?.coerce||!1,typeName:M.ZodDate,...m2(e)});class hg extends m9{_parse(e){if(this._getType(e)!==mV.symbol){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.symbol,received:t.parsedType}),mW}return mX(e.data)}}hg.create=e=>new hg({typeName:M.ZodSymbol,...m2(e)});class hy extends m9{_parse(e){if(this._getType(e)!==mV.undefined){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.undefined,received:t.parsedType}),mW}return mX(e.data)}}hy.create=e=>new hy({typeName:M.ZodUndefined,...m2(e)});class hv extends m9{_parse(e){if(this._getType(e)!==mV.null){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.null,received:t.parsedType}),mW}return mX(e.data)}}hv.create=e=>new hv({typeName:M.ZodNull,...m2(e)});class h_ extends m9{constructor(){super(...arguments),this._any=!0}_parse(e){return mX(e.data)}}h_.create=e=>new h_({typeName:M.ZodAny,...m2(e)});class hb extends m9{constructor(){super(...arguments),this._unknown=!0}_parse(e){return mX(e.data)}}hb.create=e=>new hb({typeName:M.ZodUnknown,...m2(e)});class hS extends m9{_parse(e){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.never,received:t.parsedType}),mW}}hS.create=e=>new hS({typeName:M.ZodNever,...m2(e)});class h$ extends m9{_parse(e){if(this._getType(e)!==mV.undefined){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.void,received:t.parsedType}),mW}return mX(e.data)}}h$.create=e=>new h$({typeName:M.ZodVoid,...m2(e)});class hw extends m9{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==mV.array)return mK(t,{code:mH.invalid_type,expected:mV.array,received:t.parsedType}),mW;if(null!==a.exactLength){let e=t.data.length>a.exactLength.value,i=t.data.length<a.exactLength.value;(e||i)&&(mK(t,{code:e?mH.too_big:mH.too_small,minimum:i?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(mK(t,{code:mH.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(mK(t,{code:mH.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((e,r)=>a.type._parseAsync(new m0(t,e,t.path,r)))).then(e=>mG.mergeArray(r,e));let i=[...t.data].map((e,r)=>a.type._parseSync(new m0(t,e,t.path,r)));return mG.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new hw({...this._def,minLength:{value:e,message:z.toString(t)}})}max(e,t){return new hw({...this._def,maxLength:{value:e,message:z.toString(t)}})}length(e,t){return new hw({...this._def,exactLength:{value:e,message:z.toString(t)}})}nonempty(e){return this.min(1,e)}}hw.create=(e,t)=>new hw({type:e,minLength:null,maxLength:null,exactLength:null,typeName:M.ZodArray,...m2(t)});class hR extends m9{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let e=this._def.shape(),t=q.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==mV.object){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.object,received:t.parsedType}),mW}let{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),n=[];if(!(this._def.catchall instanceof hS&&"strip"===this._def.unknownKeys))for(let e in r.data)i.includes(e)||n.push(e);let o=[];for(let e of i){let t=a[e],i=r.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new m0(r,i,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof hS){let e=this._def.unknownKeys;if("passthrough"===e)for(let e of n)o.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)n.length>0&&(mK(r,{code:mH.unrecognized_keys,keys:n}),t.dirty());else if("strip"===e);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let e=this._def.catchall;for(let t of n){let a=r.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new m0(r,a,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then(async()=>{let e=[];for(let t of o){let r=await t.key,a=await t.value;e.push({key:r,value:a,alwaysSet:t.alwaysSet})}return e}).then(e=>mG.mergeObjectSync(t,e)):mG.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return z.errToObj,new hR({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{let a=this._def.errorMap?.(t,r).message??r.defaultError;return"unrecognized_keys"===t.code?{message:z.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new hR({...this._def,unknownKeys:"strip"})}passthrough(){return new hR({...this._def,unknownKeys:"passthrough"})}extend(e){return new hR({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new hR({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:M.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new hR({...this._def,catchall:e})}pick(e){let t={};for(let r of q.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new hR({...this._def,shape:()=>t})}omit(e){let t={};for(let r of q.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new hR({...this._def,shape:()=>t})}deepPartial(){return function e(t){if(t instanceof hR){let r={};for(let a in t.shape){let i=t.shape[a];r[a]=hz.create(e(i))}return new hR({...t._def,shape:()=>r})}if(t instanceof hw)return new hw({...t._def,type:e(t.element)});if(t instanceof hz)return hz.create(e(t.unwrap()));if(t instanceof hM)return hM.create(e(t.unwrap()));if(t instanceof hP)return hP.create(t.items.map(t=>e(t)));else return t}(this)}partial(e){let t={};for(let r of q.objectKeys(this.shape)){let a=this.shape[r];e&&!e[r]?t[r]=a:t[r]=a.optional()}return new hR({...this._def,shape:()=>t})}required(e){let t={};for(let r of q.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let e=this.shape[r];for(;e instanceof hz;)e=e._def.innerType;t[r]=e}return new hR({...this._def,shape:()=>t})}keyof(){return hC(q.objectKeys(this.shape))}}hR.create=(e,t)=>new hR({shape:()=>e,unknownKeys:"strip",catchall:hS.create(),typeName:M.ZodObject,...m2(t)}),hR.strictCreate=(e,t)=>new hR({shape:()=>e,unknownKeys:"strict",catchall:hS.create(),typeName:M.ZodObject,...m2(t)}),hR.lazycreate=(e,t)=>new hR({shape:e,unknownKeys:"strip",catchall:hS.create(),typeName:M.ZodObject,...m2(t)});class hk extends m9{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map(async e=>{let r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(function(e){for(let t of e)if("valid"===t.result.status)return t.result;for(let r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;let r=e.map(e=>new mJ(e.ctx.common.issues));return mK(t,{code:mH.invalid_union,unionErrors:r}),mW});{let e,a=[];for(let i of r){let r={...t,common:{...t.common,issues:[]},parent:null},n=i._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&a.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;let i=a.map(e=>new mJ(e));return mK(t,{code:mH.invalid_union,unionErrors:i}),mW}}get options(){return this._def.options}}hk.create=(e,t)=>new hk({options:e,typeName:M.ZodUnion,...m2(t)});class hx extends m9{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=(e,a)=>{if("aborted"===e.status||"aborted"===a.status)return mW;let i=function e(t,r){let a=mF(t),i=mF(r);if(t===r)return{valid:!0,data:t};if(a===mV.object&&i===mV.object){let a=q.objectKeys(r),i=q.objectKeys(t).filter(e=>-1!==a.indexOf(e)),n={...t,...r};for(let a of(Object.prototype.hasOwnProperty.call(n,"__proto__")&&delete n.__proto__,i)){if("__proto__"===a)continue;let i=e(t[a],r[a]);if(!i.valid)return{valid:!1};n[a]=i.data}return{valid:!0,data:n}}if(a===mV.array&&i===mV.array){if(t.length!==r.length)return{valid:!1};let a=[];for(let i=0;i<t.length;i++){let n=e(t[i],r[i]);if(!n.valid)return{valid:!1};a.push(n.data)}return{valid:!0,data:a}}if(a===mV.date&&i===mV.date&&+t==+r)return{valid:!0,data:t};return{valid:!1}}(e.value,a.value);return i.valid?(("dirty"===e.status||"dirty"===a.status)&&t.dirty(),{status:t.value,value:i.data}):(mK(r,{code:mH.invalid_intersection_types}),mW)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([e,t])=>a(e,t)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}hx.create=(e,t,r)=>new hx({left:e,right:t,typeName:M.ZodIntersection,...m2(r)});class hP extends m9{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mV.array)return mK(r,{code:mH.invalid_type,expected:mV.array,received:r.parsedType}),mW;if(r.data.length<this._def.items.length)return mK(r,{code:mH.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mW;!this._def.rest&&r.data.length>this._def.items.length&&(mK(r,{code:mH.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());let a=[...r.data].map((e,t)=>{let a=this._def.items[t]||this._def.rest;return a?a._parse(new m0(r,e,r.path,t)):null}).filter(e=>!!e);return r.common.async?Promise.all(a).then(e=>mG.mergeArray(t,e)):mG.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new hP({...this._def,rest:e})}}hP.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hP({items:e,typeName:M.ZodTuple,rest:null,...m2(t)})};class hE extends m9{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mV.map)return mK(r,{code:mH.invalid_type,expected:mV.map,received:r.parsedType}),mW;let a=this._def.keyType,i=this._def.valueType,n=[...r.data.entries()].map(([e,t],n)=>({key:a._parse(new m0(r,e,r.path,[n,"key"])),value:i._parse(new m0(r,t,r.path,[n,"value"]))}));if(r.common.async){let e=new Map;return Promise.resolve().then(async()=>{for(let r of n){let a=await r.key,i=await r.value;if("aborted"===a.status||"aborted"===i.status)return mW;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}})}{let e=new Map;for(let r of n){let a=r.key,i=r.value;if("aborted"===a.status||"aborted"===i.status)return mW;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}}}}hE.create=(e,t,r)=>new hE({valueType:t,keyType:e,typeName:M.ZodMap,...m2(r)});class hT extends m9{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mV.set)return mK(r,{code:mH.invalid_type,expected:mV.set,received:r.parsedType}),mW;let a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(mK(r,{code:mH.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(mK(r,{code:mH.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());let i=this._def.valueType;function n(e){let r=new Set;for(let a of e){if("aborted"===a.status)return mW;"dirty"===a.status&&t.dirty(),r.add(a.value)}return{status:t.value,value:r}}let o=[...r.data.values()].map((e,t)=>i._parse(new m0(r,e,r.path,t)));return r.common.async?Promise.all(o).then(e=>n(e)):n(o)}min(e,t){return new hT({...this._def,minSize:{value:e,message:z.toString(t)}})}max(e,t){return new hT({...this._def,maxSize:{value:e,message:z.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}hT.create=(e,t)=>new hT({valueType:e,minSize:null,maxSize:null,typeName:M.ZodSet,...m2(t)});class hj extends m9{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}hj.create=(e,t)=>new hj({getter:e,typeName:M.ZodLazy,...m2(t)});class hO extends m9{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return mK(t,{received:t.data,code:mH.invalid_literal,expected:this._def.value}),mW}return{status:"valid",value:e.data}}get value(){return this._def.value}}function hC(e,t){return new hI({values:e,typeName:M.ZodEnum,...m2(t)})}hO.create=(e,t)=>new hO({value:e,typeName:M.ZodLiteral,...m2(t)});class hI extends m9{_parse(e){if("string"!=typeof e.data){let t=this._getOrReturnCtx(e),r=this._def.values;return mK(t,{expected:q.joinValues(r),received:t.parsedType,code:mH.invalid_type}),mW}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return mK(t,{received:t.data,code:mH.invalid_enum_value,options:r}),mW}return mX(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return hI.create(e,{...this._def,...t})}exclude(e,t=this._def){return hI.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}hI.create=hC;class hN extends m9{_parse(e){let t=q.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==mV.string&&r.parsedType!==mV.number){let e=q.objectValues(t);return mK(r,{expected:q.joinValues(e),received:r.parsedType,code:mH.invalid_type}),mW}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let e=q.objectValues(t);return mK(r,{received:r.data,code:mH.invalid_enum_value,options:e}),mW}return mX(e.data)}get enum(){return this._def.values}}hN.create=(e,t)=>new hN({values:e,typeName:M.ZodNativeEnum,...m2(t)});class hq extends m9{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);return t.parsedType!==mV.promise&&!1===t.common.async?(mK(t,{code:mH.invalid_type,expected:mV.promise,received:t.parsedType}),mW):mX((t.parsedType===mV.promise?t.data:Promise.resolve(t.data)).then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}hq.create=(e,t)=>new hq({type:e,typeName:M.ZodPromise,...m2(t)});class hA extends m9{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===M.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=this._def.effect||null,i={addIssue:e=>{mK(r,e),e.fatal?t.abort():t.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===a.type){let e=a.transform(r.data,i);if(r.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return mW;let a=await this._def.schema._parseAsync({data:e,path:r.path,parent:r});return"aborted"===a.status?mW:"dirty"===a.status||"dirty"===t.value?mY(a.value):a});{if("aborted"===t.value)return mW;let a=this._def.schema._parseSync({data:e,path:r.path,parent:r});return"aborted"===a.status?mW:"dirty"===a.status||"dirty"===t.value?mY(a.value):a}}if("refinement"===a.type){let e=e=>{let t=a.refinement(e,i);if(r.common.async)return Promise.resolve(t);if(t instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(r=>"aborted"===r.status?mW:("dirty"===r.status&&t.dirty(),e(r.value).then(()=>({status:t.value,value:r.value}))));{let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===a.status?mW:("dirty"===a.status&&t.dirty(),e(a.value),{status:t.value,value:a.value})}}if("transform"===a.type)if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(e=>"valid"!==e.status?mW:Promise.resolve(a.transform(e.value,i)).then(e=>({status:t.value,value:e})));else{let e=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if("valid"!==e.status)return mW;let n=a.transform(e.value,i);if(n instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:n}}q.assertNever(a)}}hA.create=(e,t,r)=>new hA({schema:e,typeName:M.ZodEffects,effect:t,...m2(r)}),hA.createWithPreprocess=(e,t,r)=>new hA({schema:t,effect:{type:"preprocess",transform:e},typeName:M.ZodEffects,...m2(r)});class hz extends m9{_parse(e){return this._getType(e)===mV.undefined?mX(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hz.create=(e,t)=>new hz({innerType:e,typeName:M.ZodOptional,...m2(t)});class hM extends m9{_parse(e){return this._getType(e)===mV.null?mX(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hM.create=(e,t)=>new hM({innerType:e,typeName:M.ZodNullable,...m2(t)});class hL extends m9{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return t.parsedType===mV.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}hL.create=(e,t)=>new hL({innerType:e,typeName:M.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...m2(t)});class hZ extends m9{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return mQ(a)?a.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new mJ(r.common.issues)},input:r.data})})):{status:"valid",value:"valid"===a.status?a.value:this._def.catchValue({get error(){return new mJ(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}hZ.create=(e,t)=>new hZ({innerType:e,typeName:M.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...m2(t)});class hD extends m9{_parse(e){if(this._getType(e)!==mV.nan){let t=this._getOrReturnCtx(e);return mK(t,{code:mH.invalid_type,expected:mV.nan,received:t.parsedType}),mW}return{status:"valid",value:e.data}}}hD.create=e=>new hD({typeName:M.ZodNaN,...m2(e)}),Symbol("zod_brand");class hU extends m9{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class hV extends m9{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mW:"dirty"===e.status?(t.dirty(),mY(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{let e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mW:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new hV({in:e,out:t,typeName:M.ZodPipeline})}}class hF extends m9{_parse(e){let t=this._def.innerType._parse(e),r=e=>("valid"===e.status&&(e.value=Object.freeze(e.value)),e);return mQ(t)?t.then(e=>r(e)):r(t)}unwrap(){return this._def.innerType}}hF.create=(e,t)=>new hF({innerType:e,typeName:M.ZodReadonly,...m2(t)}),hR.lazycreate,(O=M||(M={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly";let hH=hd.create;hp.create,hD.create,hm.create,hh.create,hf.create,hg.create,hy.create,hv.create,h_.create,hb.create,hS.create,h$.create,hw.create;let hJ=hR.create;hR.strictCreate,hk.create,hx.create,hP.create,hE.create,hT.create,hj.create,hO.create,hI.create,hN.create,hq.create,hA.create,hz.create,hM.create,hA.createWithPreprocess,hV.create;let hB=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")};function hK(e){if("openAi"!==e.target)return{};let t=[...e.basePath,e.definitionPath,e.openAiAnyTypeName];return e.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===e.$refStrategy?hB(t,e.currentPath):t.join("/")}}function hG(e,t,r,a){a?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function hW(e,t,r,a,i){e[t]=r,hG(e,t,a,i)}function hY(e,t){return fl(e.type._def,t)}let hX=/^[cC][^\s-]{8,}$/,hQ=/^[0-9a-z]+$/,h0=/^[0-9A-HJKMNP-TV-Z]{26}$/,h1=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,h2=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),h9=/^(?:(?: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])$/,h4=/^(([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])$/,h3=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h5=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,h6=/^[a-zA-Z0-9_-]{21}$/,h7=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function h8(e,t){let r={type:"string"};if(e.checks)for(let a of e.checks)switch(a.kind){case"min":hW(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t);break;case"max":hW(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"email":switch(t.emailStrategy){case"format:email":fr(r,"email",a.message,t);break;case"format:idn-email":fr(r,"idn-email",a.message,t);break;case"pattern:zod":fa(r,h1,a.message,t)}break;case"url":fr(r,"uri",a.message,t);break;case"uuid":fr(r,"uuid",a.message,t);break;case"regex":fa(r,a.regex,a.message,t);break;case"cuid":fa(r,hX,a.message,t);break;case"cuid2":fa(r,hQ,a.message,t);break;case"startsWith":fa(r,RegExp(`^${fe(a.value,t)}`),a.message,t);break;case"endsWith":fa(r,RegExp(`${fe(a.value,t)}$`),a.message,t);break;case"datetime":fr(r,"date-time",a.message,t);break;case"date":fr(r,"date",a.message,t);break;case"time":fr(r,"time",a.message,t);break;case"duration":fr(r,"duration",a.message,t);break;case"length":hW(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t),hW(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"includes":fa(r,RegExp(fe(a.value,t)),a.message,t);break;case"ip":"v6"!==a.version&&fr(r,"ipv4",a.message,t),"v4"!==a.version&&fr(r,"ipv6",a.message,t);break;case"base64url":fa(r,h5,a.message,t);break;case"jwt":fa(r,h7,a.message,t);break;case"cidr":"v6"!==a.version&&fa(r,h9,a.message,t),"v4"!==a.version&&fa(r,h4,a.message,t);break;case"emoji":fa(r,h2(),a.message,t);break;case"ulid":fa(r,h0,a.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":fr(r,"binary",a.message,t);break;case"contentEncoding:base64":hW(r,"contentEncoding","base64",a.message,t);break;case"pattern:zod":fa(r,h3,a.message,t)}break;case"nanoid":fa(r,h6,a.message,t)}return r}function fe(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)ft.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}let ft=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fr(e,t,r,a){e.format||e.anyOf?.some(e=>e.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&a.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&a.errorMessages&&{errorMessage:{format:r}}})):hW(e,"format",t,r,a)}function fa(e,t,r,a){e.pattern||e.allOf?.some(e=>e.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&a.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:fi(t,a),...r&&a.errorMessages&&{errorMessage:{pattern:r}}})):hW(e,"pattern",fi(t,a),r,a)}function fi(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let r={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},a=r.i?e.source.toLowerCase():e.source,i="",n=!1,o=!1,s=!1;for(let e=0;e<a.length;e++){if(n){i+=a[e],n=!1;continue}if(r.i){if(o){if(a[e].match(/[a-z]/)){s?(i+=a[e],i+=`${a[e-2]}-${a[e]}`.toUpperCase(),s=!1):"-"===a[e+1]&&a[e+2]?.match(/[a-z]/)?(i+=a[e],s=!0):i+=`${a[e]}${a[e].toUpperCase()}`;continue}}else if(a[e].match(/[a-z]/)){i+=`[${a[e]}${a[e].toUpperCase()}]`;continue}}if(r.m){if("^"===a[e]){i+=`(^|(?<=[\r
|
|
77
|
+
`,e.enqueue(t.encode(i)),!0}catch(e){return this.onerror?.(e),!1}}handleUnsupportedRequest(){return this.onerror?.(Error("Method not allowed.")),Response.json({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null},{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(e,t){try{let r,a,i,n,o,s=e.headers.get("accept");if(!s?.includes("application/json")||!s.includes("text/event-stream"))return this.onerror?.(Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");if(!uA(e.headers.get("content-type")))return this.onerror?.(Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");if(t?.parsedBody===void 0)try{let t=await pX(e,this._maxRequestBodySize);if(t.tooLarge){let e=pW(this._maxRequestBodySize);return this.onerror?.(Error(e)),this.createJsonErrorResponse(413,-32e3,e)}r=JSON.parse(t.text)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}else r=t.parsedBody;if(Array.isArray(r)&&r.length>100)return this.onerror?.(Error("Invalid Request: Batch must not exceed 100 messages")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Batch must not exceed 100 messages");try{a=Array.isArray(r)?r.map(e=>os.parse(e)):[os.parse(r)]}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");let l=a.some(e=>o$.safeParse(e).success);if(l){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(a.length>1)return this.onerror?.(Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!l){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r}if(this._closed)return this.createJsonErrorResponse(404,-32001,"Session not found");try{i=await this._checkScopeChallenge(a,t?.authInfo)}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(500,-32603,"Internal server error")}if(i)return i;if(!a.some(e=>cB(e))){for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e});return new Response(null,{status:202})}let c=crypto.randomUUID(),u=a.find(e=>o$.safeParse(e).success),d=u?u.params.protocolVersion:e.headers.get("mcp-protocol-version")??"2025-03-26";if(this._enableJsonResponse)return new Promise(r=>{for(let e of(this._streamMapping.set(c,{resolveJson:r,cleanup:()=>{this._streamMapping.delete(c)}}),a))cB(e)&&this._requestToStreamMapping.set(e.id,c);for(let r of a)this.onmessage?.(r,{authInfo:t?.authInfo,request:e})});let p=new TextEncoder,m=new ReadableStream({start:e=>{n=e},cancel:()=>{void 0!==o&&clearInterval(o),this._streamMapping.get(c)?.controller===n&&this._streamMapping.delete(c)}}),h={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"};for(let e of(void 0!==this.sessionId&&(h["mcp-session-id"]=this.sessionId),a))cB(e)&&(this._streamMapping.set(c,{controller:n,encoder:p,cleanup:()=>{void 0!==o&&clearInterval(o),this._streamMapping.delete(c);try{n.close()}catch{}}}),this._requestToStreamMapping.set(e.id,c));for(let r of(await this.writePrimingEvent(n,p,c,d),a)){let a,i;cB(r)&&this._eventStore&&this.supportsEmptySSEData(d)&&(a=()=>{this.closeSSEStream(r.id)},i=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(r,{authInfo:t?.authInfo,request:e,closeSSEStream:a,closeStandaloneSSEStream:i})}return this._streamMapping.get(c)?.controller===n&&(o=this.startKeepAlive(n,p)),new Response(m,{status:200,headers:h})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(e)})}}async handleDeleteRequest(e){let t=this.validateSession(e);if(t)return t;let r=this.validateProtocolVersion(e);if(r)return r;try{return await Promise.resolve(this._onsessionclosed?.(this.sessionId)),new Response(null,{status:200})}finally{await this.close()}}validateSession(e){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let t=e.headers.get("mcp-session-id");return t?t!==this.sessionId?(this.onerror?.(Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(e){let t=e.headers.get("mcp-protocol-version");if(null!==t&&!this._supportedProtocolVersions.includes(t)){let e=`Bad Request: Unsupported protocol version: ${t} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;return this.onerror?.(Error(e)),this.createJsonErrorResponse(400,-32e3,e)}}async close(){if(!this._closed){for(let{cleanup:e}of(this._closed=!0,this._streamMapping.values()))e();this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}}closeSSEStream(e){let t=this._requestToStreamMapping.get(e);if(!t)return;let r=this._streamMapping.get(t);r&&r.cleanup()}closeStandaloneSSEStream(){let e=this._streamMapping.get(this._standaloneSseStreamId);e&&e.cleanup()}async send(e,t){let r=t?.relatedRequestId;if((cG(e)||cW(e))&&(r=e.id),void 0===r){let t;if(cG(e)||cW(e))throw Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");this._eventStore&&(t=await this._eventStore.storeEvent(this._standaloneSseStreamId,e));let r=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===r)return;r.controller&&r.encoder&&(void 0===t||!r.replayedEventIds?.has(t))&&this.writeSSEEvent(r.controller,r.encoder,e,t);return}let a=this._requestToStreamMapping.get(r);if(!a)throw Error(`No connection established for request ID: ${String(r)}`);let i=this._streamMapping.get(a);if(!this._enableJsonResponse){let t;this._eventStore&&(t=await this._eventStore.storeEvent(a,e),i=this._streamMapping.get(a)),i?.controller&&i?.encoder&&(void 0===t||!i.replayedEventIds?.has(t))&&this.writeSSEEvent(i.controller,i.encoder,e,t)}if(cG(e)||cW(e)){this._requestResponseMap.set(r,e);let t=[...this._requestToStreamMapping.entries()].filter(([e,t])=>t===a).map(([e])=>e);if(t.every(e=>this._requestResponseMap.has(e))){if(!i){if(this._enableJsonResponse)throw Error(`No connection established for request ID: ${String(r)}`);if(!this._eventStore){for(let e of(this.onerror?.(Error(`Response for request ID ${String(r)} is undeliverable: per-request stream is disconnected and no eventStore is configured`)),t))this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e);return}if(this._enableJsonResponse&&i.resolveJson){let e={"Content-Type":"application/json"};void 0!==this.sessionId&&(e["mcp-session-id"]=this.sessionId);let r=t.map(e=>this._requestResponseMap.get(e));1===r.length?i.resolveJson(Response.json(r[0],{status:200,headers:e})):i.resolveJson(Response.json(r,{status:200,headers:e})),i.cleanup()}else i.cleanup();for(let e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e)}}}};function p0(e){if(null===e||"object"!=typeof e||Array.isArray(e))return null;let{method:t,id:r}=e;return"string"!=typeof t?null:"string"==typeof r||"number"==typeof r?r:null}function p1(e,t,r,a,i=null){return Response.json({jsonrpc:"2.0",error:{code:t,message:r,...void 0!==a&&{data:a}},id:i},{status:e,...405===e&&{headers:{Allow:"POST"}}})}function p2(e,t=null){return p1(e.httpStatus,e.code,e.message,e.data,t)}function p9(e){return e instanceof Error?e:Error(String(e))}function p4(e=null){return p1(500,-32603,"Internal server error",void 0,e)}function p3(e){if(void 0!==e.transport)throw Error("The factory returned an instance that is still serving another request. Return a new instance for each request.")}function p5(e){return{protocolVersionHeader:e.headers.get("mcp-protocol-version")??void 0,mcpMethodHeader:e.headers.get("mcp-method")??void 0,mcpNameHeader:e.headers.get("mcp-name")??void 0}}let p6=require("async_hooks"),p7=(e,t)=>{globalThis[e]=t},p8=e=>globalThis[e];function me({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(p8(r))return p8(r);let i=new p6.AsyncLocalStorage,n=globalThis[a]??{current:null};p7(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return p7(r,o),o}let mt=me({name:"http-request-context"}),mr=mt.setContext,ma=mt.getContext,mi=mt.provider,mn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),mo=e=>{if(!mn(e)||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},ms=e=>{if(e&&"initialize"===e.method&&mn(e.params))return mo(e.params.clientInfo)},ml=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}};function mc(e){let{tags:t,enabled:r,...a}=e;return{...a,_meta:void 0===t?a._meta:{...a._meta,"xmcp/tags":t}}}let mu=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){var e,t;e="resources",t=new Map,e in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},md=me({name:"request-context",fallback:!1});function mp(){try{return md.getContext().value}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}function mm(e,t,r,a=!1){let i;if(a){let t;try{t=md.getContext()}catch{}if(t?.request===e.mcpReq)return r()}let n=new Map;if(e.http){let e=ma(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));i=Object.freeze({id:e.id,headers:Object.freeze(t)})}let o=Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:i,authInfo:e.http?.authInfo,_meta:e.mcpReq._meta?Object.freeze({...e.mcpReq._meta}):void 0,signal:e.mcpReq.signal,set(e,t){n.set(e,t)},get:e=>n.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)});return md.provider({request:e.mcpReq,value:o},r)}function mh(e){let t=e?.["xmcp/tags"];return Array.isArray(t)?t:void 0}function mf(e,t,r=!1){let a;try{a=new URL(t).toString()}catch{return}for(let i of r?[t,a]:[a]){let t=e.uiOwners.get(i)??e.resources.get(i);if(t)return t}for(let{component:t,template:r}of e.templates.values())if(r.uriTemplate.match(a))return t}let mg=me({name:"client-info-context"});mg.setContext;let my=mg.getContext;mg.provider;let mv=new Set(["message","mode","requestedSchema"]),m_=new Set(["elicitationId","message","mode","url"]),mb=new Set(["properties","required","type"]),mS=new Set(["default","description","format","maxLength","minLength","title","type"]),m$=new Set(["default","description","enum","enumNames","title","type"]),mw=new Set(["default","description","title","type"]),mR=new Set(["default","description","maximum","minimum","title","type"]),mk=new Set(["date","date-time","email","uri"]);function mx(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function mP(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mE(e,t){if("string"!=typeof e)throw Error(t)}function mT(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mj(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mO(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mC(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}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"]);function mA(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mz={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mM(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mz[e.type];return t?t(e):{valid:!0}}let mL=Symbol("Let zodToJsonSchema decide on which parser to use"),mZ={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"};(T=q||(q={})).assertEqual=e=>{},T.assertIs=function(e){},T.assertNever=function(e){throw Error()},T.arrayToEnum=e=>{let t={};for(let r of e)t[r]=r;return t},T.getValidEnumValues=e=>{let t=T.objectKeys(e).filter(t=>"number"!=typeof e[e[t]]),r={};for(let a of t)r[a]=e[a];return T.objectValues(r)},T.objectValues=e=>T.objectKeys(e).map(function(t){return e[t]}),T.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{let t=[];for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t},T.find=(e,t)=>{for(let r of e)if(t(r))return r},T.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,T.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},T.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(A||(A={})).mergeShapes=(e,t)=>({...e,...t});let mD=q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),mU=e=>{switch(typeof e){case"undefined":return mD.undefined;case"string":return mD.string;case"number":return Number.isNaN(e)?mD.nan:mD.number;case"boolean":return mD.boolean;case"function":return mD.function;case"bigint":return mD.bigint;case"symbol":return mD.symbol;case"object":if(Array.isArray(e))return mD.array;if(null===e)return mD.null;if(e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch)return mD.promise;if("u">typeof Map&&e instanceof Map)return mD.map;if("u">typeof Set&&e instanceof Set)return mD.set;if("u">typeof Date&&e instanceof Date)return mD.date;return mD.object;default:return mD.unknown}},mV=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 mF extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(e){return e.message},r={_errors:[]},a=e=>{for(let i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(a);else if("invalid_return_type"===i.code)a(i.returnTypeError);else if("invalid_arguments"===i.code)a(i.argumentsError);else if(0===i.path.length)r._errors.push(t(i));else{let e=r,a=0;for(;a<i.path.length;){let r=i.path[a],n=a===i.path.length-1;if("_errors"===r){n&&e._errors.push(t(i)),a++;continue}Object.prototype.hasOwnProperty.call(e,r)||("__proto__"===r?Object.defineProperty(e,r,{value:{_errors:[]},writable:!0,enumerable:!0,configurable:!0}):e[r]={_errors:[]}),e=e[r],n&&e._errors.push(t(i)),a++}}};return a(this),r}static assert(e){if(!(e instanceof mF))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,q.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){let t=Object.create(null),r=[];for(let a of this.issues)if(a.path.length>0){let r=a.path[0];t[r]=t[r]||[],t[r].push(e(a))}else r.push(e(a));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}mF.create=e=>new mF(e);let mH=(e,t)=>{let r;switch(e.code){case mV.invalid_type:r=e.received===mD.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case mV.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,q.jsonStringifyReplacer)}`;break;case mV.unrecognized_keys:r=`Unrecognized key(s) in object: ${q.joinValues(e.keys,", ")}`;break;case mV.invalid_union:r="Invalid input";break;case mV.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${q.joinValues(e.options)}`;break;case mV.invalid_enum_value:r=`Invalid enum value. Expected ${q.joinValues(e.options)}, received '${e.received}'`;break;case mV.invalid_arguments:r="Invalid function arguments";break;case mV.invalid_return_type:r="Invalid function return type";break;case mV.invalid_date:r="Invalid date";break;case mV.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(r=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(r=`${r} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?r=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?r=`Invalid input: must end with "${e.validation.endsWith}"`:q.assertNever(e.validation):r="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case mV.too_small:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case mV.too_big:r="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case mV.custom:r="Invalid input";break;case mV.invalid_intersection_types:r="Intersection results could not be merged";break;case mV.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case mV.not_finite:r="Number must be finite";break;default:r=t.defaultError,q.assertNever(e)}return{message:r}};(j=z||(z={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},j.toString=e=>"string"==typeof e?e:e?.message;function mJ(e,t){let r=(e=>{let{data:t,path:r,errorMaps:a,issueData:i}=e,n=[...r,...i.path||[]],o={...i,path:n};if(void 0!==i.message)return{...i,path:n,message:i.message};let s="";for(let e of a.filter(e=>!!e).slice().reverse())s=e(o,{data:t,defaultError:s}).message;return{...i,path:n,message:s}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,mH,void 0].filter(e=>!!e)});e.common.issues.push(r)}class mB{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){let r=[];for(let a of t){if("aborted"===a.status)return mK;"dirty"===a.status&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let e of t){let t=await e.key,a=await e.value;r.push({key:t,value:a})}return mB.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let a of t){let{key:t,value:i}=a;if("aborted"===t.status||"aborted"===i.status)return mK;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"!==t.value&&(void 0!==i.value||a.alwaysSet)&&(r[t.value]=i.value)}return{status:e.value,value:r}}}let mK=Object.freeze({status:"aborted"}),mG=e=>({status:"dirty",value:e}),mW=e=>({status:"valid",value:e}),mY=e=>"u">typeof Promise&&e instanceof Promise;class mX{constructor(e,t,r,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}let mQ=(e,t)=>{if("valid"===t.status)return{success:!0,data:t.value};if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let t=new mF(e.common.issues);return this._error=t,this._error}}};function m0(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:a,description:i}=e;if(t&&(r||a))throw Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:i}:{errorMap:(t,i)=>{let{message:n}=e;return"invalid_enum_value"===t.code?{message:n??i.defaultError}:void 0===i.data?{message:n??a??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:n??r??i.defaultError}},description:i}}class m1{get description(){return this._def.description}_getType(e){return mU(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:mU(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new mB,ctx:{common:e.parent.common,data:e.data,parsedType:mU(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(mY(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){return Promise.resolve(this._parse(e))}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mU(e)},a=this._parseSync({data:e,path:r.path,parent:r});return mQ(r,a)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mU(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return"valid"===r.status?{value:r.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>"valid"===e.status?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:mU(e)},a=this._parse({data:e,path:r.path,parent:r});return mQ(r,await (mY(a)?a:Promise.resolve(a)))}refine(e,t){return this._refinement((r,a)=>{let i=e(r),n=()=>a.addIssue({code:mV.custom,..."string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(r):t});return"u">typeof Promise&&i instanceof Promise?i.then(e=>!!e||(n(),!1)):!!i||(n(),!1)})}refinement(e,t){return this._refinement((r,a)=>!!e(r)||(a.addIssue("function"==typeof t?t(r,a):t),!1))}_refinement(e){return new hN({schema:this,typeName:M.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return hq.create(this,this._def)}nullable(){return hA.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return hS.create(this)}promise(){return hI.create(this,this._def)}or(e){return hw.create([this,e],this._def)}and(e){return hR.create(this,e,this._def)}transform(e){return new hN({...m0(this._def),schema:this,typeName:M.ZodEffects,effect:{type:"transform",transform:e}})}default(e){return new hz({...m0(this._def),innerType:this,defaultValue:"function"==typeof e?e:()=>e,typeName:M.ZodDefault})}brand(){return new hZ({typeName:M.ZodBranded,type:this,...m0(this._def)})}catch(e){return new hM({...m0(this._def),innerType:this,catchValue:"function"==typeof e?e:()=>e,typeName:M.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return hD.create(this,e)}readonly(){return hU.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}let m2=/^c[^\s-]{8,}$/i,m9=/^[0-9a-z]+$/,m4=/^[0-9A-HJKMNP-TV-Z]{26}$/i,m3=/^[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,m5=/^[a-z0-9_-]{21}$/i,m6=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,m7=/^[-+]?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)?)??$/,m8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,he=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ht=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,hr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ha=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,hi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ho="((\\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])))",hs=RegExp(`^${ho}$`);function hl(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}class hc extends m1{_parse(e){var t,r,a,i;let n;if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==mD.string){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.string,received:t.parsedType}),mK}let o=new mB;for(let s of this._def.checks)if("min"===s.kind)e.data.length<s.value&&(mJ(n=this._getOrReturnCtx(e,n),{code:mV.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("max"===s.kind)e.data.length>s.value&&(mJ(n=this._getOrReturnCtx(e,n),{code:mV.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),o.dirty());else if("length"===s.kind){let t=e.data.length>s.value,r=e.data.length<s.value;(t||r)&&(n=this._getOrReturnCtx(e,n),t?mJ(n,{code:mV.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&mJ(n,{code:mV.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),o.dirty())}else if("email"===s.kind)m8.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"email",code:mV.invalid_string,message:s.message}),o.dirty());else if("emoji"===s.kind)h||(h=RegExp("^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$","u")),h.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"emoji",code:mV.invalid_string,message:s.message}),o.dirty());else if("uuid"===s.kind)m3.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"uuid",code:mV.invalid_string,message:s.message}),o.dirty());else if("nanoid"===s.kind)m5.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"nanoid",code:mV.invalid_string,message:s.message}),o.dirty());else if("cuid"===s.kind)m2.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"cuid",code:mV.invalid_string,message:s.message}),o.dirty());else if("cuid2"===s.kind)m9.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"cuid2",code:mV.invalid_string,message:s.message}),o.dirty());else if("ulid"===s.kind)m4.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"ulid",code:mV.invalid_string,message:s.message}),o.dirty());else if("url"===s.kind)try{new URL(e.data)}catch{mJ(n=this._getOrReturnCtx(e,n),{validation:"url",code:mV.invalid_string,message:s.message}),o.dirty()}else"regex"===s.kind?(s.regex.lastIndex=0,s.regex.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"regex",code:mV.invalid_string,message:s.message}),o.dirty())):"trim"===s.kind?e.data=e.data.trim():"includes"===s.kind?e.data.includes(s.value,s.position)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),o.dirty()):"toLowerCase"===s.kind?e.data=e.data.toLowerCase():"toUpperCase"===s.kind?e.data=e.data.toUpperCase():"startsWith"===s.kind?e.data.startsWith(s.value)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:{startsWith:s.value},message:s.message}),o.dirty()):"endsWith"===s.kind?e.data.endsWith(s.value)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:{endsWith:s.value},message:s.message}),o.dirty()):"datetime"===s.kind?(function(e){let t=`${ho}T${hl(e)}`,r=[];return r.push(e.local?"Z?":"Z"),e.offset&&r.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${r.join("|")})`,RegExp(`^${t}$`)})(s).test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:"datetime",message:s.message}),o.dirty()):"date"===s.kind?hs.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:"date",message:s.message}),o.dirty()):"time"===s.kind?RegExp(`^${hl(s)}$`).test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{code:mV.invalid_string,validation:"time",message:s.message}),o.dirty()):"duration"===s.kind?m7.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"duration",code:mV.invalid_string,message:s.message}),o.dirty()):"ip"===s.kind?(t=e.data,!(("v4"===(r=s.version)||!r)&&he.test(t)||("v6"===r||!r)&&hr.test(t))&&1&&(mJ(n=this._getOrReturnCtx(e,n),{validation:"ip",code:mV.invalid_string,message:s.message}),o.dirty())):"jwt"===s.kind?!function(e,t){if(!m6.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let a=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),i=JSON.parse(atob(a));if("object"!=typeof i||null===i||"typ"in i&&i?.typ!=="JWT"||!i.alg||t&&i.alg!==t)return!1;return!0}catch{return!1}}(e.data,s.alg)&&(mJ(n=this._getOrReturnCtx(e,n),{validation:"jwt",code:mV.invalid_string,message:s.message}),o.dirty()):"cidr"===s.kind?(a=e.data,!(("v4"===(i=s.version)||!i)&&ht.test(a)||("v6"===i||!i)&&ha.test(a))&&1&&(mJ(n=this._getOrReturnCtx(e,n),{validation:"cidr",code:mV.invalid_string,message:s.message}),o.dirty())):"base64"===s.kind?hi.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"base64",code:mV.invalid_string,message:s.message}),o.dirty()):"base64url"===s.kind?hn.test(e.data)||(mJ(n=this._getOrReturnCtx(e,n),{validation:"base64url",code:mV.invalid_string,message:s.message}),o.dirty()):q.assertNever(s);return{status:o.value,value:e.data}}_regex(e,t,r){return this.refinement(t=>e.test(t),{validation:t,code:mV.invalid_string,...z.errToObj(r)})}_addCheck(e){return new hc({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...z.errToObj(e)})}url(e){return this._addCheck({kind:"url",...z.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...z.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...z.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...z.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...z.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...z.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...z.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...z.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...z.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...z.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...z.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...z.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...z.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...z.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...z.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...z.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...z.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...z.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...z.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...z.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...z.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...z.errToObj(t)})}nonempty(e){return this.min(1,z.errToObj(e))}trim(){return new hc({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new hc({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new hc({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hc.create=e=>new hc({checks:[],typeName:M.ZodString,coerce:e?.coerce??!1,...m0(e)});class hu extends m1{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){let t;if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==mD.number){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.number,received:t.parsedType}),mK}let r=new mB;for(let a of this._def.checks)"int"===a.kind?q.isInteger(e.data)||(mJ(t=this._getOrReturnCtx(e,t),{code:mV.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):"multipleOf"===a.kind?0!==function(e,t){let r=(e.toString().split(".")[1]||"").length,a=(t.toString().split(".")[1]||"").length,i=r>a?r:a;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(e.data,a.value)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(e.data)||(mJ(t=this._getOrReturnCtx(e,t),{code:mV.not_finite,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hu({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hu({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:z.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:z.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:z.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:z.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&q.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if("finite"===r.kind||"int"===r.kind||"multipleOf"===r.kind)return!0;else"min"===r.kind?(null===t||r.value>t)&&(t=r.value):"max"===r.kind&&(null===e||r.value<e)&&(e=r.value);return Number.isFinite(t)&&Number.isFinite(e)}}hu.create=e=>new hu({checks:[],typeName:M.ZodNumber,coerce:e?.coerce||!1,...m0(e)});class hd extends m1{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){let t;if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==mD.bigint)return this._getInvalidInput(e);let r=new mB;for(let a of this._def.checks)"min"===a.kind?(a.inclusive?e.data<a.value:e.data<=a.value)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"max"===a.kind?(a.inclusive?e.data>a.value:e.data>=a.value)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):"multipleOf"===a.kind?e.data%a.value!==BigInt(0)&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):q.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.bigint,received:t.parsedType}),mK}gte(e,t){return this.setLimit("min",e,!0,z.toString(t))}gt(e,t){return this.setLimit("min",e,!1,z.toString(t))}lte(e,t){return this.setLimit("max",e,!0,z.toString(t))}lt(e,t){return this.setLimit("max",e,!1,z.toString(t))}setLimit(e,t,r,a){return new hd({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:z.toString(a)}]})}_addCheck(e){return new hd({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:z.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:z.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:z.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:z.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:z.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}hd.create=e=>new hd({checks:[],typeName:M.ZodBigInt,coerce:e?.coerce??!1,...m0(e)});class hp extends m1{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==mD.boolean){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.boolean,received:t.parsedType}),mK}return mW(e.data)}}hp.create=e=>new hp({typeName:M.ZodBoolean,coerce:e?.coerce||!1,...m0(e)});class hm extends m1{_parse(e){let t;if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==mD.date){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.date,received:t.parsedType}),mK}if(Number.isNaN(e.data.getTime()))return mJ(this._getOrReturnCtx(e),{code:mV.invalid_date}),mK;let r=new mB;for(let a of this._def.checks)"min"===a.kind?e.data.getTime()<a.value&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):"max"===a.kind?e.data.getTime()>a.value&&(mJ(t=this._getOrReturnCtx(e,t),{code:mV.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):q.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new hm({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:z.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:z.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}hm.create=e=>new hm({checks:[],coerce:e?.coerce||!1,typeName:M.ZodDate,...m0(e)});class hh extends m1{_parse(e){if(this._getType(e)!==mD.symbol){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.symbol,received:t.parsedType}),mK}return mW(e.data)}}hh.create=e=>new hh({typeName:M.ZodSymbol,...m0(e)});class hf extends m1{_parse(e){if(this._getType(e)!==mD.undefined){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.undefined,received:t.parsedType}),mK}return mW(e.data)}}hf.create=e=>new hf({typeName:M.ZodUndefined,...m0(e)});class hg extends m1{_parse(e){if(this._getType(e)!==mD.null){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.null,received:t.parsedType}),mK}return mW(e.data)}}hg.create=e=>new hg({typeName:M.ZodNull,...m0(e)});class hy extends m1{constructor(){super(...arguments),this._any=!0}_parse(e){return mW(e.data)}}hy.create=e=>new hy({typeName:M.ZodAny,...m0(e)});class hv extends m1{constructor(){super(...arguments),this._unknown=!0}_parse(e){return mW(e.data)}}hv.create=e=>new hv({typeName:M.ZodUnknown,...m0(e)});class h_ extends m1{_parse(e){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.never,received:t.parsedType}),mK}}h_.create=e=>new h_({typeName:M.ZodNever,...m0(e)});class hb extends m1{_parse(e){if(this._getType(e)!==mD.undefined){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.void,received:t.parsedType}),mK}return mW(e.data)}}hb.create=e=>new hb({typeName:M.ZodVoid,...m0(e)});class hS extends m1{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),a=this._def;if(t.parsedType!==mD.array)return mJ(t,{code:mV.invalid_type,expected:mD.array,received:t.parsedType}),mK;if(null!==a.exactLength){let e=t.data.length>a.exactLength.value,i=t.data.length<a.exactLength.value;(e||i)&&(mJ(t,{code:e?mV.too_big:mV.too_small,minimum:i?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(mJ(t,{code:mV.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(mJ(t,{code:mV.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((e,r)=>a.type._parseAsync(new mX(t,e,t.path,r)))).then(e=>mB.mergeArray(r,e));let i=[...t.data].map((e,r)=>a.type._parseSync(new mX(t,e,t.path,r)));return mB.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new hS({...this._def,minLength:{value:e,message:z.toString(t)}})}max(e,t){return new hS({...this._def,maxLength:{value:e,message:z.toString(t)}})}length(e,t){return new hS({...this._def,exactLength:{value:e,message:z.toString(t)}})}nonempty(e){return this.min(1,e)}}hS.create=(e,t)=>new hS({type:e,minLength:null,maxLength:null,exactLength:null,typeName:M.ZodArray,...m0(t)});class h$ extends m1{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;let e=this._def.shape(),t=q.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==mD.object){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.object,received:t.parsedType}),mK}let{status:t,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),n=[];if(!(this._def.catchall instanceof h_&&"strip"===this._def.unknownKeys))for(let e in r.data)i.includes(e)||n.push(e);let o=[];for(let e of i){let t=a[e],i=r.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new mX(r,i,r.path,e)),alwaysSet:e in r.data})}if(this._def.catchall instanceof h_){let e=this._def.unknownKeys;if("passthrough"===e)for(let e of n)o.push({key:{status:"valid",value:e},value:{status:"valid",value:r.data[e]}});else if("strict"===e)n.length>0&&(mJ(r,{code:mV.unrecognized_keys,keys:n}),t.dirty());else if("strip"===e);else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let e=this._def.catchall;for(let t of n){let a=r.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new mX(r,a,r.path,t)),alwaysSet:t in r.data})}}return r.common.async?Promise.resolve().then(async()=>{let e=[];for(let t of o){let r=await t.key,a=await t.value;e.push({key:r,value:a,alwaysSet:t.alwaysSet})}return e}).then(e=>mB.mergeObjectSync(t,e)):mB.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return z.errToObj,new h$({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,r)=>{let a=this._def.errorMap?.(t,r).message??r.defaultError;return"unrecognized_keys"===t.code?{message:z.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new h$({...this._def,unknownKeys:"strip"})}passthrough(){return new h$({...this._def,unknownKeys:"passthrough"})}extend(e){return new h$({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new h$({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:M.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new h$({...this._def,catchall:e})}pick(e){let t={};for(let r of q.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new h$({...this._def,shape:()=>t})}omit(e){let t={};for(let r of q.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new h$({...this._def,shape:()=>t})}deepPartial(){return function e(t){if(t instanceof h$){let r={};for(let a in t.shape){let i=t.shape[a];r[a]=hq.create(e(i))}return new h$({...t._def,shape:()=>r})}if(t instanceof hS)return new hS({...t._def,type:e(t.element)});if(t instanceof hq)return hq.create(e(t.unwrap()));if(t instanceof hA)return hA.create(e(t.unwrap()));if(t instanceof hk)return hk.create(t.items.map(t=>e(t)));else return t}(this)}partial(e){let t={};for(let r of q.objectKeys(this.shape)){let a=this.shape[r];e&&!e[r]?t[r]=a:t[r]=a.optional()}return new h$({...this._def,shape:()=>t})}required(e){let t={};for(let r of q.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let e=this.shape[r];for(;e instanceof hq;)e=e._def.innerType;t[r]=e}return new h$({...this._def,shape:()=>t})}keyof(){return hj(q.objectKeys(this.shape))}}h$.create=(e,t)=>new h$({shape:()=>e,unknownKeys:"strip",catchall:h_.create(),typeName:M.ZodObject,...m0(t)}),h$.strictCreate=(e,t)=>new h$({shape:()=>e,unknownKeys:"strict",catchall:h_.create(),typeName:M.ZodObject,...m0(t)}),h$.lazycreate=(e,t)=>new h$({shape:e,unknownKeys:"strip",catchall:h_.create(),typeName:M.ZodObject,...m0(t)});class hw extends m1{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;if(t.common.async)return Promise.all(r.map(async e=>{let r={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(function(e){for(let t of e)if("valid"===t.result.status)return t.result;for(let r of e)if("dirty"===r.result.status)return t.common.issues.push(...r.ctx.common.issues),r.result;let r=e.map(e=>new mF(e.ctx.common.issues));return mJ(t,{code:mV.invalid_union,unionErrors:r}),mK});{let e,a=[];for(let i of r){let r={...t,common:{...t.common,issues:[]},parent:null},n=i._parseSync({data:t.data,path:t.path,parent:r});if("valid"===n.status)return n;"dirty"!==n.status||e||(e={result:n,ctx:r}),r.common.issues.length&&a.push(r.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;let i=a.map(e=>new mF(e));return mJ(t,{code:mV.invalid_union,unionErrors:i}),mK}}get options(){return this._def.options}}hw.create=(e,t)=>new hw({options:e,typeName:M.ZodUnion,...m0(t)});class hR extends m1{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=(e,a)=>{if("aborted"===e.status||"aborted"===a.status)return mK;let i=function e(t,r){let a=mU(t),i=mU(r);if(t===r)return{valid:!0,data:t};if(a===mD.object&&i===mD.object){let a=q.objectKeys(r),i=q.objectKeys(t).filter(e=>-1!==a.indexOf(e)),n={...t,...r};for(let a of(Object.prototype.hasOwnProperty.call(n,"__proto__")&&delete n.__proto__,i)){if("__proto__"===a)continue;let i=e(t[a],r[a]);if(!i.valid)return{valid:!1};n[a]=i.data}return{valid:!0,data:n}}if(a===mD.array&&i===mD.array){if(t.length!==r.length)return{valid:!1};let a=[];for(let i=0;i<t.length;i++){let n=e(t[i],r[i]);if(!n.valid)return{valid:!1};a.push(n.data)}return{valid:!0,data:a}}if(a===mD.date&&i===mD.date&&+t==+r)return{valid:!0,data:t};return{valid:!1}}(e.value,a.value);return i.valid?(("dirty"===e.status||"dirty"===a.status)&&t.dirty(),{status:t.value,value:i.data}):(mJ(r,{code:mV.invalid_intersection_types}),mK)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([e,t])=>a(e,t)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}hR.create=(e,t,r)=>new hR({left:e,right:t,typeName:M.ZodIntersection,...m0(r)});class hk extends m1{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mD.array)return mJ(r,{code:mV.invalid_type,expected:mD.array,received:r.parsedType}),mK;if(r.data.length<this._def.items.length)return mJ(r,{code:mV.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mK;!this._def.rest&&r.data.length>this._def.items.length&&(mJ(r,{code:mV.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());let a=[...r.data].map((e,t)=>{let a=this._def.items[t]||this._def.rest;return a?a._parse(new mX(r,e,r.path,t)):null}).filter(e=>!!e);return r.common.async?Promise.all(a).then(e=>mB.mergeArray(t,e)):mB.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new hk({...this._def,rest:e})}}hk.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new hk({items:e,typeName:M.ZodTuple,rest:null,...m0(t)})};class hx extends m1{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mD.map)return mJ(r,{code:mV.invalid_type,expected:mD.map,received:r.parsedType}),mK;let a=this._def.keyType,i=this._def.valueType,n=[...r.data.entries()].map(([e,t],n)=>({key:a._parse(new mX(r,e,r.path,[n,"key"])),value:i._parse(new mX(r,t,r.path,[n,"value"]))}));if(r.common.async){let e=new Map;return Promise.resolve().then(async()=>{for(let r of n){let a=await r.key,i=await r.value;if("aborted"===a.status||"aborted"===i.status)return mK;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}})}{let e=new Map;for(let r of n){let a=r.key,i=r.value;if("aborted"===a.status||"aborted"===i.status)return mK;("dirty"===a.status||"dirty"===i.status)&&t.dirty(),e.set(a.value,i.value)}return{status:t.value,value:e}}}}hx.create=(e,t,r)=>new hx({valueType:t,keyType:e,typeName:M.ZodMap,...m0(r)});class hP extends m1{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==mD.set)return mJ(r,{code:mV.invalid_type,expected:mD.set,received:r.parsedType}),mK;let a=this._def;null!==a.minSize&&r.data.size<a.minSize.value&&(mJ(r,{code:mV.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&r.data.size>a.maxSize.value&&(mJ(r,{code:mV.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());let i=this._def.valueType;function n(e){let r=new Set;for(let a of e){if("aborted"===a.status)return mK;"dirty"===a.status&&t.dirty(),r.add(a.value)}return{status:t.value,value:r}}let o=[...r.data.values()].map((e,t)=>i._parse(new mX(r,e,r.path,t)));return r.common.async?Promise.all(o).then(e=>n(e)):n(o)}min(e,t){return new hP({...this._def,minSize:{value:e,message:z.toString(t)}})}max(e,t){return new hP({...this._def,maxSize:{value:e,message:z.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}hP.create=(e,t)=>new hP({valueType:e,minSize:null,maxSize:null,typeName:M.ZodSet,...m0(t)});class hE extends m1{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}hE.create=(e,t)=>new hE({getter:e,typeName:M.ZodLazy,...m0(t)});class hT extends m1{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return mJ(t,{received:t.data,code:mV.invalid_literal,expected:this._def.value}),mK}return{status:"valid",value:e.data}}get value(){return this._def.value}}function hj(e,t){return new hO({values:e,typeName:M.ZodEnum,...m0(t)})}hT.create=(e,t)=>new hT({value:e,typeName:M.ZodLiteral,...m0(t)});class hO extends m1{_parse(e){if("string"!=typeof e.data){let t=this._getOrReturnCtx(e),r=this._def.values;return mJ(t,{expected:q.joinValues(r),received:t.parsedType,code:mV.invalid_type}),mK}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return mJ(t,{received:t.data,code:mV.invalid_enum_value,options:r}),mK}return mW(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return hO.create(e,{...this._def,...t})}exclude(e,t=this._def){return hO.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}hO.create=hj;class hC extends m1{_parse(e){let t=q.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==mD.string&&r.parsedType!==mD.number){let e=q.objectValues(t);return mJ(r,{expected:q.joinValues(e),received:r.parsedType,code:mV.invalid_type}),mK}if(this._cache||(this._cache=new Set(q.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let e=q.objectValues(t);return mJ(r,{received:r.data,code:mV.invalid_enum_value,options:e}),mK}return mW(e.data)}get enum(){return this._def.values}}hC.create=(e,t)=>new hC({values:e,typeName:M.ZodNativeEnum,...m0(t)});class hI extends m1{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);return t.parsedType!==mD.promise&&!1===t.common.async?(mJ(t,{code:mV.invalid_type,expected:mD.promise,received:t.parsedType}),mK):mW((t.parsedType===mD.promise?t.data:Promise.resolve(t.data)).then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}hI.create=(e,t)=>new hI({type:e,typeName:M.ZodPromise,...m0(t)});class hN extends m1{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===M.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),a=this._def.effect||null,i={addIssue:e=>{mJ(r,e),e.fatal?t.abort():t.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===a.type){let e=a.transform(r.data,i);if(r.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return mK;let a=await this._def.schema._parseAsync({data:e,path:r.path,parent:r});return"aborted"===a.status?mK:"dirty"===a.status||"dirty"===t.value?mG(a.value):a});{if("aborted"===t.value)return mK;let a=this._def.schema._parseSync({data:e,path:r.path,parent:r});return"aborted"===a.status?mK:"dirty"===a.status||"dirty"===t.value?mG(a.value):a}}if("refinement"===a.type){let e=e=>{let t=a.refinement(e,i);if(r.common.async)return Promise.resolve(t);if(t instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(r=>"aborted"===r.status?mK:("dirty"===r.status&&t.dirty(),e(r.value).then(()=>({status:t.value,value:r.value}))));{let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===a.status?mK:("dirty"===a.status&&t.dirty(),e(a.value),{status:t.value,value:a.value})}}if("transform"===a.type)if(!1!==r.common.async)return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(e=>"valid"!==e.status?mK:Promise.resolve(a.transform(e.value,i)).then(e=>({status:t.value,value:e})));else{let e=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if("valid"!==e.status)return mK;let n=a.transform(e.value,i);if(n instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:n}}q.assertNever(a)}}hN.create=(e,t,r)=>new hN({schema:e,typeName:M.ZodEffects,effect:t,...m0(r)}),hN.createWithPreprocess=(e,t,r)=>new hN({schema:t,effect:{type:"preprocess",transform:e},typeName:M.ZodEffects,...m0(r)});class hq extends m1{_parse(e){return this._getType(e)===mD.undefined?mW(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hq.create=(e,t)=>new hq({innerType:e,typeName:M.ZodOptional,...m0(t)});class hA extends m1{_parse(e){return this._getType(e)===mD.null?mW(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hA.create=(e,t)=>new hA({innerType:e,typeName:M.ZodNullable,...m0(t)});class hz extends m1{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return t.parsedType===mD.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}hz.create=(e,t)=>new hz({innerType:e,typeName:M.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...m0(t)});class hM extends m1{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return mY(a)?a.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new mF(r.common.issues)},input:r.data})})):{status:"valid",value:"valid"===a.status?a.value:this._def.catchValue({get error(){return new mF(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}hM.create=(e,t)=>new hM({innerType:e,typeName:M.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...m0(t)});class hL extends m1{_parse(e){if(this._getType(e)!==mD.nan){let t=this._getOrReturnCtx(e);return mJ(t,{code:mV.invalid_type,expected:mD.nan,received:t.parsedType}),mK}return{status:"valid",value:e.data}}}hL.create=e=>new hL({typeName:M.ZodNaN,...m0(e)}),Symbol("zod_brand");class hZ extends m1{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class hD extends m1{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let e=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mK:"dirty"===e.status?(t.dirty(),mG(e.value)):this._def.out._parseAsync({data:e.value,path:r.path,parent:r})})();{let e=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return"aborted"===e.status?mK:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:r.path,parent:r})}}static create(e,t){return new hD({in:e,out:t,typeName:M.ZodPipeline})}}class hU extends m1{_parse(e){let t=this._def.innerType._parse(e),r=e=>("valid"===e.status&&(e.value=Object.freeze(e.value)),e);return mY(t)?t.then(e=>r(e)):r(t)}unwrap(){return this._def.innerType}}hU.create=(e,t)=>new hU({innerType:e,typeName:M.ZodReadonly,...m0(t)}),h$.lazycreate,(O=M||(M={})).ZodString="ZodString",O.ZodNumber="ZodNumber",O.ZodNaN="ZodNaN",O.ZodBigInt="ZodBigInt",O.ZodBoolean="ZodBoolean",O.ZodDate="ZodDate",O.ZodSymbol="ZodSymbol",O.ZodUndefined="ZodUndefined",O.ZodNull="ZodNull",O.ZodAny="ZodAny",O.ZodUnknown="ZodUnknown",O.ZodNever="ZodNever",O.ZodVoid="ZodVoid",O.ZodArray="ZodArray",O.ZodObject="ZodObject",O.ZodUnion="ZodUnion",O.ZodDiscriminatedUnion="ZodDiscriminatedUnion",O.ZodIntersection="ZodIntersection",O.ZodTuple="ZodTuple",O.ZodRecord="ZodRecord",O.ZodMap="ZodMap",O.ZodSet="ZodSet",O.ZodFunction="ZodFunction",O.ZodLazy="ZodLazy",O.ZodLiteral="ZodLiteral",O.ZodEnum="ZodEnum",O.ZodEffects="ZodEffects",O.ZodNativeEnum="ZodNativeEnum",O.ZodOptional="ZodOptional",O.ZodNullable="ZodNullable",O.ZodDefault="ZodDefault",O.ZodCatch="ZodCatch",O.ZodPromise="ZodPromise",O.ZodBranded="ZodBranded",O.ZodPipeline="ZodPipeline",O.ZodReadonly="ZodReadonly";let hV=hc.create;hu.create,hL.create,hd.create,hp.create,hm.create,hh.create,hf.create,hg.create,hy.create,hv.create,h_.create,hb.create,hS.create;let hF=h$.create;h$.strictCreate,hw.create,hR.create,hk.create,hx.create,hP.create,hE.create,hT.create,hO.create,hC.create,hI.create,hN.create,hq.create,hA.create,hN.createWithPreprocess,hD.create;let hH=(e,t)=>{let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];r++);return[(e.length-r).toString(),...t.slice(r)].join("/")};function hJ(e){if("openAi"!==e.target)return{};let t=[...e.basePath,e.definitionPath,e.openAiAnyTypeName];return e.flags.hasReferencedOpenAiAnyType=!0,{$ref:"relative"===e.$refStrategy?hH(t,e.currentPath):t.join("/")}}function hB(e,t,r,a){a?.errorMessages&&r&&(e.errorMessage={...e.errorMessage,[t]:r})}function hK(e,t,r,a,i){e[t]=r,hB(e,t,a,i)}function hG(e,t){return fo(e.type._def,t)}let hW=/^[cC][^\s-]{8,}$/,hY=/^[0-9a-z]+$/,hX=/^[0-9A-HJKMNP-TV-Z]{26}$/,hQ=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,h0=()=>(void 0===w&&(w=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),w),h1=/^(?:(?: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])$/,h2=/^(([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])$/,h9=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h4=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,h3=/^[a-zA-Z0-9_-]{21}$/,h5=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;function h6(e,t){let r={type:"string"};if(e.checks)for(let a of e.checks)switch(a.kind){case"min":hK(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t);break;case"max":hK(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"email":switch(t.emailStrategy){case"format:email":fe(r,"email",a.message,t);break;case"format:idn-email":fe(r,"idn-email",a.message,t);break;case"pattern:zod":ft(r,hQ,a.message,t)}break;case"url":fe(r,"uri",a.message,t);break;case"uuid":fe(r,"uuid",a.message,t);break;case"regex":ft(r,a.regex,a.message,t);break;case"cuid":ft(r,hW,a.message,t);break;case"cuid2":ft(r,hY,a.message,t);break;case"startsWith":ft(r,RegExp(`^${h7(a.value,t)}`),a.message,t);break;case"endsWith":ft(r,RegExp(`${h7(a.value,t)}$`),a.message,t);break;case"datetime":fe(r,"date-time",a.message,t);break;case"date":fe(r,"date",a.message,t);break;case"time":fe(r,"time",a.message,t);break;case"duration":fe(r,"duration",a.message,t);break;case"length":hK(r,"minLength","number"==typeof r.minLength?Math.max(r.minLength,a.value):a.value,a.message,t),hK(r,"maxLength","number"==typeof r.maxLength?Math.min(r.maxLength,a.value):a.value,a.message,t);break;case"includes":ft(r,RegExp(h7(a.value,t)),a.message,t);break;case"ip":"v6"!==a.version&&fe(r,"ipv4",a.message,t),"v4"!==a.version&&fe(r,"ipv6",a.message,t);break;case"base64url":ft(r,h4,a.message,t);break;case"jwt":ft(r,h5,a.message,t);break;case"cidr":"v6"!==a.version&&ft(r,h1,a.message,t),"v4"!==a.version&&ft(r,h2,a.message,t);break;case"emoji":ft(r,h0(),a.message,t);break;case"ulid":ft(r,hX,a.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":fe(r,"binary",a.message,t);break;case"contentEncoding:base64":hK(r,"contentEncoding","base64",a.message,t);break;case"pattern:zod":ft(r,h9,a.message,t)}break;case"nanoid":ft(r,h3,a.message,t)}return r}function h7(e,t){return"escape"===t.patternStrategy?function(e){let t="";for(let r=0;r<e.length;r++)h8.has(e[r])||(t+="\\"),t+=e[r];return t}(e):e}let h8=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function fe(e,t,r,a){e.format||e.anyOf?.some(e=>e.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&a.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...r&&a.errorMessages&&{errorMessage:{format:r}}})):hK(e,"format",t,r,a)}function ft(e,t,r,a){e.pattern||e.allOf?.some(e=>e.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&a.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:fr(t,a),...r&&a.errorMessages&&{errorMessage:{pattern:r}}})):hK(e,"pattern",fr(t,a),r,a)}function fr(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let r={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},a=r.i?e.source.toLowerCase():e.source,i="",n=!1,o=!1,s=!1;for(let e=0;e<a.length;e++){if(n){i+=a[e],n=!1;continue}if(r.i){if(o){if(a[e].match(/[a-z]/)){s?(i+=a[e],i+=`${a[e-2]}-${a[e]}`.toUpperCase(),s=!1):"-"===a[e+1]&&a[e+2]?.match(/[a-z]/)?(i+=a[e],s=!0):i+=`${a[e]}${a[e].toUpperCase()}`;continue}}else if(a[e].match(/[a-z]/)){i+=`[${a[e]}${a[e].toUpperCase()}]`;continue}}if(r.m){if("^"===a[e]){i+=`(^|(?<=[\r
|
|
78
78
|
]))`;continue}else if("$"===a[e]){i+=`($|(?=[\r
|
|
79
79
|
]))`;continue}}if(r.s&&"."===a[e]){i+=o?`${a[e]}\r
|
|
80
80
|
`:`[${a[e]}\r
|
|
81
|
-
]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function fn(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===M.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:fl(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??hK(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:fl(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===M.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=h8(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===M.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===M.ZodBranded&&e.keyType._def.type._def.typeName===M.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=hY(e.keyType._def,t);return{...r,propertyNames:i}}return r}let fo={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fs=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>fl(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function fl(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==mD)return i}if(a&&!r){let e=fc(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case M.ZodString:return h8(e,r);case M.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",hG(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?hW(a,"minimum",t.value,t.message,r):hW(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),hW(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hW(a,"maximum",t.value,t.message,r):hW(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),hW(a,"maximum",t.value,t.message,r));break;case"multipleOf":hW(a,"multipleOf",t.value,t.message,r)}return a;case M.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=fl(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return fl(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case M.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?hW(i,"minimum",t.value,t.message,r):hW(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),hW(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hW(i,"maximum",t.value,t.message,r):hW(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),hW(i,"maximum",t.value,t.message,r));break;case"multipleOf":hW(i,"multipleOf",t.value,t.message,r)}return i;case M.ZodBoolean:return{type:"boolean"};case M.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":hW(s,"minimum",e.value,e.message,o);break;case"max":hW(s,"maximum",e.value,e.message,o)}return s}}(e,r);case M.ZodUndefined:return{not:hK(r)};case M.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case M.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==M.ZodAny&&(n.items=fl(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&hW(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&hW(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(hW(n,"minItems",e.exactLength.value,e.exactLength.message,r),hW(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case M.ZodUnion:case M.ZodDiscriminatedUnion:if("openApi3"===r.target)return fs(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in fo&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=fo[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return fs(e,r);case M.ZodIntersection:let s,l,c;return s=[fl(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),fl(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case M.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>fl(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:fl(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>fl(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case M.ZodRecord:return fn(e,r);case M.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case M.ZodEnum:return{type:"string",enum:Array.from(e.values)};case M.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case M.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:fo[e.innerType._def.typeName],nullable:!0}:{type:[fo[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=fl(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=fl(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case M.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return fl(e.innerType._def,r);let f=fl(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:hK(r)},f]}:hK(r);case M.ZodMap:if("record"===r.mapStrategy)return fn(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[fl(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||hK(r),fl(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||hK(r)],minItems:2,maxItems:2}};case M.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fl(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&hW(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&hW(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case M.ZodLazy:return()=>e.getter()._def;case M.ZodPromise:return fl(e.type._def,r);case M.ZodNaN:case M.ZodNever:return"openAi"===r.target?void 0:{not:hK({...r,currentPath:[...r.currentPath,"not"]})};case M.ZodEffects:return"input"===r.effectStrategy?fl(e.schema._def,r):hK(r);case M.ZodAny:case M.ZodUnknown:return hK(r);case M.ZodDefault:return{...fl(e.innerType._def,r),default:e.defaultValue()};case M.ZodBranded:return hY(e,r);case M.ZodReadonly:case M.ZodCatch:return fl(e.innerType._def,r);case M.ZodPipeline:if("input"===r.pipeStrategy)return fl(e.in._def,r);if("output"===r.pipeStrategy)return fl(e.out._def,r);let y=fl(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=fl(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case M.ZodFunction:case M.ZodVoid:case M.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?fl(n(),t):n;if(o&&fu(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let fc=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:hB(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),hK(t);return"seen"===t.$refStrategy?hK(t):void 0}},fu=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function fd(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=function(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...mU,name:t}:{...mU,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:fl(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??hK(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=fl(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??hK(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=a8(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}},jsonSchema:{input:i("input"),output:i("output")}}}}function fp(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let fm=["ui/resourceUri","resourceUri","visibility"],fh=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function ff(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function fg(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function fy(e,t,r){return e.names?.includes(t)===!0||e.tags?.some(e=>r.includes(e))===!0}function fv(e,t){return t?new Map([...e].filter(([e,{metadata:r}])=>{if(r?.enabled===!1)return!1;let a=r?.name??fg(e),i=r?.tags??[];return(!t.include||fy(t.include,a,i))&&(!t.exclude||!fy(t.exclude,a,i))})):e}function f_(e){return Error(`[xmcp] Invalid prompt file: ${e}
|
|
82
|
-
-> Default export must be a prompt handler function.`)}let
|
|
83
|
-
-> ${r}`)});let i=r.length;e.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.`)}let
|
|
85
|
-
-> ${r}`)});let i=r.length;e.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.`)}let
|
|
87
|
-
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),
|
|
81
|
+
]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function fa(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===M.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:fo(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??hJ(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:fo(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===M.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=h6(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===M.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===M.ZodBranded&&e.keyType._def.type._def.typeName===M.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=hG(e.keyType._def,t);return{...r,propertyNames:i}}return r}let fi={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},fn=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>fo(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function fo(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==mL)return i}if(a&&!r){let e=fs(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case M.ZodString:return h6(e,r);case M.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",hB(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?hK(a,"minimum",t.value,t.message,r):hK(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),hK(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hK(a,"maximum",t.value,t.message,r):hK(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),hK(a,"maximum",t.value,t.message,r));break;case"multipleOf":hK(a,"multipleOf",t.value,t.message,r)}return a;case M.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=fo(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return fo(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case M.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?hK(i,"minimum",t.value,t.message,r):hK(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),hK(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?hK(i,"maximum",t.value,t.message,r):hK(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),hK(i,"maximum",t.value,t.message,r));break;case"multipleOf":hK(i,"multipleOf",t.value,t.message,r)}return i;case M.ZodBoolean:return{type:"boolean"};case M.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":hK(s,"minimum",e.value,e.message,o);break;case"max":hK(s,"maximum",e.value,e.message,o)}return s}}(e,r);case M.ZodUndefined:return{not:hJ(r)};case M.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case M.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==M.ZodAny&&(n.items=fo(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&hK(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&hK(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(hK(n,"minItems",e.exactLength.value,e.exactLength.message,r),hK(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case M.ZodUnion:case M.ZodDiscriminatedUnion:if("openApi3"===r.target)return fn(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in fi&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=fi[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return fn(e,r);case M.ZodIntersection:let s,l,c;return s=[fo(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),fo(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case M.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>fo(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:fo(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>fo(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case M.ZodRecord:return fa(e,r);case M.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case M.ZodEnum:return{type:"string",enum:Array.from(e.values)};case M.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case M.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:fi[e.innerType._def.typeName],nullable:!0}:{type:[fi[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=fo(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=fo(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case M.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return fo(e.innerType._def,r);let f=fo(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:hJ(r)},f]}:hJ(r);case M.ZodMap:if("record"===r.mapStrategy)return fa(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[fo(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||hJ(r),fo(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||hJ(r)],minItems:2,maxItems:2}};case M.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:fo(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&hK(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&hK(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case M.ZodLazy:return()=>e.getter()._def;case M.ZodPromise:return fo(e.type._def,r);case M.ZodNaN:case M.ZodNever:return"openAi"===r.target?void 0:{not:hJ({...r,currentPath:[...r.currentPath,"not"]})};case M.ZodEffects:return"input"===r.effectStrategy?fo(e.schema._def,r):hJ(r);case M.ZodAny:case M.ZodUnknown:return hJ(r);case M.ZodDefault:return{...fo(e.innerType._def,r),default:e.defaultValue()};case M.ZodBranded:return hG(e,r);case M.ZodReadonly:case M.ZodCatch:return fo(e.innerType._def,r);case M.ZodPipeline:if("input"===r.pipeStrategy)return fo(e.in._def,r);if("output"===r.pipeStrategy)return fo(e.out._def,r);let y=fo(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=fo(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case M.ZodFunction:case M.ZodVoid:case M.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?fo(n(),t):n;if(o&&fl(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let fs=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:hH(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),hJ(t);return"seen"===t.$refStrategy?hJ(t):void 0}},fl=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function fc(e){if("object"!=typeof e||null===e)return!1;let t=e["~standard"];return"object"==typeof t&&null!==t&&"function"==typeof t.validate}function fu(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...mZ,name:t}:{...mZ,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:fo(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??hJ(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=fo(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??hJ(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=a8(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}function fd(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=fu(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}},jsonSchema:{input:i("input"),output:i("output")}}}}function fp(e,t={}){let r;return fc(e)?{..."object"==typeof(r=e.shape)&&null!==r&&Object.values(r).every(fc)?{shape:r}:{},"~standard":{version:1,vendor:"xmcp",validate:t=>e["~standard"].validate(t),jsonSchema:{input:({target:t})=>fu(e,t,"input"),output:({target:t})=>fu(e,t,"output")}}}:fd(e,t)}async function fm(e,t,r,a){if(fc(t)){let i=await t["~standard"].validate(e);if(i.issues){let e=i.issues.map(e=>{let t=(e.path??[]).map(e=>"object"==typeof e&&null!==e&&"key"in e?String(e.key):String(e)).join(".");return t?`${t}: ${e.message}`:e.message}).join("; ");throw Error(`Tool "${r}" ${a}: ${e}`)}return}if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function fh(e){return!(!e||"object"!=typeof e||Array.isArray(e))&&("structuredContent"in e||"content"in e&&Array.isArray(e.content)||"_meta"in e||"isError"in e)}function ff(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function fg(e){let t=e.mcpReq.envelope,r=mo(t?.[nJ]);if(!r)try{let e,t=ma();r=t.clientInfo??(e=t.headers,mo({name:ml(e,"x-mcp-client-name"),version:ml(e,"x-mcp-client-version"),title:ml(e,"x-mcp-client-title"),websiteUrl:ml(e,"x-mcp-client-website-url"),description:ml(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=my().clientInfo}catch{}return r}function fy(e,t=!1){let r=[...e];return(e,a,i)=>mm(a,fg(a),async()=>{if(0===r.length)return i();let t=Object.freeze({...mp(),...e,params:Object.freeze({...e.params})}),a=-1,n=async e=>{if(e<=a)throw Error("MCP middleware next() can only be called once");a=e;let o=r[e];return o?o(t,()=>n(e+1)):i()};return n(0)},t)}function fv(e,t=new WeakMap){if(null===e||"object"!=typeof e)return e;let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&null!==r)return e;if(t.has(e))return t.get(e);let a=Array.isArray(e)?[]:Object.create(r);for(let[r,i]of(t.set(e,a),Object.entries(e)))Object.defineProperty(a,r,{value:fv(i,t),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(a)}let f_=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function fb(e){return e.endsWith(".tsx")}function fS(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let f$=["ui/resourceUri","resourceUri","visibility"],fw=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"];function fR(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function fk(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function fx(e,t,r){return e.names?.includes(t)===!0||e.tags?.some(e=>r.includes(e))===!0}function fP(e,t){return t?new Map([...e].filter(([e,{metadata:r}])=>{if(r?.enabled===!1)return!1;let a=r?.name??fk(e),i=r?.tags??[];return(!t.include||fx(t.include,a,i))&&(!t.exclude||!fx(t.exclude,a,i))})):e}function fE(e){if("string"!=typeof e)return;let t=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(e);if(!(!t||"ff"===t[1]||/^0+$/.test(t[2])||/^0+$/.test(t[3]))&&("00"!==t[1]||void 0===t[5]))return{trace:{id:t[2]},parent:{id:t[3]}}}function fT(e){return Error(`[xmcp] Invalid prompt file: ${e}
|
|
82
|
+
-> Default export must be a prompt handler function.`)}let fj=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load prompt file: ${t}
|
|
83
|
+
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fO(e){return Error(`[xmcp] Invalid resource file: ${e}
|
|
84
|
+
-> Default export must be a resource handler function.`)}let fC=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load resource file: ${t}
|
|
85
|
+
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function fI(e){let t=e.replace(/\\/g,"/");if(!t)throw Error("Invalid tool path: path is empty");let r=t.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:t,baseName:r}}function fN(e){let t=e.split("/").filter(e=>""!==e),r=t.findIndex(e=>e.match(/^\(.+\)$/));if(-1===r)return null;let a=t[t.length-1];if(a&&a.match(/^\[.+\]\.ts$/))return null;let i=t[r].slice(1,-1),n=t.slice(r+1),o=n[n.length-1];if(o&&o.includes(".")){let e=o.split(".")[0];"index"!==e?n[n.length-1]=e:n.pop()}let s=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=s.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:s,pathSegments:l,type:d}}let fq={ttlMs:0,cacheScope:"private"},fA=hF({cursor:hV().optional()}).passthrough().optional(),fz=hF({uri:hV()}).passthrough();function fM({uri:e,frontmatter:t,files:r}){return{uri:e,frontmatter:t,resources:r.map(({uri:e,digest:t,size:r})=>({uri:e,digest:t,size:r}))}}function fL(e){return Error(`[xmcp] Invalid tool file: ${e}
|
|
86
|
+
-> Default export must be a tool handler function.`)}let fZ=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load tool file: ${t}
|
|
87
|
+
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fD=INJECTED_TOOLS,fU=INJECTED_PROMPTS,fV=INJECTED_RESOURCES,fF="u"<typeof INJECTED_SKILLS?[]:INJECTED_SKILLS??[],fH=SERVER_INFO,fJ={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, OPTIONS","Access-Control-Allow-Headers":"*","Access-Control-Max-Age":"86400"};function fB(e,t,r,a,i){let n=new URL(e.url).origin,o=`${n}/.well-known/oauth-protected-resource`;return new Response(JSON.stringify({jsonrpc:"2.0",error:{code:i,message:r},id:null}),{status:a,headers:{"WWW-Authenticate":`Bearer error="${t}", error_description="${r}", resource_metadata="${o}"`,"Content-Type":"application/json"}})}function fK(e,t){return async r=>{var a,i;let n,{verifyToken:o,required:s=!1,requiredScopes:l}=t,c=function(e){let t=e.headers.get("Authorization"),[r,a]=t?.split(" ")||[];return r?.toLowerCase()==="bearer"?a:void 0}(r);try{n=await o(r,c)}catch(e){return console.error("[MCP Auth] Error verifying token:",e),fB(r,"invalid_token","Invalid token",401,-32001)}return s&&!n?fB(r,"invalid_token","No authorization provided",401,-32001):n?void 0!==(a=n).expiresAt&&a.expiresAt<Date.now()/1e3?fB(r,"invalid_token","Token has expired",401,-32001):l?.length&&(i=n,!l.every(e=>i.scopes.includes(e)))?fB(r,"insufficient_scope","Insufficient scope",403,-32002):(r.auth=n,e(r)):e(r)}}function fG(e){return t=>{let r;return new Response(JSON.stringify({resource:((r=new URL(t.url)).pathname=r.pathname.replace(/^\/\.well-known\/[^\/]+/,""),"/"===r.pathname?r.toString().replace(/\/$/,""):r.toString()),authorization_servers:e.authorizationServers}),{headers:{...fJ,"Cache-Control":"max-age=3600","Content-Type":"application/json"}})}}function fW(e){return new Response(null,{status:200,headers:fJ})}let fY=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t,o=pY(t.maxRequestBodySize);if("function"==typeof a)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let s=new Set,l=!1,u=e=>{try{i?.(e)}catch{}},h=t.bus??new pB(u),f={toolsChanged:()=>h.publish({kind:"tools_list_changed"}),promptsChanged:()=>h.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>h.publish({kind:"resources_list_changed"}),resourceUpdated:e=>h.publish({kind:"resource_updated",uri:e})},g=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){let c,u,d,p,m,h,f;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),pK(e.id,-32603,"Subscription limit reached");let g=(m=cq(cN).validateRequest("subscriptions/listen",e)).ok?m.value.params?.notifications:void 0;if(void 0===g)return pK(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let y=(h={},f=e=>void 0===s||!0===e,!0===g.toolsListChanged&&f(s?.tools?.listChanged)&&(h.toolsListChanged=!0),!0===g.promptsListChanged&&f(s?.prompts?.listChanged)&&(h.promptsListChanged=!0),!0===g.resourcesListChanged&&f(s?.resources?.listChanged)&&(h.resourcesListChanged=!0),void 0!==g.resourceSubscriptions&&g.resourceSubscriptions.length>0&&f(s?.resources?.subscribe)&&(h.resourceSubscriptions=[...g.resourceSubscriptions]),h),v=e.id,_=new TextEncoder,b=!1,S=e=>{if(!b)try{c.enqueue(_.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},$=(e,t)=>{S(`event: message
|
|
88
88
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
89
89
|
|
|
90
90
|
`)},w=e=>{if(!b){e&&S(`event: message
|
|
91
91
|
data: ${JSON.stringify({jsonrpc:"2.0",id:v,result:{resultType:"complete",_meta:{[nG]:v,[nB]:l}}})}
|
|
92
92
|
|
|
93
|
-
`),b=!0;try{u?.()}catch(e){r?.(e instanceof Error?e:Error(String(e)))}void 0!==d&&clearInterval(d),p?.(),n.delete(w);try{c.close()}catch{}}},R=new ReadableStream({start(e){c=e;let r=pG({method:"notifications/subscriptions/acknowledged",params:{notifications:y}},v);($(r.method,r.params),0===Object.keys(y).length)?w(!0):(u=t.subscribe(e=>{if(b||!function(e,t){switch(t.kind){case"tools_list_changed":return!0===e.toolsListChanged;case"prompts_list_changed":return!0===e.promptsListChanged;case"resources_list_changed":return!0===e.resourcesListChanged;case"resource_updated":return void 0!==e.resourceSubscriptions&&e.resourceSubscriptions.includes(t.uri)}}(y,e))return;let t=pG(function(e){switch(e.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed",...void 0!==e.params&&{params:e.params}};case"prompts_list_changed":return{method:"notifications/prompts/list_changed",...void 0!==e.params&&{params:e.params}};case"resources_list_changed":return{method:"notifications/resources/list_changed",...void 0!==e.params&&{params:e.params}};case"resource_updated":return{method:"notifications/resources/updated",params:{...e.params,uri:e.uri}}}}(e),v);$(t.method,t.params)}),d=pk(i,()=>S(": keepalive\n\n")),n.add(w))},cancel(){w(!1)}});if(void 0!==o)if(o.aborted)w(!1);else{let e=()=>w(!1);o.addEventListener("abort",e,{once:!0}),p=()=>o.removeEventListener("abort",e)}return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let e of n)e(!0)},get openCount(){return n.size}}}({bus:h,maxSubscriptions:t.maxSubscriptions??1024,keepAliveMs:t.keepAliveMs??15e3,onerror:u});"json"===n&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let y="reject"===a?void 0:(r=t.keepAliveMs,async(t,a)=>{if("POST"!==t.method.toUpperCase())return p1(405,-32e3,"Method not allowed.");try{let i=await e({era:"legacy",...a?.authInfo!==void 0&&{authInfo:a.authInfo},requestInfo:t}),n=new pQ({sessionIdGenerator:void 0,...void 0!==r&&{keepAliveMs:r},...void 0!==o&&{maxRequestBodySize:o}});await i.connect(n);let s=()=>{n.close().catch(()=>{}),i.close().catch(()=>{})};t.signal?.addEventListener("abort",s,{once:!0});let l=await n.handleRequest(t,{...a?.authInfo!==void 0&&{authInfo:a.authInfo},...a?.parsedBody!==void 0&&{parsedBody:a.parsedBody}});if(null===l.body||"text/event-stream"!==uq(l.headers.get("content-type")))return s(),l;let c=l.body.getReader(),u=!1,d=()=>{u||(u=!0,s())},p=new ReadableStream({pull:async e=>{try{let{done:t,value:r}=await c.read();if(t){d(),e.close();return}void 0!==r&&e.enqueue(r)}catch(t){d(),e.error(t)}},cancel:e=>(d(),c.cancel(e).catch(()=>{}))});return new Response(p,{status:l.status,statusText:l.statusText,headers:l.headers})}catch(e){try{u?.(p9(e))}catch{}return p4(p0(a?.parsedBody))}});return{fetch:async(r,a)=>{if(l)throw Error("This MCP handler has been closed");try{return await async function(r,a){let i=a?.authInfo;if("POST"===r.method.toUpperCase()&&!uA(r.headers.get("content-type")))return u(Error("Unsupported Media Type: Content-Type must be application/json")),p1(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let l=await async function(e,t,r=!0,a=4194304){let i,n=e.method.toUpperCase(),o=t,s=e,l=!1;if("POST"===n){if(void 0===o){let t;r&&(s=e.clone());try{let r=await pX(e,a);if(r.tooLarge)return{step:"body-too-large"};t=r.text}catch{return{step:"unreadable-body"}}try{i=0===t.length?void 0:JSON.parse(t)}catch{l=!0}l||void 0===i||(o=i)}else i=o;if(l||void 0===i)return{step:"no-json-body",forwardRequest:s}}return{step:"classified",outcome:function(e){if("POST"!==(e={...e,...void 0!==e.protocolVersionHeader&&{protocolVersionHeader:ui(e.protocolVersionHeader)},...void 0!==e.mcpMethodHeader&&{mcpMethodHeader:ui(e.mcpMethodHeader)},...void 0!==e.mcpNameHeader&&{mcpNameHeader:ui(e.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let t=e.body;if(Array.isArray(t)){if(0===t.length)return ut("jsonrpc-shape","empty-batch",400,new cf(ch.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let e of t){if(cV(un(e)?e.params:void 0))return ut("jsonrpc-shape","batch-with-modern-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cB(e)||cK(e)||cG(e)||cW(e)))return ut("jsonrpc-shape","batch-with-invalid-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cG(t)||cW(t)?{kind:"legacy",reason:"response"}:un(t)&&cB(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if("initialize"===a&&!function(e){if(!cV(e))return!1;let t=cF(e);if(void 0===t||!(t>=lG))return!1;let r=cU(e);return void 0!==r&&0===cH(r).length}(r)){if(n)return ur("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let e=un(r)&&"string"==typeof r.protocolVersion?r.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(cV(r)){let n=cU(r),o=(void 0===n?[]:cH(n))[0];if(void 0!==o)return ut("envelope","envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${o.key}: ${o.problem}`,{envelope:o}),!0);let s=cF(r);return void 0!==i&&void 0!==s&&i!==s?ur("header-body-version-mismatch",i,`the body envelope names protocol version ${s} but the MCP-Protocol-Version header names ${i}`):void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("method-header-mismatch",e.mcpMethodHeader,`the body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:t,classification:uo(s)}}if(n){let e=cU(r),t=cH(e??{}).filter(e=>"missing"===e.problem).map(e=>e.key),a=void 0===e?["_meta"]:t.length>0?t:[nH];return ut("envelope","modern-header-without-claim",400,new cf(ch.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${a.join(", ")}`,{envelope:{missing:a}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(e,t):un(t)&&cK(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if(cV(r)){let n=cF(r);if(void 0===n){let e=cU(r),t=(void 0===e?[]:cH(e)).find(e=>e.key===nH)??{key:nH,problem:"expected a protocol version string"};return ut("envelope","notification-envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${t.key}: ${t.problem}`,{envelope:t}),!0)}if(void 0!==i&&i!==n)return ur("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${n} but the MCP-Protocol-Version header names ${i}`);let o=uo(n);return"modern"===o.era&&void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:o}}return n?void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(e,t):ut("jsonrpc-shape","invalid-json-rpc-body",400,new cf(ch.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:n,...p5(e),...void 0!==i&&{body:i}}),body:i,parsedBody:o,forwardRequest:s}}(r,a?.parsedBody,!0,o);if("unreadable-body"===l.step)return p1(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===l.step)return p1(413,-32e3,pW(o));if("no-json-body"===l.step)return void 0!==y?y(l.forwardRequest,{...void 0!==i&&{authInfo:i}}):p1(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:h,body:f,parsedBody:v,forwardRequest:_}=l;try{switch(h.kind){case"reject":return u(Error(`Rejected inbound request (${h.cell}): ${h.message}`)),p2(h,p0(f));case"modern":return await async function(r,a,i){var o,l;let h=r.classification.revision;if(void 0===h||!lW.includes(h)){let e=new cv({supported:[...lW],requested:h??"unknown"});return u(e),p1(400,e.code,e.message,e.data,p0(r.message))}let f=function(e,t){if("request"!==t.messageKind)return;let r=t.message.method;if(void 0===e.protocolVersionHeader){let e=t.classification.revision;return ur("version-header-missing","(missing)",void 0===e?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${e} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===e.mcpMethodHeader)return ur("method-header-missing","(missing)",`the body names method ${r} but the required Mcp-Method header is absent`,"standard-header-validation");let a=function(e,t){let r=Object.hasOwn(ua,e)?ua[e]:void 0;if(void 0===r)return;let a=un(t)?t[r]:void 0;return{field:r,value:"string"==typeof a?a:void 0}}(r,t.message.params);if(void 0===a)return;let{field:i,value:n}=a;if(void 0===e.mcpNameHeader){if(void 0===n)return;return ur("name-header-missing","(missing)",`the body carries params.${i}="${n}" but the required Mcp-Name header is absent`,"standard-header-validation")}let o=ui(e.mcpNameHeader),s=c6(o);return void 0===s?ur("name-header-invalid-encoding",o,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==n&&s!==n?ur("name-header-mismatch",o,`the body carries params.${i}="${n}" but the Mcp-Name header names "${s}"`,"standard-header-validation"):void 0}({httpMethod:a.method,...p5(a)},r);if(void 0!==f)return u(Error(`Rejected inbound request (${f.cell}): ${f.message}`)),p2(f,p0(r.message));let y="request"===r.messageKind?cU(r.message.params):void 0,v=y?.[nK];if("request"===r.messageKind){let e=Object.hasOwn(lJ,o=r.message.method)?lJ[o]:void 0;if(void 0!==e){let t=lK(e,v);if(void 0!==t){let e=new c_({requiredCapabilities:t});return u(e),p1(ue[e.code]??400,e.code,e.message,e.data,r.message.id)}}}let _=await e({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:a}),b=_ instanceof pz?_.server:_;if(p3(b),"request"===r.messageKind&&"subscriptions/listen"===r.message.method){let e=b.getCapabilities(),t=m(b);return _.close().catch(u),g.serve(r.message,a.signal,e,t)}if("request"===r.messageKind&&"tools/call"===r.message.method&&_ instanceof pz){let e=r.message.params,t="string"==typeof e?.name?e.name:void 0,i=void 0===t?void 0:_.toolInputSchemaJson(t);if(void 0!==i){let t=c1(i);if(void 0!==t.declarations&&t.declarations.length>0){let i=function(e,t,r){for(let a of e){let e=`Mcp-Param-${a.headerName}`,i=r.get(e),n=function(e,t){let r=e;for(let e of t){if(null===r||"object"!=typeof r)return;r=r[e]}return r}(t,a.path);if(null==n)continue;let o=function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e){if(!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return;return String(e)}}(n);if(void 0===o)continue;if(null===i)return c7("param-header-missing",e,`the body carries ${c4(a.path)}=${JSON.stringify(n)} but the ${e} header is absent`);let s=c6(i);if(void 0===s)return c7("param-header-invalid-encoding",e,`the ${e} header carries an invalid Base64 sentinel value`);if(!(("integer"===a.type||"number"===a.type)&&c5.test(s)&&"number"==typeof n?Number(s)===n:s===o))return c7("param-header-mismatch",e,`the ${e} header decodes to ${JSON.stringify(s)} but the body carries ${c4(a.path)}=${JSON.stringify(n)}`)}}(t.declarations,e?.arguments,a.headers);if(void 0!==i)return _.close().catch(u),u(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p2(i,r.message.id)}}}if("request"===r.messageKind&&_ instanceof pz)try{let e=await pT([r.message],i,e=>_.resolveScopeChallenge(e));if(void 0!==e)return _.close().catch(u),pO(e,pj(i))}catch(e){return _.close().catch(u),u(p9(e)),p4(r.message.id)}p3(b),c(b,h),p(b,lW),void 0!==y&&(l={clientInfo:y[nJ],clientCapabilities:v},d(b,l));let S=b.onclose;s.add(b);let $=()=>{s.delete(b),b.onclose===$&&(b.onclose=S),S?.()};b.onclose=$;try{let e=await async function(e,t,r){let a=new px({classification:r.classification,...void 0!==r.responseMode&&{responseMode:r.responseMode},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return await e.connect(a),a.handleMessage(t,{...void 0!==r.request&&{request:r.request},...void 0!==r.authInfo&&{authInfo:r.authInfo}})}(_,r.message,{classification:r.classification,request:a,...void 0!==i&&{authInfo:i},...void 0!==n&&{responseMode:n},...void 0!==t.keepAliveMs&&{keepAliveMs:t.keepAliveMs}});return"notification"===r.messageKind&&queueMicrotask(()=>void b.close().catch(()=>{})),e}catch(e){if(e instanceof lH&&e.code===lF.ConnectionClosed)return new Response(null,{status:499});return await b.close().catch(()=>{}),s.delete(b),u(p9(e)),p4(p0(r.message))}}(h,r,i);case"legacy":return await async function(e,t,r,a){if(void 0!==y)return y(t,{...void 0!==r&&{authInfo:r},...void 0!==a&&{parsedBody:a}});let i=function(e,t){switch(e.reason){case"http-method":return ut("http-method","modern-only-method-not-allowed",405,new cf(-32e3,"Method not allowed."),!0);case"batch":return ut("jsonrpc-shape","modern-only-batch-not-supported",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ut("jsonrpc-shape","modern-only-response-post",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return ut("era-classification","modern-only-missing-envelope",400,void 0===r?new cf(ch.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cv({supported:[...t],requested:r}),!0)}}}(e,lW);return void 0===i?new Response(null,{status:202}):(u(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p2(i,p0(a)))}(h,_,i,v)}}catch(e){return u(p9(e)),p4(p0(f))}}(r,a)}catch(e){return u(p9(e)),p4(p0(a?.parsedBody))}},notify:f,bus:h,close:async()=>{l=!0,g.closeAll();let e=[...s].map(e=>e.close().catch(()=>{}));s.clear(),await Promise.all(e)}}}(async function(){let e=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fT(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fT(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(fO);return fj(t),e}(),t=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw f_(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw f_(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(fC);return fb(t),e}(),a=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fS(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fS(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(fI);return f$(t),e}(),[i,n,o]=await Promise.all([e,t,a]),{instructions:s,...l}=fq,c=new pz(l,{instructions:s});return await async function(e,t,a,i){let n=await INJECTED_MIDDLEWARE?.(),o=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(n?.mcp),s="u">typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(e=e=>console.error(e)){let t=new Map,r=[];function a(t){try{e(JSON.stringify({"@timestamp":new Date().toISOString(),...t}))}catch{}}return{middleware:async(e,i)=>{let n,o,s;if("tools/call"!==e.method&&"prompts/get"!==e.method&&"resources/read"!==e.method)return i();try{o=performance.now(),n={log:{level:"info"},...function(e){let t=e.http?.headers.traceparent;if("string"!=typeof t)return{};let r=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/.exec(t);return!r||"ff"===r[1]||/^0+$/.test(r[2])||/^0+$/.test(r[3])||"00"===r[1]&&void 0!==r[5]?{}:{trace:{id:r[2]},parent:{id:r[3]}}}(e),transaction:{id:crypto.randomUUID()},...e.http?{http:{request:{id:e.http.id}}}:{},xmcp:{method:e.method,component:"resources/read"===e.method?function(e){try{let a=new URL(e).href;return t.get(a)??r.find(({template:e})=>e.uriTemplate.match(a))?.name??"unknown"}catch{return"unknown"}}(e.params.uri):e.params.name}}}catch{return i()}a({...n,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let l="unknown";try{let t=await i();try{l=e.signal.aborted?"cancelled":cY(t)?"input_required":"isError"in t&&!0===t.isError?"failure":"success","failure"===l&&(s={message:"Operation returned an error result"})}catch{}return t}catch(t){throw s={message:"cancelled"==(l=e.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},t}finally{try{a({...n,log:{level:"failure"===l?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-o)*1e6),outcome:"success"===l?"success":"failure"===l?"failure":"unknown"},xmcp:{...n.xmcp,status:l},...s?{error:s}:{}})}catch{}}},registerResource(e,a){try{"string"==typeof a?t.set(new URL(a).href,e):r.push({name:e,template:a})}catch{}}}}():void 0;s&&o.unshift(s.middleware),mu.clear();let l="u"<typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(e,t,r){let a=e.server,i=a.setRequestHandler,n=mM(t);a.setRequestHandler=(e,...t)=>{if(mL.has(e)&&1===t.length&&"function"==typeof t[0]){let e=t[0];t[0]=(t,r)=>n({method:t.method,params:t.params??{}},r,()=>e(t,r))}Reflect.apply(i,a,[e,...t])};try{r()}finally{a.setRequestHandler=i}}(e,o,()=>{var n,c;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c,u={name:fg(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(ff(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected Record<string, z.ZodType>`),null!=h)if(ff(h))o=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...mc(u)._meta};let g=mZ(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))fm.includes(e)?i[e]=t:fh.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mu.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=fp(v),b=y?_:void 0;s=mZ(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=mz(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mw(e,"Elicitation request must be a plain object."),m$(e,mf,"URL elicitation"),mR(e.message,"URL elicitation requires a string message."),mk(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mk(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){mw(e,"Elicitation request must be a plain object."),m$(e,mh,"Form elicitation"),mR(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mw(t,"Form elicitation requires a flat object schema."),m$(t,mg,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mw(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mw(t,`Form elicitation field "${e}" must be a plain object.`),mx(t.title,`Form elicitation field "${e}" title must be a string.`),mx(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(m$(t,mv,`Form elicitation field "${e}"`),mE(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mE(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mx(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){m$(t,my,`Form elicitation field "${e}"`),mP(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mP(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mx(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mx(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mS.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mS).join(", ")}.`);return}if("boolean"===t.type){if(m$(t,m_,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){m$(t,mb,`Form elicitation field "${e}"`),mP(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mP(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mP(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lH&&e.code===lF.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mC(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mj.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mT.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mC(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mC(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mO.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lH&&e.code===lF.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cY(l))return l;if("string"==typeof l||"number"==typeof l){if(r){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return mA(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(!r||!l||"object"!=typeof l||Array.isArray(l)||"structuredContent"in l||"content"in l&&Array.isArray(l.content)||"_meta"in l||"isError"in l||(mq(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(mA(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
93
|
+
`),b=!0;try{u?.()}catch(e){r?.(e instanceof Error?e:Error(String(e)))}void 0!==d&&clearInterval(d),p?.(),n.delete(w);try{c.close()}catch{}}},R=new ReadableStream({start(e){c=e;let r=pG({method:"notifications/subscriptions/acknowledged",params:{notifications:y}},v);($(r.method,r.params),0===Object.keys(y).length)?w(!0):(u=t.subscribe(e=>{if(b||!function(e,t){switch(t.kind){case"tools_list_changed":return!0===e.toolsListChanged;case"prompts_list_changed":return!0===e.promptsListChanged;case"resources_list_changed":return!0===e.resourcesListChanged;case"resource_updated":return void 0!==e.resourceSubscriptions&&e.resourceSubscriptions.includes(t.uri)}}(y,e))return;let t=pG(function(e){switch(e.kind){case"tools_list_changed":return{method:"notifications/tools/list_changed",...void 0!==e.params&&{params:e.params}};case"prompts_list_changed":return{method:"notifications/prompts/list_changed",...void 0!==e.params&&{params:e.params}};case"resources_list_changed":return{method:"notifications/resources/list_changed",...void 0!==e.params&&{params:e.params}};case"resource_updated":return{method:"notifications/resources/updated",params:{...e.params,uri:e.uri}}}}(e),v);$(t.method,t.params)}),d=pk(i,()=>S(": keepalive\n\n")),n.add(w))},cancel(){w(!1)}});if(void 0!==o)if(o.aborted)w(!1);else{let e=()=>w(!1);o.addEventListener("abort",e,{once:!0}),p=()=>o.removeEventListener("abort",e)}return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}})},closeAll(){for(let e of n)e(!0)},get openCount(){return n.size}}}({bus:h,maxSubscriptions:t.maxSubscriptions??1024,keepAliveMs:t.keepAliveMs??15e3,onerror:u});"json"===n&&console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");let y="reject"===a?void 0:(r=t.keepAliveMs,async(t,a)=>{if("POST"!==t.method.toUpperCase())return p1(405,-32e3,"Method not allowed.");try{let i=await e({era:"legacy",...a?.authInfo!==void 0&&{authInfo:a.authInfo},requestInfo:t}),n=new pQ({sessionIdGenerator:void 0,...void 0!==r&&{keepAliveMs:r},...void 0!==o&&{maxRequestBodySize:o}});await i.connect(n);let s=()=>{n.close().catch(()=>{}),i.close().catch(()=>{})};t.signal?.addEventListener("abort",s,{once:!0});let l=await n.handleRequest(t,{...a?.authInfo!==void 0&&{authInfo:a.authInfo},...a?.parsedBody!==void 0&&{parsedBody:a.parsedBody}});if(null===l.body||"text/event-stream"!==uq(l.headers.get("content-type")))return s(),l;let c=l.body.getReader(),u=!1,d=()=>{u||(u=!0,s())},p=new ReadableStream({pull:async e=>{try{let{done:t,value:r}=await c.read();if(t){d(),e.close();return}void 0!==r&&e.enqueue(r)}catch(t){d(),e.error(t)}},cancel:e=>(d(),c.cancel(e).catch(()=>{}))});return new Response(p,{status:l.status,statusText:l.statusText,headers:l.headers})}catch(e){try{u?.(p9(e))}catch{}return p4(p0(a?.parsedBody))}});return{fetch:async(r,a)=>{if(l)throw Error("This MCP handler has been closed");try{return await async function(r,a){let i=a?.authInfo;if("POST"===r.method.toUpperCase()&&!uA(r.headers.get("content-type")))return u(Error("Unsupported Media Type: Content-Type must be application/json")),p1(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let l=await async function(e,t,r=!0,a=4194304){let i,n=e.method.toUpperCase(),o=t,s=e,l=!1;if("POST"===n){if(void 0===o){let t;r&&(s=e.clone());try{let r=await pX(e,a);if(r.tooLarge)return{step:"body-too-large"};t=r.text}catch{return{step:"unreadable-body"}}try{i=0===t.length?void 0:JSON.parse(t)}catch{l=!0}l||void 0===i||(o=i)}else i=o;if(l||void 0===i)return{step:"no-json-body",forwardRequest:s}}return{step:"classified",outcome:function(e){if("POST"!==(e={...e,...void 0!==e.protocolVersionHeader&&{protocolVersionHeader:ui(e.protocolVersionHeader)},...void 0!==e.mcpMethodHeader&&{mcpMethodHeader:ui(e.mcpMethodHeader)},...void 0!==e.mcpNameHeader&&{mcpNameHeader:ui(e.mcpNameHeader)}}).httpMethod.toUpperCase())return{kind:"legacy",reason:"http-method"};let t=e.body;if(Array.isArray(t)){if(0===t.length)return ut("jsonrpc-shape","empty-batch",400,new cf(ch.InvalidRequest,"Bad Request: empty JSON-RPC batch"),!0);for(let e of t){if(cV(un(e)?e.params:void 0))return ut("jsonrpc-shape","batch-with-modern-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches may not contain requests for protocol revision 2026-07-28 or later"),!0);if(!(cB(e)||cK(e)||cG(e)||cW(e)))return ut("jsonrpc-shape","batch-with-invalid-element",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batch contains an invalid message"),!0)}return{kind:"legacy",reason:"batch"}}return cG(t)||cW(t)?{kind:"legacy",reason:"response"}:un(t)&&cB(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if("initialize"===a&&!function(e){if(!cV(e))return!1;let t=cF(e);if(void 0===t||!(t>=lG))return!1;let r=cU(e);return void 0!==r&&0===cH(r).length}(r)){if(n)return ur("initialize-with-modern-header",i,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let e=un(r)&&"string"==typeof r.protocolVersion?r.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(cV(r)){let n=cU(r),o=(void 0===n?[]:cH(n))[0];if(void 0!==o)return ut("envelope","envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${o.key}: ${o.problem}`,{envelope:o}),!0);let s=cF(r);return void 0!==i&&void 0!==s&&i!==s?ur("header-body-version-mismatch",i,`the body envelope names protocol version ${s} but the MCP-Protocol-Version header names ${i}`):void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("method-header-mismatch",e.mcpMethodHeader,`the body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"request",message:t,classification:uo(s)}}if(n){let e=cU(r),t=cH(e??{}).filter(e=>"missing"===e.problem).map(e=>e.key),a=void 0===e?["_meta"]:t.length>0?t:[nH];return ut("envelope","modern-header-without-claim",400,new cf(ch.InvalidParams,`Invalid params: the MCP-Protocol-Version header names protocol revision ${i}, but the request is missing the required per-request envelope key(s): ${a.join(", ")}`,{envelope:{missing:a}}),!0)}return{kind:"legacy",reason:"no-claim",...void 0!==i&&{requestedVersion:i}}}(e,t):un(t)&&cK(t)?function(e,t){let r=t.params,a=t.method,i=e.protocolVersionHeader,n=void 0!==i&&i>=lG;if(cV(r)){let n=cF(r);if(void 0===n){let e=cU(r),t=(void 0===e?[]:cH(e)).find(e=>e.key===nH)??{key:nH,problem:"expected a protocol version string"};return ut("envelope","notification-envelope-invalid",400,new cf(ch.InvalidParams,`Invalid _meta envelope for protocol revision 2026-07-28: ${t.key}: ${t.problem}`,{envelope:t}),!0)}if(void 0!==i&&i!==n)return ur("notification-header-body-version-mismatch",i,`the notification envelope names protocol version ${n} but the MCP-Protocol-Version header names ${i}`);let o=uo(n);return"modern"===o.era&&void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:o}}return n?void 0!==e.mcpMethodHeader&&e.mcpMethodHeader!==a?ur("notification-method-header-mismatch",e.mcpMethodHeader,`the notification body names method ${a} but the Mcp-Method header names ${e.mcpMethodHeader}`):{kind:"modern",messageKind:"notification",message:t,classification:{era:"modern",revision:i}}:{kind:"legacy",reason:"notification",...void 0!==i&&{requestedVersion:i}}}(e,t):ut("jsonrpc-shape","invalid-json-rpc-body",400,new cf(ch.InvalidRequest,"Bad Request: the request body is not a valid JSON-RPC message"),!0)}({httpMethod:n,...p5(e),...void 0!==i&&{body:i}}),body:i,parsedBody:o,forwardRequest:s}}(r,a?.parsedBody,!0,o);if("unreadable-body"===l.step)return p1(400,-32700,"Parse error: the request body could not be read");if("body-too-large"===l.step)return p1(413,-32e3,pW(o));if("no-json-body"===l.step)return void 0!==y?y(l.forwardRequest,{...void 0!==i&&{authInfo:i}}):p1(400,-32700,"Parse error: the request body is not valid JSON");let{outcome:h,body:f,parsedBody:v,forwardRequest:_}=l;try{switch(h.kind){case"reject":return u(Error(`Rejected inbound request (${h.cell}): ${h.message}`)),p2(h,p0(f));case"modern":return await async function(r,a,i){var o,l;let h=r.classification.revision;if(void 0===h||!lW.includes(h)){let e=new cv({supported:[...lW],requested:h??"unknown"});return u(e),p1(400,e.code,e.message,e.data,p0(r.message))}let f=function(e,t){if("request"!==t.messageKind)return;let r=t.message.method;if(void 0===e.protocolVersionHeader){let e=t.classification.revision;return ur("version-header-missing","(missing)",void 0===e?"the body carries a modern per-request envelope but the required MCP-Protocol-Version header is absent":`the body envelope names protocol version ${e} but the required MCP-Protocol-Version header is absent`,"standard-header-validation")}if(void 0===e.mcpMethodHeader)return ur("method-header-missing","(missing)",`the body names method ${r} but the required Mcp-Method header is absent`,"standard-header-validation");let a=function(e,t){let r=Object.hasOwn(ua,e)?ua[e]:void 0;if(void 0===r)return;let a=un(t)?t[r]:void 0;return{field:r,value:"string"==typeof a?a:void 0}}(r,t.message.params);if(void 0===a)return;let{field:i,value:n}=a;if(void 0===e.mcpNameHeader){if(void 0===n)return;return ur("name-header-missing","(missing)",`the body carries params.${i}="${n}" but the required Mcp-Name header is absent`,"standard-header-validation")}let o=ui(e.mcpNameHeader),s=c6(o);return void 0===s?ur("name-header-invalid-encoding",o,"the Mcp-Name header carries an invalid Base64 sentinel value","standard-header-validation"):void 0!==n&&s!==n?ur("name-header-mismatch",o,`the body carries params.${i}="${n}" but the Mcp-Name header names "${s}"`,"standard-header-validation"):void 0}({httpMethod:a.method,...p5(a)},r);if(void 0!==f)return u(Error(`Rejected inbound request (${f.cell}): ${f.message}`)),p2(f,p0(r.message));let y="request"===r.messageKind?cU(r.message.params):void 0,v=y?.[nK];if("request"===r.messageKind){let e=Object.hasOwn(lJ,o=r.message.method)?lJ[o]:void 0;if(void 0!==e){let t=lK(e,v);if(void 0!==t){let e=new c_({requiredCapabilities:t});return u(e),p1(ue[e.code]??400,e.code,e.message,e.data,r.message.id)}}}let _=await e({era:"modern",...void 0!==i&&{authInfo:i},requestInfo:a}),b=_ instanceof pz?_.server:_;if(p3(b),"request"===r.messageKind&&"subscriptions/listen"===r.message.method){let e=b.getCapabilities(),t=m(b);return _.close().catch(u),g.serve(r.message,a.signal,e,t)}if("request"===r.messageKind&&"tools/call"===r.message.method&&_ instanceof pz){let e=r.message.params,t="string"==typeof e?.name?e.name:void 0,i=void 0===t?void 0:_.toolInputSchemaJson(t);if(void 0!==i){let t=c1(i);if(void 0!==t.declarations&&t.declarations.length>0){let i=function(e,t,r){for(let a of e){let e=`Mcp-Param-${a.headerName}`,i=r.get(e),n=function(e,t){let r=e;for(let e of t){if(null===r||"object"!=typeof r)return;r=r[e]}return r}(t,a.path);if(null==n)continue;let o=function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e){if(!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return;return String(e)}}(n);if(void 0===o)continue;if(null===i)return c7("param-header-missing",e,`the body carries ${c4(a.path)}=${JSON.stringify(n)} but the ${e} header is absent`);let s=c6(i);if(void 0===s)return c7("param-header-invalid-encoding",e,`the ${e} header carries an invalid Base64 sentinel value`);if(!(("integer"===a.type||"number"===a.type)&&c5.test(s)&&"number"==typeof n?Number(s)===n:s===o))return c7("param-header-mismatch",e,`the ${e} header decodes to ${JSON.stringify(s)} but the body carries ${c4(a.path)}=${JSON.stringify(n)}`)}}(t.declarations,e?.arguments,a.headers);if(void 0!==i)return _.close().catch(u),u(Error(`Rejected inbound request (${i.cell}): ${i.message}`)),p2(i,r.message.id)}}}if("request"===r.messageKind&&_ instanceof pz)try{let e=await pT([r.message],i,e=>_.resolveScopeChallenge(e));if(void 0!==e)return _.close().catch(u),pO(e,pj(i))}catch(e){return _.close().catch(u),u(p9(e)),p4(r.message.id)}p3(b),c(b,h),p(b,lW),void 0!==y&&(l={clientInfo:y[nJ],clientCapabilities:v},d(b,l));let S=b.onclose;s.add(b);let $=()=>{s.delete(b),b.onclose===$&&(b.onclose=S),S?.()};b.onclose=$;try{let e=await async function(e,t,r){let a=new px({classification:r.classification,...void 0!==r.responseMode&&{responseMode:r.responseMode},...void 0!==r.keepAliveMs&&{keepAliveMs:r.keepAliveMs}});return await e.connect(a),a.handleMessage(t,{...void 0!==r.request&&{request:r.request},...void 0!==r.authInfo&&{authInfo:r.authInfo}})}(_,r.message,{classification:r.classification,request:a,...void 0!==i&&{authInfo:i},...void 0!==n&&{responseMode:n},...void 0!==t.keepAliveMs&&{keepAliveMs:t.keepAliveMs}});return"notification"===r.messageKind&&queueMicrotask(()=>void b.close().catch(()=>{})),e}catch(e){if(e instanceof lH&&e.code===lF.ConnectionClosed)return new Response(null,{status:499});return await b.close().catch(()=>{}),s.delete(b),u(p9(e)),p4(p0(r.message))}}(h,r,i);case"legacy":return await async function(e,t,r,a){if(void 0!==y)return y(t,{...void 0!==r&&{authInfo:r},...void 0!==a&&{parsedBody:a}});let i=function(e,t){switch(e.reason){case"http-method":return ut("http-method","modern-only-method-not-allowed",405,new cf(-32e3,"Method not allowed."),!0);case"batch":return ut("jsonrpc-shape","modern-only-batch-not-supported",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return ut("jsonrpc-shape","modern-only-response-post",400,new cf(ch.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return ut("era-classification","modern-only-missing-envelope",400,void 0===r?new cf(ch.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cv({supported:[...t],requested:r}),!0)}}}(e,lW);return void 0===i?new Response(null,{status:202}):(u(Error(`Rejected 2025-era request on a modern-only endpoint (${i.cell}): ${i.message}`)),p2(i,p0(a)))}(h,_,i,v)}}catch(e){return u(p9(e)),p4(p0(f))}}(r,a)}catch(e){return u(p9(e)),p4(p0(a?.parsedBody))}},notify:f,bus:h,close:async()=>{l=!0,g.closeAll();let e=[...s].map(e=>e.close().catch(()=>{}));s.clear(),await Promise.all(e)}}}(async function(){let e=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fL(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fL(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(fD);return fZ(t),e}(),t=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fT(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fT(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(fU);return fj(t),e}(),a=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fO(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fO(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(fV);return fC(t),e}(),[i,n,o]=await Promise.all([e,t,a]),s=function(){let{instructions:e,...t}=fH;return new pz(t,{instructions:e,cacheHints:"u"<typeof CACHE_HINTS_CONFIG?void 0:CACHE_HINTS_CONFIG})}();return await async function(e,t,a,i){let n=await INJECTED_MIDDLEWARE?.(),o=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(n?.mcp),s=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(n?.authorize),l="u">typeof OBSERVABILITY_CONFIG&&OBSERVABILITY_CONFIG.enabled?function(e=e=>console.error(e)){let t=new Map,r=[];function a(t){try{e(JSON.stringify({"@timestamp":new Date().toISOString(),...t}))}catch{}}return{middleware:async(e,i)=>{let n,o,s;if("tools/call"!==e.method&&"prompts/get"!==e.method&&"resources/read"!==e.method)return i();try{o=performance.now(),n={log:{level:"info"},...fE(e._meta?.traceparent)??fE(e.http?.headers.traceparent)??{},transaction:{id:crypto.randomUUID()},...e.http?{http:{request:{id:e.http.id}}}:{},xmcp:{method:e.method,component:"resources/read"===e.method?function(e){try{let a=new URL(e).href;return t.get(a)??r.find(({template:e})=>e.uriTemplate.match(a))?.name??"unknown"}catch{return"unknown"}}(e.params.uri):e.params.name}}}catch{return i()}a({...n,event:{kind:"event",category:["api"],type:["start"],action:"execution.start"}});let l="unknown";try{let t=await i();try{l=e.signal.aborted?"cancelled":cY(t)?"input_required":"isError"in t&&!0===t.isError?"failure":"success","failure"===l&&(s={message:"Operation returned an error result"})}catch{}return t}catch(t){throw s={message:"cancelled"==(l=e.signal.aborted?"cancelled":"failure")?"Operation cancelled":"Operation threw an exception"},t}finally{try{a({...n,log:{level:"failure"===l?"error":"info"},event:{kind:"event",category:["api"],type:["end"],action:"execution.end",duration:Math.round((performance.now()-o)*1e6),outcome:"success"===l?"success":"failure"===l?"failure":"unknown"},xmcp:{...n.xmcp,status:l},...s?{error:s}:{}})}catch{}}},registerResource(e,a){try{"string"==typeof a?t.set(new URL(a).href,e):r.push({name:e,template:a})}catch{}}}}():void 0;l&&o.unshift(l.middleware),mu.clear();let c="u"<typeof COMPONENTS_CONFIG?void 0:COMPONENTS_CONFIG;return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,o=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,s=a&&o?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new cf(ch.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new cf(ch.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,mf(t,a),"read"))throw new cg(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new cf(ch.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>mf(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,o):void 0,l=fy(s?[s,...t]:t),c=s?fy([s]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];f_.has(e)?t[0]=(e,t)=>l({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&c&&o&&(t[0]=(e,t)=>{let a=o.tools.get(e.params.name);return a?c({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(o){let t=async(e,t,r)=>{let i=o.resources.get(t);return!i||await a(e,i,r)===!0},i={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(t,r,...a)=>{let n=fv({name:t,description:r.description??"",annotations:r.annotations,icons:r.icons,tags:mh(r._meta),_meta:r._meta});return o.tools.set(t,Object.freeze({type:"tool",name:t,metadata:n})),Reflect.apply(i.registerTool,e,[t,r,...a])},e.registerPrompt=(t,r,...a)=>{let n=fv({name:t,title:r.title,description:r.description,icons:r.icons,tags:mh(r._meta),_meta:r._meta});return o.prompts.set(t,Object.freeze({type:"prompt",name:t,metadata:n})),Reflect.apply(i.registerPrompt,e,[t,r,...a])},e.registerResource=(t,r,a,...n)=>{let s=fv({name:t,title:a.title,description:a.description,icons:a.icons,mimeType:a.mimeType,tags:mh(a._meta),_meta:a._meta});if("string"==typeof r)o.resources.set(r,Object.freeze({type:"resource",name:t,uri:r,metadata:s}));else{let e=r.uriTemplate.toString();o.templates.set(t,{component:Object.freeze({type:"resourceTemplate",name:t,uriTemplate:e,metadata:s}),template:r})}return Reflect.apply(i.registerResource,e,[t,r,a,...n])};try{r(t)}finally{Object.assign(e,i)}for(let[e,t]of mu.getAll()){let r=o.tools.get(e);r&&o.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,o,n=>{var s,u;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c,u={name:fk(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(fc(m)?(!function(e,t){let{type:r}=fu(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,u.name),f=m):fR(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=h)if(fc(h))o=h;else if(fR(h))o=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...mc(u)._meta};let g=fb(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))f$.includes(e)?i[e]=t:fw.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mu.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=fS(v),b=y?_:void 0;s=fb(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=fg(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mP(e,"Elicitation request must be a plain object."),mx(e,m_,"URL elicitation"),mE(e.message,"URL elicitation requires a string message."),mT(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mT(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){mP(e,"Elicitation request must be a plain object."),mx(e,mv,"Form elicitation"),mE(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mP(t,"Form elicitation requires a flat object schema."),mx(t,mb,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mP(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mP(t,`Form elicitation field "${e}" must be a plain object.`),mj(t.title,`Form elicitation field "${e}" title must be a string.`),mj(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(mx(t,m$,`Form elicitation field "${e}"`),mC(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mC(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mj(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){mx(t,mS,`Form elicitation field "${e}"`),mO(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mO(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mj(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mj(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mk.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mk).join(", ")}.`);return}if("boolean"===t.type){if(mx(t,mw,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){mx(t,mR,`Form elicitation field "${e}"`),mO(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mO(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mO(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lH&&e.code===lF.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mA(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mN.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mI.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mA(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mA(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mq.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lH&&e.code===lF.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cY(l))return l;if(r&&fc(r)&&void 0!==l&&!fh(l)){if(await fm(l,r,a,"returned data that does not match outputSchema"),"string"==typeof l||"number"==typeof l)return{content:[{type:"text",text:`${l}`}],structuredContent:l};l={structuredContent:l}}if("string"==typeof l||"number"==typeof l){if(r&&!fc(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return ff(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(r&&l&&"object"==typeof l&&!Array.isArray(l)&&!fh(l)&&(await fm(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(ff(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
94
94
|
|
|
95
95
|
Expected CallToolResult format:
|
|
96
96
|
{
|
|
@@ -119,7 +119,7 @@ Or for widget metadata only:
|
|
|
119
119
|
_meta: {
|
|
120
120
|
"ui/...": ...
|
|
121
121
|
}
|
|
122
|
-
}`)}let c="content"in l&&Array.isArray(l.content),u="structuredContent"in l,d="isError"in l&&!0===l.isError;if(!c&&!u&&!d){let e=JSON.stringify(l,null,2);throw Error(`Tool handler must return at least 'content' or 'structuredContent'. Got: ${e}
|
|
122
|
+
}`)}let c="content"in l&&Array.isArray(l.content),u="structuredContent"in l&&void 0!==l.structuredContent,d="isError"in l&&!0===l.isError;if(!c&&!u&&!d){let e=JSON.stringify(l,null,2);throw Error(`Tool handler must return at least 'content' or 'structuredContent'. Got: ${e}
|
|
123
123
|
|
|
124
124
|
Expected CallToolResult format:
|
|
125
125
|
{
|
|
@@ -140,7 +140,7 @@ Or both for backwards compatibility:
|
|
|
140
140
|
{
|
|
141
141
|
content: [{ type: "text", text: "fallback" }],
|
|
142
142
|
structuredContent: { your: "data" }
|
|
143
|
-
}`)}if(d&&!c&&!u){let{isError:e,...t}=l,r=Object.keys(t).length>0?`Tool execution failed: ${JSON.stringify(t)}`:"Tool execution failed";l.content=[{type:"text",text:r}],c=!0}if(r&&u&&!d&&
|
|
143
|
+
}`)}if(d&&!c&&!u){let{isError:e,...t}=l,r=Object.keys(t).length>0?`Tool execution failed: ${JSON.stringify(t)}`:"Tool execution failed";l.content=[{type:"text",text:r}],c=!0}if(r&&u&&!d&&await fm(l.structuredContent,r,a,"returned structuredContent that does not match outputSchema"),!c&&u&&(l.content=[{type:"text",text:JSON.stringify(l.structuredContent)}],c=!0),c)for(let e=0;e<l.content.length;e++){let t=l.content[e],r=mM(t);if(!r.valid)throw Error(`Invalid content item at index ${e}: ${r.error}
|
|
144
144
|
|
|
145
145
|
Content item: ${JSON.stringify(t,null,2)}
|
|
146
146
|
|
|
@@ -149,15 +149,7 @@ Expected content formats:
|
|
|
149
149
|
- Image: { type: "image", data: "base64data", mimeType: "image/jpeg" }
|
|
150
150
|
- Audio: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
|
|
151
151
|
- Resource: { type: "resource_link", name: "name", uri: "uri" }
|
|
152
|
-
All content types support an optional "_meta" object property`)}
|
|
153
|
-
|
|
154
|
-
Expected format:
|
|
155
|
-
{
|
|
156
|
-
structuredContent: {
|
|
157
|
-
key: "value",
|
|
158
|
-
nested: { data: "here" }
|
|
159
|
-
}
|
|
160
|
-
}`)}}return l}}(d,b,o,u.name);let S={title:u.annotations?.title,description:u.description,inputSchema:fd(f),outputSchema:o?fd(o,{strict:!0}):void 0,annotations:u.annotations,icons:u.icons,_meta:_};e.registerTool(u.name,S,(n={name:u.name,description:S.description,annotations:S.annotations,icons:S.icons,tags:u.tags,_meta:S._meta},l=mM(r),c=Object.freeze({metadata:function e(t,r=new WeakMap){if(null===t||"object"!=typeof t)return t;let a=Object.getPrototypeOf(t);if(!Array.isArray(t)&&a!==Object.prototype&&null!==a)return t;if(r.has(t))return r.get(t);let i=Array.isArray(t)?[]:Object.create(a);for(let[a,n]of(r.set(t,i),Object.entries(t)))Object.defineProperty(i,a,{value:e(n,r),enumerable:!0,configurable:!0,writable:!0});return Object.freeze(i)}(n)}),(e,t)=>l({method:"tools/call",params:{name:c.metadata.name,arguments:e},tool:c},t,()=>s(e,t))))})}(e,fv(t,l),o),fv(a,l).forEach((t,r)=>{let a=fg(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;if("object"==typeof s&&null!==s&&Object.assign(i,s),!1===i.enabled)return;let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await uR.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mN(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
|
|
152
|
+
All content types support an optional "_meta" object property`)}return l}}(d,b,o,u.name);let S={title:u.annotations?.title,description:u.description,inputSchema:fp(f),outputSchema:o?fp(o,{strict:!0}):void 0,annotations:u.annotations,icons:u.icons,_meta:_};e.registerTool(u.name,S,(n={name:u.name,description:S.description,annotations:S.annotations,icons:S.icons,tags:u.tags,_meta:S._meta},l=fy(r,!0),c=Object.freeze({metadata:fv(n)}),(e,t)=>l({method:"tools/call",params:{name:c.metadata.name,arguments:e},tool:c},t,()=>s(e,t))))})}(e,fP(t,c),o),fP(a,c).forEach((t,r)=>{let a=fk(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;if("object"==typeof s&&null!==s&&Object.assign(i,s),!1===i.enabled)return;let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await uR.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mM(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
|
|
161
153
|
|
|
162
154
|
Validation error: ${e.error}
|
|
163
155
|
|
|
@@ -170,7 +162,7 @@ Expected formats:
|
|
|
170
162
|
- Image content: { type: "image", data: "base64data", mimeType: "image/jpeg" }
|
|
171
163
|
- Audio content: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
|
|
172
164
|
- Resource link: { type: "resource_link", name: "resource name", uri: "resource://uri" }
|
|
173
|
-
- All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");
|
|
165
|
+
- All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");fR(l)?Object.assign(n,l):null!=l&&console.warn(`Invalid schema for prompt "${i.name}" at ${r}. Expected Record<string, z.ZodType>`),e.registerPrompt(i.name,{title:i.title,description:i.description,icons:i.icons,_meta:mc(i)._meta,argsSchema:fd(n)},c)}),s=fP(i,c),u=l?.registerResource,[...mu.getAll()].forEach(([t,a])=>{let i=a.mimeType||"text/html;profile=mcp-app",n=a?._meta?fS(a._meta):void 0,o={name:a.name,description:`Auto-generated resource for ${a.name} tool`,mimeType:a.mimeType,_meta:n};u?.(a.name,a.uri),e.registerResource(a.name,a.uri,o,async(e,t)=>{if(a.mimeType&&a.toolPath)try{var n;let e,t,o=(n=a.toolPath,IS_CLOUDFLARE?function(e){let{normalizedPath:t,baseName:r}=fI(e),a=5381;for(let e=0;e<t.length;e++)a=Math.imul(a,33)+t.charCodeAt(e)>>>0;let i=a.toString(16).slice(0,6).padStart(6,"0");return`${r}_${i}`}(n):function(e){let{normalizedPath:t,baseName:a}=fI(e),i=r(6982).createHash("md5").update(t).digest("hex").slice(0,6);return`${a}_${i}`}(n)),s=function(e){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[e]||null;if(!IS_CLOUDFLARE)try{let t=r(9896),a=r(6928);for(let r of[a.join(process.cwd(),"dist","client"),a.join(process.cwd(),"client")]){let i=a.join(r,`${e}.bundle.js`),n=a.join(r,`${e}.bundle.css`);if(t.existsSync(i)){let e,r=t.readFileSync(i,"utf-8");return t.existsSync(n)&&(e=t.readFileSync(n,"utf-8")),{js:r,css:e}}}}catch{}return null}(o);if(!s)throw Error(`React client bundle not found for "${a.name}" (bundle: "${o}").
|
|
174
166
|
React tool bundles are generated automatically when you run "xmcp build" (or "xmcp dev").
|
|
175
167
|
Please re-run the build so the framework can regenerate the bundle.`);let l=s.js,c=s.css,u=(e=`
|
|
176
168
|
<script type="module">
|
|
@@ -225,7 +217,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
|
|
|
225
217
|
<div id="root"></div>
|
|
226
218
|
${e}
|
|
227
219
|
</body>
|
|
228
|
-
</html>`);return{contents:[{uri:a.uri,text:u,mimeType:i,_meta:a._meta}]}}catch(e){throw console.error(`React failed for ${a.name}:`,e),e}let o=a.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:a.uri,text:o,mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:a.uri,text:e.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}})}),
|
|
220
|
+
</html>`);return{contents:[{uri:a.uri,text:u,mimeType:i,_meta:a._meta}]}}catch(e){throw console.error(`React failed for ${a.name}:`,e),e}let o=a.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:a.uri,text:o,mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:a.uri,text:e.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}})}),s.forEach((t,r)=>{let a={name:fk(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;if("object"==typeof n&&null!==n&&Object.assign(a,n),!1===a.enabled)return;let l={};fR(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=fN(r);if(!c)return void console.warn(`Skipping resource "${a.name}" at ${r}: Invalid file path format`);let d=c.uriTemplate;a.mimeType&&a.mimeType.includes("html")&&(d=d.endsWith(".html")?d:`${d}.html`);let p=function(e,t,r={}){let a=fN(t);if(!a)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,r){let a={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),l=o.split("/");for(let e=0;e<s.length&&e<l.length;e++){let t=s[e],r=l[e],i=t.match(/^\{(.+)\}$/);i&&(a[i[1]]=r)}for(let e of t.parameters){let t=a[e],n=r[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(r){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${r instanceof Error?r.message:String(r)}`)}}return i}(t.href,a,r),i);if(n instanceof Promise&&(n=await n),cY(n))return n;if("string"==typeof n)return{contents:[{uri:t.href,text:n}]};if(!n||"object"!=typeof n||!Array.isArray(n.contents)){let e=null===n?"null":typeof n,t=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Resource handler must return a ReadResourceResult, InputRequiredResult, or string. Got ${e}: ${t}
|
|
229
221
|
|
|
230
222
|
Expected ReadResourceResult format:
|
|
231
223
|
{
|
|
@@ -234,4 +226,4 @@ Expected ReadResourceResult format:
|
|
|
234
226
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
235
227
|
{ uri: "resource://uri", blob: base64data }
|
|
236
228
|
]
|
|
237
|
-
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===
|
|
229
|
+
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)u?.(a.name,d),e.registerResource(a.name,d,mc(a),p);else{let t=Object.create(null);for(let e of c.parameters)s&&Object.hasOwn(s,e)&&(t[e]=s[e]);let r=new pM(d,{list:void 0,complete:t});u?.(a.name,r),e.registerResource(a.name,r,mc(a),async(e,t,r)=>{let a={};for(let e of c.parameters){let r=t[e],i=l[e];if(void 0===r)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?a[e]=i.parse(r):a[e]=r}let n=i(a,r);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n})}}),function(e,t,r,a,i){let n=[...fP(new Map(t.map(e=>[e.uri,{metadata:{name:e.frontmatter.name},skill:e}])),r).values()].map(({skill:e})=>e);if(0===n.length)return;for(let{frontmatter:t,files:r}of n){let i=r[0].uri.slice(0,r[0].uri.lastIndexOf("/")+1);r.forEach(({uri:r,mimeType:n,text:o,blob:s},l)=>{let c=0===l?{mimeType:n,description:t.description}:{mimeType:n},u=0===l?t.name:`${t.name}/${decodeURIComponent(r.slice(i.length))}`,d=void 0!==o?{uri:r,mimeType:n,text:o}:{uri:r,mimeType:n,blob:s??""};a?.(u,r),e.registerResource(u,r,c,()=>({contents:[d]}))})}let o=n.map(fM),s=new Map(o.map(e=>[e.uri,e]));e.server.registerCapabilities({extensions:{"io.modelcontextprotocol/skills":{}}}),e.server.setRequestHandler("skills/list",{params:fA},(e,t)=>mm(t,fg(t),async()=>{let t=Object.freeze({...mp(),method:"skills/list",params:Object.freeze({...e})}),r=i?await Promise.all(o.map(e=>i(t,e.uri,"list"))):void 0,a=r?o.filter((e,t)=>r[t]):o,n=e?.cursor===void 0?0:function(e,t){let r=0/0;try{r=Number(atob(e))}catch{}if(!Number.isSafeInteger(r)||r<=0||r>=t)throw new cf(ch.InvalidParams,`Invalid cursor: ${e}`);return r}(e.cursor,a.length),s=n+50;return{skills:a.slice(n,s),...s<a.length?{nextCursor:btoa(String(s))}:{},...fq}})),e.server.setRequestHandler("skills/get",{params:fz},(e,t)=>mm(t,fg(t),async()=>{let{uri:t}=e,r=s.get(t),a=Object.freeze({...mp(),method:"skills/get",params:Object.freeze({...e})});if(!r||i&&!await i(a,t,"read"))throw new cf(ch.InvalidParams,`No skill is served at ${t}`);return{skill:r,...fq}}))}(e,fF,c,l?.registerResource,n)},s),e}(s,i,n,o),s},{legacy:"stateless",maxSubscriptions:HTTP_CONFIG.maxSubscriptions});async function fX(e){return mi({id:(0,R.randomUUID)(),headers:Object.fromEntries(e.headers.entries()),clientInfo:void 0},async()=>{try{let t;return"POST"===e.method&&(t=await e.json().catch(()=>void 0),mr({clientInfo:(e=>{for(let t of Array.isArray(e)?e:[e]){let e=ms(t);if(e)return e}})(t)})),await fY.fetch(e,{authInfo:e.auth,parsedBody:t})}catch(e){return console.error("[Next.js MCP] Error handling MCP request:",e),Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null},{status:500})}})}function fQ(e){let t=new URL(e.url),r=t.hostname.split(".").reverse().join("."),a={$schema:"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",name:`${r}/mcp`,version:SERVER_INFO.version,description:TEMPLATE_CONFIG.description,title:TEMPLATE_CONFIG.name,remotes:[{type:"streamable-http",url:`${t.origin}${HTTP_CONFIG.endpoint}`}]};return TEMPLATE_CONFIG.icons?.length&&(a.icons=TEMPLATE_CONFIG.icons),Response.json(a,{headers:{"Content-Type":"application/mcp-server-card+json","Cache-Control":"public, max-age=3600, must-revalidate","Access-Control-Allow-Origin":"*"}})}})(),a})());
|