@wp-playground/mcp 3.1.39 → 3.1.41
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/README.md +31 -2
- package/bridge-server.d.ts +3 -0
- package/client.cjs +1 -1
- package/client.cjs.map +1 -1
- package/client.js +45 -45
- package/client.js.map +1 -1
- package/index.cjs +17 -17
- package/index.cjs.map +1 -1
- package/index.js +2564 -2543
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/{tool-executors-CnK8qvl5.cjs → tool-executors-DX_lR1Jc.cjs} +46 -9
- package/tool-executors-DX_lR1Jc.cjs.map +1 -0
- package/{tool-executors-SsQekZdW.js → tool-executors-DeiRNg9-.js} +100 -63
- package/tool-executors-DeiRNg9-.js.map +1 -0
- package/tools/register-mcp-server-tools.d.ts +1 -1
- package/tools/tool-definitions.d.ts +2 -2
- package/tool-executors-CnK8qvl5.cjs.map +0 -1
- package/tool-executors-SsQekZdW.js.map +0 -1
package/index.cjs
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
"use strict";const $r=require("node:process"),oo=require("ws"),ao=require("node:http"),co=require("node:crypto"),Qe=require("./tool-executors-CnK8qvl5.cjs"),zs=require("ajv"),uo=require("zod"),lo=require("module");var yn=typeof document<"u"?document.currentScript:null;function _(t,e,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const u=o.prototype,l=Object.keys(u);for(let d=0;d<l.length;d++){const p=l[d];p in a||(a[p]=u[p].bind(a))}}const s=(n==null?void 0:n.Parent)??Object;class i extends s{}Object.defineProperty(i,"name",{value:t});function o(a){var c;const u=n!=null&&n.Parent?new i:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,u;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(u=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:u.has(t)}}),Object.defineProperty(o,"name",{value:t}),o}class it extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class $s extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ps={};function Fe(t){return Ps}function Rs(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,s])=>e.indexOf(+r)===-1).map(([r,s])=>s)}function $n(t,e){return typeof e=="bigint"?e.toString():e}function an(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Gn(t){return t==null}function Kn(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function fo(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let s=(r.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c!=null&&c[1]&&(s=Number.parseInt(c[1]))}const i=n>s?n:s,o=Number.parseInt(t.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return o%a/10**i}const Pr=Symbol("evaluating");function B(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==Pr)return r===void 0&&(r=Pr,r=n()),r},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function et(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function He(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function Rr(t){return JSON.stringify(t)}function ho(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Ns="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function kt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const mo=an(()=>{var t;if(typeof navigator<"u"&&((t=navigator==null?void 0:navigator.userAgent)!=null&&t.includes("Cloudflare")))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function ot(t){if(kt(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(kt(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Es(t){return ot(t)?{...t}:Array.isArray(t)?[...t]:t}const po=new Set(["string","number","symbol"]);function at(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Me(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n!=null&&n.parent)&&(r._zod.parent=t),r}function N(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if((e==null?void 0:e.message)!==void 0){if((e==null?void 0:e.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function go(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const _o={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function yo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(o[a]=n.shape[a])}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function vo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={...t._zod.def.shape};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete o[a]}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function bo(t,e){if(!ot(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const i=t._zod.def.shape;for(const o in e)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=He(t._zod.def,{get shape(){const i={...t._zod.def.shape,...e};return et(this,"shape",i),i}});return Me(t,s)}function wo(t,e){if(!ot(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return et(this,"shape",r),r}});return Me(t,n)}function ko(t,e){const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return et(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return Me(t,n)}function So(t,e,n){const s=e._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=He(e._zod.def,{get shape(){const a=e._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=t?new t({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=t?new t({type:"optional",innerType:a[u]}):a[u];return et(this,"shape",c),c},checks:[]});return Me(e,o)}function To(t,e,n){const r=He(e._zod.def,{get shape(){const s=e._zod.def.shape,i={...s};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)i[o]=new t({type:"nonoptional",innerType:s[o]});return et(this,"shape",i),i}});return Me(e,r)}function nt(t,e=0){var n;if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(((n=t.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function rt(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function At(t){return typeof t=="string"?t:t==null?void 0:t.message}function Ue(t,e,n){var s,i,o,a,c,u;const r={...t,path:t.path??[]};if(!t.message){const l=At((o=(i=(s=t.inst)==null?void 0:s._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,t))??At((a=e==null?void 0:e.error)==null?void 0:a.call(e,t))??At((c=n.customError)==null?void 0:c.call(n,t))??At((u=n.localeError)==null?void 0:u.call(n,t))??"Invalid input";r.message=l}return delete r.inst,delete r.continue,e!=null&&e.reportInput||delete r.input,r}function Yn(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function St(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Cs=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,$n,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Is=_("$ZodError",Cs),cn=_("$ZodError",Cs,{Parent:Error});function zo(t,e=n=>n.message){const n={},r=[];for(const s of t.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:n}}function $o(t,e=n=>n.message){const n={_errors:[]},r=s=>{for(const i of s.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>r({issues:o}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(e(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(t),n}const un=t=>(e,n,r,s)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new it;if(o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Ns(a,s==null?void 0:s.callee),a}return o.value},Po=un(cn),ln=t=>async(e,n,r,s)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Ns(a,s==null?void 0:s.callee),a}return o.value},Ro=ln(cn),dn=t=>(e,n,r)=>{const s=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new it;return i.issues.length?{success:!1,error:new(t??Is)(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},Qn=dn(cn),fn=t=>async(e,n,r)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=e._zod.run({value:n,issues:[]},s);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new t(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},Xn=fn(cn),No=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return un(t)(e,n,s)},Eo=t=>(e,n,r)=>un(t)(e,n,r),Co=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ln(t)(e,n,s)},Io=t=>async(e,n,r)=>ln(t)(e,n,r),Oo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return dn(t)(e,n,s)},xo=t=>(e,n,r)=>dn(t)(e,n,r),Zo=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return fn(t)(e,n,s)},Ao=t=>async(e,n,r)=>fn(t)(e,n,r),jo=/^[cC][^\s-]{8,}$/,Mo=/^[0-9a-z]+$/,Lo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Do=/^[0-9a-vA-V]{20}$/,qo=/^[A-Za-z0-9]{27}$/,Fo=/^[a-zA-Z0-9_-]{21}$/,Uo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Vo=/^([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})$/,Nr=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Ho=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Jo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Bo(){return new RegExp(Jo,"u")}const Wo=/^(?:(?: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])$/,Go=/^(([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}|:))$/,Ko=/^((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])$/,Yo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Qo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Os=/^[A-Za-z0-9_-]*$/,Xo=/^\+[1-9]\d{6,14}$/,xs="(?:(?:\\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])))",ea=new RegExp(`^${xs}$`);function Zs(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function ta(t){return new RegExp(`^${Zs(t)}$`)}function na(t){const e=Zs({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${xs}T(?:${r})$`)}const ra=t=>{const e=t?`[\\s\\S]{${(t==null?void 0:t.minimum)??0},${(t==null?void 0:t.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},sa=/^-?\d+$/,As=/^-?\d+(?:\.\d+)?$/,ia=/^(?:true|false)$/i,oa=/^null$/i,aa=/^[^A-Z]*$/,ca=/^[^a-z]*$/,Se=_("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),js={number:"number",bigint:"bigint",object:"date"},Ms=_("$ZodCheckLessThan",(t,e)=>{Se.init(t,e);const n=js[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<i&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Ls=_("$ZodCheckGreaterThan",(t,e)=>{Se.init(t,e);const n=js[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>i&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),ua=_("$ZodCheckMultipleOf",(t,e)=>{Se.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):fo(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),la=_("$ZodCheckNumberFormat",(t,e)=>{var o;Se.init(t,e),e.format=e.format||"float64";const n=(o=e.format)==null?void 0:o.includes("int"),r=n?"int":"number",[s,i]=_o[e.format];t._zod.onattach.push(a=>{const c=a._zod.bag;c.format=e.format,c.minimum=s,c.maximum=i,n&&(c.pattern=sa)}),t._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}c<s&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:t,continue:!e.abort})}}),da=_("$ZodCheckMaxLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Gn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const s=r.value;if(s.length<=e.maximum)return;const o=Yn(s);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),fa=_("$ZodCheckMinLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Gn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const s=r.value;if(s.length>=e.minimum)return;const o=Yn(s);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ha=_("$ZodCheckLengthEquals",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Gn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=r=>{const s=r.value,i=s.length;if(i===e.length)return;const o=Yn(s),a=i>e.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),hn=_("$ZodCheckStringFormat",(t,e)=>{var n,r;Se.init(t,e),t._zod.onattach.push(s=>{const i=s._zod.bag;i.format=e.format,e.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),ma=_("$ZodCheckRegex",(t,e)=>{hn.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),pa=_("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=aa),hn.init(t,e)}),ga=_("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=ca),hn.init(t,e)}),_a=_("$ZodCheckIncludes",(t,e)=>{Se.init(t,e);const n=at(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(s=>{const i=s._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),ya=_("$ZodCheckStartsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`^${at(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),va=_("$ZodCheckEndsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`.*${at(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),ba=_("$ZodCheckOverwrite",(t,e)=>{Se.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class wa{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
|
|
1
|
+
"use strict";const Rr=require("node:process"),ao=require("ws"),co=require("node:http"),uo=require("node:crypto"),Qe=require("./tool-executors-DX_lR1Jc.cjs"),$s=require("ajv"),lo=require("zod"),fo=require("module");var yn=typeof document<"u"?document.currentScript:null;function _(t,e,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const u=o.prototype,l=Object.keys(u);for(let f=0;f<l.length;f++){const p=l[f];p in a||(a[p]=u[p].bind(a))}}const s=(n==null?void 0:n.Parent)??Object;class i extends s{}Object.defineProperty(i,"name",{value:t});function o(a){var c;const u=n!=null&&n.Parent?new i:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,u;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(u=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:u.has(t)}}),Object.defineProperty(o,"name",{value:t}),o}class it extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Rs extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ps={};function Fe(t){return Ps}function Ns(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,s])=>e.indexOf(+r)===-1).map(([r,s])=>s)}function $n(t,e){return typeof e=="bigint"?e.toString():e}function an(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Kn(t){return t==null}function Yn(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function ho(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let s=(r.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c!=null&&c[1]&&(s=Number.parseInt(c[1]))}const i=n>s?n:s,o=Number.parseInt(t.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return o%a/10**i}const Pr=Symbol("evaluating");function W(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==Pr)return r===void 0&&(r=Pr,r=n()),r},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function et(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function He(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function Nr(t){return JSON.stringify(t)}function mo(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Es="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function St(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const po=an(()=>{var t;if(typeof navigator<"u"&&((t=navigator==null?void 0:navigator.userAgent)!=null&&t.includes("Cloudflare")))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function ot(t){if(St(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(St(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Is(t){return ot(t)?{...t}:Array.isArray(t)?[...t]:t}const go=new Set(["string","number","symbol"]);function at(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Me(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n!=null&&n.parent)&&(r._zod.parent=t),r}function P(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if((e==null?void 0:e.message)!==void 0){if((e==null?void 0:e.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function _o(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const yo={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function vo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(o[a]=n.shape[a])}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function bo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={...t._zod.def.shape};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete o[a]}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function wo(t,e){if(!ot(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const i=t._zod.def.shape;for(const o in e)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=He(t._zod.def,{get shape(){const i={...t._zod.def.shape,...e};return et(this,"shape",i),i}});return Me(t,s)}function ko(t,e){if(!ot(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return et(this,"shape",r),r}});return Me(t,n)}function So(t,e){const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return et(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return Me(t,n)}function To(t,e,n){const s=e._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=He(e._zod.def,{get shape(){const a=e._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=t?new t({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=t?new t({type:"optional",innerType:a[u]}):a[u];return et(this,"shape",c),c},checks:[]});return Me(e,o)}function zo(t,e,n){const r=He(e._zod.def,{get shape(){const s=e._zod.def.shape,i={...s};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)i[o]=new t({type:"nonoptional",innerType:s[o]});return et(this,"shape",i),i}});return Me(e,r)}function nt(t,e=0){var n;if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(((n=t.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function rt(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function jt(t){return typeof t=="string"?t:t==null?void 0:t.message}function Ue(t,e,n){var s,i,o,a,c,u;const r={...t,path:t.path??[]};if(!t.message){const l=jt((o=(i=(s=t.inst)==null?void 0:s._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,t))??jt((a=e==null?void 0:e.error)==null?void 0:a.call(e,t))??jt((c=n.customError)==null?void 0:c.call(n,t))??jt((u=n.localeError)==null?void 0:u.call(n,t))??"Invalid input";r.message=l}return delete r.inst,delete r.continue,e!=null&&e.reportInput||delete r.input,r}function Qn(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Tt(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Cs=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,$n,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Os=_("$ZodError",Cs),cn=_("$ZodError",Cs,{Parent:Error});function $o(t,e=n=>n.message){const n={},r=[];for(const s of t.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:n}}function Ro(t,e=n=>n.message){const n={_errors:[]},r=s=>{for(const i of s.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>r({issues:o}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(e(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(t),n}const un=t=>(e,n,r,s)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new it;if(o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},Po=un(cn),ln=t=>async(e,n,r,s)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},No=ln(cn),dn=t=>(e,n,r)=>{const s=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new it;return i.issues.length?{success:!1,error:new(t??Os)(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},Xn=dn(cn),fn=t=>async(e,n,r)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=e._zod.run({value:n,issues:[]},s);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new t(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},er=fn(cn),Eo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return un(t)(e,n,s)},Io=t=>(e,n,r)=>un(t)(e,n,r),Co=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ln(t)(e,n,s)},Oo=t=>async(e,n,r)=>ln(t)(e,n,r),xo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return dn(t)(e,n,s)},Zo=t=>(e,n,r)=>dn(t)(e,n,r),Ao=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return fn(t)(e,n,s)},jo=t=>async(e,n,r)=>fn(t)(e,n,r),Mo=/^[cC][^\s-]{8,}$/,Lo=/^[0-9a-z]+$/,Do=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qo=/^[0-9a-vA-V]{20}$/,Fo=/^[A-Za-z0-9]{27}$/,Uo=/^[a-zA-Z0-9_-]{21}$/,Vo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ho=/^([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})$/,Er=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Jo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Bo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Wo(){return new RegExp(Bo,"u")}const Go=/^(?:(?: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])$/,Ko=/^(([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}|:))$/,Yo=/^((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])$/,Qo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Xo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,xs=/^[A-Za-z0-9_-]*$/,ea=/^\+[1-9]\d{6,14}$/,Zs="(?:(?:\\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])))",ta=new RegExp(`^${Zs}$`);function As(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function na(t){return new RegExp(`^${As(t)}$`)}function ra(t){const e=As({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${Zs}T(?:${r})$`)}const sa=t=>{const e=t?`[\\s\\S]{${(t==null?void 0:t.minimum)??0},${(t==null?void 0:t.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},ia=/^-?\d+$/,js=/^-?\d+(?:\.\d+)?$/,oa=/^(?:true|false)$/i,aa=/^null$/i,ca=/^[^A-Z]*$/,ua=/^[^a-z]*$/,Se=_("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),Ms={number:"number",bigint:"bigint",object:"date"},Ls=_("$ZodCheckLessThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<i&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Ds=_("$ZodCheckGreaterThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>i&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),la=_("$ZodCheckMultipleOf",(t,e)=>{Se.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):ho(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),da=_("$ZodCheckNumberFormat",(t,e)=>{var o;Se.init(t,e),e.format=e.format||"float64";const n=(o=e.format)==null?void 0:o.includes("int"),r=n?"int":"number",[s,i]=yo[e.format];t._zod.onattach.push(a=>{const c=a._zod.bag;c.format=e.format,c.minimum=s,c.maximum=i,n&&(c.pattern=ia)}),t._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}c<s&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:t,continue:!e.abort})}}),fa=_("$ZodCheckMaxLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const s=r.value;if(s.length<=e.maximum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ha=_("$ZodCheckMinLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const s=r.value;if(s.length>=e.minimum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ma=_("$ZodCheckLengthEquals",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=r=>{const s=r.value,i=s.length;if(i===e.length)return;const o=Qn(s),a=i>e.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),hn=_("$ZodCheckStringFormat",(t,e)=>{var n,r;Se.init(t,e),t._zod.onattach.push(s=>{const i=s._zod.bag;i.format=e.format,e.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),pa=_("$ZodCheckRegex",(t,e)=>{hn.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),ga=_("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=ca),hn.init(t,e)}),_a=_("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=ua),hn.init(t,e)}),ya=_("$ZodCheckIncludes",(t,e)=>{Se.init(t,e);const n=at(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(s=>{const i=s._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),va=_("$ZodCheckStartsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`^${at(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),ba=_("$ZodCheckEndsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`.*${at(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),wa=_("$ZodCheckOverwrite",(t,e)=>{Se.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class ka{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
|
|
2
2
|
`).filter(o=>o),s=Math.min(...r.map(o=>o.length-o.trimStart().length)),i=r.map(o=>o.slice(s)).map(o=>" ".repeat(this.indent*2)+o);for(const o of i)this.content.push(o)}compile(){const e=Function,n=this==null?void 0:this.args,s=[...((this==null?void 0:this.content)??[""]).map(i=>` ${i}`)];return new e(...n,s.join(`
|
|
3
|
-
`))}}const
|
|
4
|
-
if (${
|
|
3
|
+
`))}}const Sa={major:4,minor:3,patch:6},ee=_("$ZodType",(t,e)=>{var s;var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=Sa;const r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(const i of r)for(const o of i._zod.onattach)o(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),(s=t._zod.deferred)==null||s.push(()=>{t._zod.run=t._zod.parse});else{const i=(a,c,u)=>{let l=nt(a),f;for(const p of c){if(p._zod.def.when){if(!p._zod.def.when(a))continue}else if(l)continue;const m=a.issues.length,v=p._zod.check(a);if(v instanceof Promise&&(u==null?void 0:u.async)===!1)throw new it;if(f||v instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await v,a.issues.length!==m&&(l||(l=nt(a,m)))});else{if(a.issues.length===m)continue;l||(l=nt(a,m))}}return f?f.then(()=>a):a},o=(a,c,u)=>{if(nt(a))return a.aborted=!0,a;const l=i(c,r,u);if(l instanceof Promise){if(u.async===!1)throw new it;return l.then(f=>t._zod.parse(f,u))}return t._zod.parse(l,u)};t._zod.run=(a,c)=>{if(c.skipChecks)return t._zod.parse(a,c);if(c.direction==="backward"){const l=t._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});return l instanceof Promise?l.then(f=>o(f,a,c)):o(l,a,c)}const u=t._zod.parse(a,c);if(u instanceof Promise){if(c.async===!1)throw new it;return u.then(l=>i(l,r,c))}return i(u,r,c)}}W(t,"~standard",()=>({validate:i=>{var o;try{const a=Xn(t,i);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return er(t,i).then(c=>{var u;return c.success?{value:c.data}:{issues:(u=c.error)==null?void 0:u.issues}})}},vendor:"zod",version:1}))}),tr=_("$ZodString",(t,e)=>{var n;ee.init(t,e),t._zod.pattern=[...((n=t==null?void 0:t._zod.bag)==null?void 0:n.patterns)??[]].pop()??sa(t._zod.bag),t._zod.parse=(r,s)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),ne=_("$ZodStringFormat",(t,e)=>{hn.init(t,e),tr.init(t,e)}),Ta=_("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Ho),ne.init(t,e)}),za=_("$ZodUUID",(t,e)=>{if(e.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(r===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Er(r))}else e.pattern??(e.pattern=Er());ne.init(t,e)}),$a=_("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Jo),ne.init(t,e)}),Ra=_("$ZodURL",(t,e)=>{ne.init(t,e),t._zod.check=n=>{try{const r=n.value.trim(),s=new URL(r);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(s.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:e.hostname.source,input:n.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:n.value,inst:t,continue:!e.abort})),e.normalize?n.value=s.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:t,continue:!e.abort})}}}),Pa=_("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Wo()),ne.init(t,e)}),Na=_("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Uo),ne.init(t,e)}),Ea=_("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=Mo),ne.init(t,e)}),Ia=_("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Lo),ne.init(t,e)}),Ca=_("$ZodULID",(t,e)=>{e.pattern??(e.pattern=Do),ne.init(t,e)}),Oa=_("$ZodXID",(t,e)=>{e.pattern??(e.pattern=qo),ne.init(t,e)}),xa=_("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Fo),ne.init(t,e)}),Za=_("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=ra(e)),ne.init(t,e)}),Aa=_("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=ta),ne.init(t,e)}),ja=_("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=na(e)),ne.init(t,e)}),Ma=_("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Vo),ne.init(t,e)}),La=_("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Go),ne.init(t,e),t._zod.bag.format="ipv4"}),Da=_("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Ko),ne.init(t,e),t._zod.bag.format="ipv6",t._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:t,continue:!e.abort})}}}),qa=_("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Yo),ne.init(t,e)}),Fa=_("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Qo),ne.init(t,e),t._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[s,i]=r;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${s}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:t,continue:!e.abort})}}});function qs(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Ua=_("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Xo),ne.init(t,e),t._zod.bag.contentEncoding="base64",t._zod.check=n=>{qs(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:t,continue:!e.abort})}});function Va(t){if(!xs.test(t))return!1;const e=t.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=e.padEnd(Math.ceil(e.length/4)*4,"=");return qs(n)}const Ha=_("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=xs),ne.init(t,e),t._zod.bag.contentEncoding="base64url",t._zod.check=n=>{Va(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:t,continue:!e.abort})}}),Ja=_("$ZodE164",(t,e)=>{e.pattern??(e.pattern=ea),ne.init(t,e)});function Ba(t,e=null){try{const n=t.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const s=JSON.parse(atob(r));return!("typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&(!("alg"in s)||s.alg!==e))}catch{return!1}}const Wa=_("$ZodJWT",(t,e)=>{ne.init(t,e),t._zod.check=n=>{Ba(n.value,e.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:t,continue:!e.abort})}}),Fs=_("$ZodNumber",(t,e)=>{ee.init(t,e),t._zod.pattern=t._zod.bag.pattern??js,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}const s=n.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return n;const i=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:s,inst:t,...i?{received:i}:{}}),n}}),Ga=_("$ZodNumberFormat",(t,e)=>{da.init(t,e),Fs.init(t,e)}),Ka=_("$ZodBoolean",(t,e)=>{ee.init(t,e),t._zod.pattern=oa,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=!!n.value}catch{}const s=n.value;return typeof s=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:t}),n}}),Ya=_("$ZodNull",(t,e)=>{ee.init(t,e),t._zod.pattern=aa,t._zod.values=new Set([null]),t._zod.parse=(n,r)=>{const s=n.value;return s===null||n.issues.push({expected:"null",code:"invalid_type",input:s,inst:t}),n}}),Qa=_("$ZodUnknown",(t,e)=>{ee.init(t,e),t._zod.parse=n=>n}),Xa=_("$ZodNever",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:t}),n)});function Ir(t,e,n){t.issues.length&&e.issues.push(...rt(n,t.issues)),e.value[n]=t.value}const ec=_("$ZodArray",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>{const s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:t}),n;n.value=Array(s.length);const i=[];for(let o=0;o<s.length;o++){const a=s[o],c=e.element._zod.run({value:a,issues:[]},r);c instanceof Promise?i.push(c.then(u=>Ir(u,n,o))):Ir(c,n,o)}return i.length?Promise.all(i).then(()=>n):n}});function qt(t,e,n,r,s){if(t.issues.length){if(s&&!(n in r))return;e.issues.push(...rt(n,t.issues))}t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}function Us(t){var r,s,i,o;const e=Object.keys(t.shape);for(const a of e)if(!((o=(i=(s=(r=t.shape)==null?void 0:r[a])==null?void 0:s._zod)==null?void 0:i.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=_o(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}}function Vs(t,e,n,r,s,i){const o=[],a=s.keySet,c=s.catchall._zod,u=c.def.type,l=c.optout==="optional";for(const f in e){if(a.has(f))continue;if(u==="never"){o.push(f);continue}const p=c.run({value:e[f],issues:[]},r);p instanceof Promise?t.push(p.then(m=>qt(m,n,f,e,l))):qt(p,n,f,e,l)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:i}),t.length?Promise.all(t).then(()=>n):n}const Hs=_("$ZodObject",(t,e)=>{ee.init(t,e);const n=Object.getOwnPropertyDescriptor(e,"shape");if(!(n!=null&&n.get)){const a=e.shape;Object.defineProperty(e,"shape",{get:()=>{const c={...a};return Object.defineProperty(e,"shape",{value:c}),c}})}const r=an(()=>Us(e));W(t._zod,"propValues",()=>{const a=e.shape,c={};for(const u in a){const l=a[u]._zod;if(l.values){c[u]??(c[u]=new Set);for(const f of l.values)c[u].add(f)}}return c});const s=St,i=e.catchall;let o;t._zod.parse=(a,c)=>{o??(o=r.value);const u=a.value;if(!s(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:t}),a;a.value={};const l=[],f=o.shape;for(const p of o.keys){const m=f[p],v=m._zod.optout==="optional",T=m._zod.run({value:u[p],issues:[]},c);T instanceof Promise?l.push(T.then(x=>qt(x,a,p,u,v))):qt(T,a,p,u,v)}return i?Vs(l,u,a,c,r.value,t):l.length?Promise.all(l).then(()=>a):a}}),tc=_("$ZodObjectJIT",(t,e)=>{Hs.init(t,e);const n=t._zod.parse,r=an(()=>Us(e)),s=p=>{var A;const m=new ka(["shape","payload","ctx"]),v=r.value,T=j=>{const L=Nr(j);return`shape[${L}]._zod.run({ value: input[${L}], issues: [] }, ctx)`};m.write("const input = payload.value;");const x=Object.create(null);let b=0;for(const j of v.keys)x[j]=`key_${b++}`;m.write("const newResult = {};");for(const j of v.keys){const L=x[j],ue=Nr(j),K=p[j],_e=((A=K==null?void 0:K._zod)==null?void 0:A.optout)==="optional";m.write(`const ${L} = ${T(j)};`),_e?m.write(`
|
|
4
|
+
if (${L}.issues.length) {
|
|
5
5
|
if (${ue} in input) {
|
|
6
|
-
payload.issues = payload.issues.concat(${
|
|
6
|
+
payload.issues = payload.issues.concat(${L}.issues.map(iss => ({
|
|
7
7
|
...iss,
|
|
8
8
|
path: iss.path ? [${ue}, ...iss.path] : [${ue}]
|
|
9
9
|
})));
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
if (${
|
|
13
|
+
if (${L}.value === undefined) {
|
|
14
14
|
if (${ue} in input) {
|
|
15
15
|
newResult[${ue}] = undefined;
|
|
16
16
|
}
|
|
17
17
|
} else {
|
|
18
|
-
newResult[${ue}] = ${
|
|
18
|
+
newResult[${ue}] = ${L}.value;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
`):m.write(`
|
|
22
|
-
if (${
|
|
23
|
-
payload.issues = payload.issues.concat(${
|
|
22
|
+
if (${L}.issues.length) {
|
|
23
|
+
payload.issues = payload.issues.concat(${L}.issues.map(iss => ({
|
|
24
24
|
...iss,
|
|
25
25
|
path: iss.path ? [${ue}, ...iss.path] : [${ue}]
|
|
26
26
|
})));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (${
|
|
29
|
+
if (${L}.value === undefined) {
|
|
30
30
|
if (${ue} in input) {
|
|
31
31
|
newResult[${ue}] = undefined;
|
|
32
32
|
}
|
|
33
33
|
} else {
|
|
34
|
-
newResult[${ue}] = ${
|
|
34
|
+
newResult[${ue}] = ${L}.value;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
`)}m.write("payload.value = newResult;"),m.write("return payload;");const v=m.compile();return(R,te)=>v(p,R,te)};let i;const o=kt,a=!Ps.jitless,u=a&&mo.value,l=e.catchall;let d;t._zod.parse=(p,m)=>{d??(d=r.value);const S=p.value;return o(S)?a&&u&&(m==null?void 0:m.async)===!1&&m.jitless!==!0?(i||(i=s(e.shape)),p=i(p,m),l?Us([],S,p,m,d,t):p):n(p,m):(p.issues.push({expected:"object",code:"invalid_type",input:S,inst:t}),p)}});function Cr(t,e,n,r){for(const i of t)if(i.issues.length===0)return e.value=i.value,e;const s=t.filter(i=>!nt(i));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(i=>i.issues.map(o=>Ue(o,r,Fe())))}),e)}const Hs=_("$ZodUnion",(t,e)=>{X.init(t,e),B(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),B(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),B(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),B(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(i=>i._zod.pattern);return new RegExp(`^(${s.map(i=>Kn(i.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(s,i)=>{if(n)return r(s,i);let o=!1;const a=[];for(const c of e.options){const u=c._zod.run({value:s.value,issues:[]},i);if(u instanceof Promise)a.push(u),o=!0;else{if(u.issues.length===0)return u;a.push(u)}}return o?Promise.all(a).then(c=>Cr(c,s,t,i)):Cr(a,s,t,i)}}),tc=_("$ZodDiscriminatedUnion",(t,e)=>{e.inclusive=!1,Hs.init(t,e);const n=t._zod.parse;B(t._zod,"propValues",()=>{const s={};for(const i of e.options){const o=i._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(i)}"`);for(const[a,c]of Object.entries(o)){s[a]||(s[a]=new Set);for(const u of c)s[a].add(u)}}return s});const r=an(()=>{var o;const s=e.options,i=new Map;for(const a of s){const c=(o=a._zod.propValues)==null?void 0:o[e.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(a)}"`);for(const u of c){if(i.has(u))throw new Error(`Duplicate discriminator value "${String(u)}"`);i.set(u,a)}}return i});t._zod.parse=(s,i)=>{const o=s.value;if(!kt(o))return s.issues.push({code:"invalid_type",expected:"object",input:o,inst:t}),s;const a=r.value.get(o==null?void 0:o[e.discriminator]);return a?a._zod.run(s,i):e.unionFallback?n(s,i):(s.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:e.discriminator,input:o,path:[e.discriminator],inst:t}),s)}}),nc=_("$ZodIntersection",(t,e)=>{X.init(t,e),t._zod.parse=(n,r)=>{const s=n.value,i=e.left._zod.run({value:s,issues:[]},r),o=e.right._zod.run({value:s,issues:[]},r);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([c,u])=>Ir(n,c,u)):Ir(n,i,o)}});function Pn(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(ot(t)&&ot(e)){const n=Object.keys(e),r=Object.keys(t).filter(i=>n.indexOf(i)!==-1),s={...t,...e};for(const i of r){const o=Pn(t[i],e[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};s[i]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<t.length;r++){const s=t[r],i=e[r],o=Pn(s,i);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ir(t,e,n){const r=new Map;let s;for(const a of e.issues)if(a.code==="unrecognized_keys"){s??(s=a);for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else t.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else t.issues.push(a);const i=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(i.length&&s&&t.issues.push({...s,keys:i}),nt(t))return t;const o=Pn(e.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return t.value=o.data,t}const rc=_("$ZodRecord",(t,e)=>{X.init(t,e),t._zod.parse=(n,r)=>{const s=n.value;if(!ot(s))return n.issues.push({expected:"record",code:"invalid_type",input:s,inst:t}),n;const i=[],o=e.keyType._zod.values;if(o){n.value={};const a=new Set;for(const u of o)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){a.add(typeof u=="number"?u.toString():u);const l=e.valueType._zod.run({value:s[u],issues:[]},r);l instanceof Promise?i.push(l.then(d=>{d.issues.length&&n.issues.push(...rt(u,d.issues)),n.value[u]=d.value})):(l.issues.length&&n.issues.push(...rt(u,l.issues)),n.value[u]=l.value)}let c;for(const u in s)a.has(u)||(c=c??[],c.push(u));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:s,inst:t,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(s)){if(a==="__proto__")continue;let c=e.keyType._zod.run({value:a,issues:[]},r);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&As.test(a)&&c.issues.length){const d=e.keyType._zod.run({value:Number(a),issues:[]},r);if(d instanceof Promise)throw new Error("Async schemas not supported in object keys currently");d.issues.length===0&&(c=d)}if(c.issues.length){e.mode==="loose"?n.value[a]=s[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(d=>Ue(d,r,Fe())),input:a,path:[a],inst:t});continue}const l=e.valueType._zod.run({value:s[a],issues:[]},r);l instanceof Promise?i.push(l.then(d=>{d.issues.length&&n.issues.push(...rt(a,d.issues)),n.value[c.value]=d.value})):(l.issues.length&&n.issues.push(...rt(a,l.issues)),n.value[c.value]=l.value)}}return i.length?Promise.all(i).then(()=>n):n}}),sc=_("$ZodEnum",(t,e)=>{X.init(t,e);const n=Rs(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(s=>po.has(typeof s)).map(s=>typeof s=="string"?at(s):s.toString()).join("|")})$`),t._zod.parse=(s,i)=>{const o=s.value;return r.has(o)||s.issues.push({code:"invalid_value",values:n,input:o,inst:t}),s}}),ic=_("$ZodLiteral",(t,e)=>{if(X.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(e.values);t._zod.values=n,t._zod.pattern=new RegExp(`^(${e.values.map(r=>typeof r=="string"?at(r):r?at(r.toString()):String(r)).join("|")})$`),t._zod.parse=(r,s)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:e.values,input:i,inst:t}),r}}),oc=_("$ZodTransform",(t,e)=>{X.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new $s(t.constructor.name);const s=e.transform(n.value,n);if(r.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(n.value=o,n));if(s instanceof Promise)throw new it;return n.value=s,n}});function Or(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Js=_("$ZodOptional",(t,e)=>{X.init(t,e),t._zod.optin="optional",t._zod.optout="optional",B(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),B(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Kn(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>Or(i,n.value)):Or(s,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),ac=_("$ZodExactOptional",(t,e)=>{Js.init(t,e),B(t._zod,"values",()=>e.innerType._zod.values),B(t._zod,"pattern",()=>e.innerType._zod.pattern),t._zod.parse=(n,r)=>e.innerType._zod.run(n,r)}),cc=_("$ZodNullable",(t,e)=>{X.init(t,e),B(t._zod,"optin",()=>e.innerType._zod.optin),B(t._zod,"optout",()=>e.innerType._zod.optout),B(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Kn(n.source)}|null)$`):void 0}),B(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),uc=_("$ZodDefault",(t,e)=>{X.init(t,e),t._zod.optin="optional",B(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);if(n.value===void 0)return n.value=e.defaultValue,n;const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>xr(i,e)):xr(s,e)}});function xr(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const lc=_("$ZodPrefault",(t,e)=>{X.init(t,e),t._zod.optin="optional",B(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),dc=_("$ZodNonOptional",(t,e)=>{X.init(t,e),B(t._zod,"values",()=>{const n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>Zr(i,t)):Zr(s,t)}});function Zr(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const fc=_("$ZodCatch",(t,e)=>{X.init(t,e),B(t._zod,"optin",()=>e.innerType._zod.optin),B(t._zod,"optout",()=>e.innerType._zod.optout),B(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>(n.value=i.value,i.issues.length&&(n.value=e.catchValue({...n,error:{issues:i.issues.map(o=>Ue(o,r,Fe()))},input:n.value}),n.issues=[]),n)):(n.value=s.value,s.issues.length&&(n.value=e.catchValue({...n,error:{issues:s.issues.map(i=>Ue(i,r,Fe()))},input:n.value}),n.issues=[]),n)}}),hc=_("$ZodPipe",(t,e)=>{X.init(t,e),B(t._zod,"values",()=>e.in._zod.values),B(t._zod,"optin",()=>e.in._zod.optin),B(t._zod,"optout",()=>e.out._zod.optout),B(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const i=e.out._zod.run(n,r);return i instanceof Promise?i.then(o=>jt(o,e.in,r)):jt(i,e.in,r)}const s=e.in._zod.run(n,r);return s instanceof Promise?s.then(i=>jt(i,e.out,r)):jt(s,e.out,r)}});function jt(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const mc=_("$ZodReadonly",(t,e)=>{X.init(t,e),B(t._zod,"propValues",()=>e.innerType._zod.propValues),B(t._zod,"values",()=>e.innerType._zod.values),B(t._zod,"optin",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optin}),B(t._zod,"optout",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optout}),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(Ar):Ar(s)}});function Ar(t){return t.value=Object.freeze(t.value),t}const pc=_("$ZodCustom",(t,e)=>{Se.init(t,e),X.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,s=e.fn(r);if(s instanceof Promise)return s.then(i=>jr(i,n,r,t));jr(s,n,r,t)}});function jr(t,e,n,r){if(!t){const s={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(s.params=r._zod.def.params),e.issues.push(St(s))}}var Mr;class gc{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...n){const r=n[0];return this._map.set(e,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){const n=e._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const s={...r,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function _c(){return new gc}(Mr=globalThis).__zod_globalRegistry??(Mr.__zod_globalRegistry=_c());const vt=globalThis.__zod_globalRegistry;function yc(t,e){return new t({type:"string",...N(e)})}function vc(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...N(e)})}function Lr(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...N(e)})}function bc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...N(e)})}function wc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...N(e)})}function kc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...N(e)})}function Sc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...N(e)})}function Tc(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...N(e)})}function zc(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...N(e)})}function $c(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...N(e)})}function Pc(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...N(e)})}function Rc(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...N(e)})}function Nc(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...N(e)})}function Ec(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...N(e)})}function Cc(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...N(e)})}function Ic(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...N(e)})}function Oc(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...N(e)})}function xc(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...N(e)})}function Zc(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...N(e)})}function Ac(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...N(e)})}function jc(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...N(e)})}function Mc(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...N(e)})}function Lc(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...N(e)})}function Dc(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...N(e)})}function qc(t,e){return new t({type:"string",format:"date",check:"string_format",...N(e)})}function Fc(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...N(e)})}function Uc(t,e){return new t({type:"string",format:"duration",check:"string_format",...N(e)})}function Vc(t,e){return new t({type:"number",checks:[],...N(e)})}function Hc(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...N(e)})}function Jc(t,e){return new t({type:"boolean",...N(e)})}function Bc(t,e){return new t({type:"null",...N(e)})}function Wc(t){return new t({type:"unknown"})}function Gc(t,e){return new t({type:"never",...N(e)})}function Dr(t,e){return new Ms({check:"less_than",...N(e),value:t,inclusive:!1})}function vn(t,e){return new Ms({check:"less_than",...N(e),value:t,inclusive:!0})}function qr(t,e){return new Ls({check:"greater_than",...N(e),value:t,inclusive:!1})}function bn(t,e){return new Ls({check:"greater_than",...N(e),value:t,inclusive:!0})}function Fr(t,e){return new ua({check:"multiple_of",...N(e),value:t})}function Bs(t,e){return new da({check:"max_length",...N(e),maximum:t})}function Ft(t,e){return new fa({check:"min_length",...N(e),minimum:t})}function Ws(t,e){return new ha({check:"length_equals",...N(e),length:t})}function Kc(t,e){return new ma({check:"string_format",format:"regex",...N(e),pattern:t})}function Yc(t){return new pa({check:"string_format",format:"lowercase",...N(t)})}function Qc(t){return new ga({check:"string_format",format:"uppercase",...N(t)})}function Xc(t,e){return new _a({check:"string_format",format:"includes",...N(e),includes:t})}function eu(t,e){return new ya({check:"string_format",format:"starts_with",...N(e),prefix:t})}function tu(t,e){return new va({check:"string_format",format:"ends_with",...N(e),suffix:t})}function ht(t){return new ba({check:"overwrite",tx:t})}function nu(t){return ht(e=>e.normalize(t))}function ru(){return ht(t=>t.trim())}function su(){return ht(t=>t.toLowerCase())}function iu(){return ht(t=>t.toUpperCase())}function ou(){return ht(t=>ho(t))}function au(t,e,n){return new t({type:"array",element:e,...N(n)})}function cu(t,e,n){const r=N(n);return r.abort??(r.abort=!0),new t({type:"custom",check:"custom",fn:e,...r})}function uu(t,e,n){return new t({type:"custom",check:"custom",fn:e,...N(n)})}function lu(t){const e=du(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(St(r,n.value,e._zod.def));else{const s=r;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),n.issues.push(St(s))}},t(n.value,n)));return e}function du(t,e){const n=new Se({check:"custom",...N(e)});return n._zod.check=t,n}function Ut(t){let e=(t==null?void 0:t.target)??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:(t==null?void 0:t.metadata)??vt,target:e,unrepresentable:(t==null?void 0:t.unrepresentable)??"throw",override:(t==null?void 0:t.override)??(()=>{}),io:(t==null?void 0:t.io)??"output",counter:0,seen:new Map,cycles:(t==null?void 0:t.cycles)??"ref",reused:(t==null?void 0:t.reused)??"inline",external:(t==null?void 0:t.external)??void 0}}function Q(t,e,n={path:[],schemaPath:[]}){var l,d;var r;const s=t._zod.def,i=e.seen.get(t);if(i)return i.count++,n.schemaPath.includes(t)&&(i.cycle=n.path),i.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};e.seen.set(t,o);const a=(d=(l=t._zod).toJSONSchema)==null?void 0:d.call(l);if(a)o.schema=a;else{const p={...n,schemaPath:[...n.schemaPath,t],path:n.path};if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,o.schema,p);else{const S=o.schema,T=e.processors[s.type];if(!T)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);T(t,e,S,p)}const m=t._zod.parent;m&&(o.ref||(o.ref=m),Q(m,e,p),e.seen.get(m).isParent=!0)}const c=e.metadataRegistry.get(t);return c&&Object.assign(o.schema,c),e.io==="input"&&ve(t)&&(delete o.schema.examples,delete o.schema.default),e.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,e.seen.get(t).schema}function Vt(t,e){var o,a,c,u;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const l of t.seen.entries()){const d=(o=t.metadataRegistry.get(l[0]))==null?void 0:o.id;if(d){const p=r.get(d);if(p&&p!==l[0])throw new Error(`Duplicate schema id "${d}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(d,l[0])}}const s=l=>{var T;const d=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const j=(T=t.external.registry.get(l[0]))==null?void 0:T.id,y=t.external.uri??(Z=>Z);if(j)return{ref:y(j)};const v=l[1].defId??l[1].schema.id??`schema${t.counter++}`;return l[1].defId=v,{defId:v,ref:`${y("__shared")}#/${d}/${v}`}}if(l[1]===n)return{ref:"#"};const m=`#/${d}/`,S=l[1].schema.id??`__schema${t.counter++}`;return{defId:S,ref:m+S}},i=l=>{if(l[1].schema.$ref)return;const d=l[1],{ref:p,defId:m}=s(l);d.def={...d.schema},m&&(d.defId=m);const S=d.schema;for(const T in S)delete S[T];S.$ref=p};if(t.cycles==="throw")for(const l of t.seen.entries()){const d=l[1];if(d.cycle)throw new Error(`Cycle detected: #/${(a=d.cycle)==null?void 0:a.join("/")}/<root>
|
|
37
|
+
`)}m.write("payload.value = newResult;"),m.write("return payload;");const y=m.compile();return(j,L)=>y(p,j,L)};let i;const o=St,a=!Ps.jitless,u=a&&po.value,l=e.catchall;let f;t._zod.parse=(p,m)=>{f??(f=r.value);const v=p.value;return o(v)?a&&u&&(m==null?void 0:m.async)===!1&&m.jitless!==!0?(i||(i=s(e.shape)),p=i(p,m),l?Vs([],v,p,m,f,t):p):n(p,m):(p.issues.push({expected:"object",code:"invalid_type",input:v,inst:t}),p)}});function Cr(t,e,n,r){for(const i of t)if(i.issues.length===0)return e.value=i.value,e;const s=t.filter(i=>!nt(i));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(i=>i.issues.map(o=>Ue(o,r,Fe())))}),e)}const Js=_("$ZodUnion",(t,e)=>{ee.init(t,e),W(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),W(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),W(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),W(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(i=>i._zod.pattern);return new RegExp(`^(${s.map(i=>Yn(i.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(s,i)=>{if(n)return r(s,i);let o=!1;const a=[];for(const c of e.options){const u=c._zod.run({value:s.value,issues:[]},i);if(u instanceof Promise)a.push(u),o=!0;else{if(u.issues.length===0)return u;a.push(u)}}return o?Promise.all(a).then(c=>Cr(c,s,t,i)):Cr(a,s,t,i)}}),nc=_("$ZodDiscriminatedUnion",(t,e)=>{e.inclusive=!1,Js.init(t,e);const n=t._zod.parse;W(t._zod,"propValues",()=>{const s={};for(const i of e.options){const o=i._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(i)}"`);for(const[a,c]of Object.entries(o)){s[a]||(s[a]=new Set);for(const u of c)s[a].add(u)}}return s});const r=an(()=>{var o;const s=e.options,i=new Map;for(const a of s){const c=(o=a._zod.propValues)==null?void 0:o[e.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(a)}"`);for(const u of c){if(i.has(u))throw new Error(`Duplicate discriminator value "${String(u)}"`);i.set(u,a)}}return i});t._zod.parse=(s,i)=>{const o=s.value;if(!St(o))return s.issues.push({code:"invalid_type",expected:"object",input:o,inst:t}),s;const a=r.value.get(o==null?void 0:o[e.discriminator]);return a?a._zod.run(s,i):e.unionFallback?n(s,i):(s.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:e.discriminator,input:o,path:[e.discriminator],inst:t}),s)}}),rc=_("$ZodIntersection",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>{const s=n.value,i=e.left._zod.run({value:s,issues:[]},r),o=e.right._zod.run({value:s,issues:[]},r);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([c,u])=>Or(n,c,u)):Or(n,i,o)}});function Rn(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(ot(t)&&ot(e)){const n=Object.keys(e),r=Object.keys(t).filter(i=>n.indexOf(i)!==-1),s={...t,...e};for(const i of r){const o=Rn(t[i],e[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};s[i]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<t.length;r++){const s=t[r],i=e[r],o=Rn(s,i);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Or(t,e,n){const r=new Map;let s;for(const a of e.issues)if(a.code==="unrecognized_keys"){s??(s=a);for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else t.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else t.issues.push(a);const i=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(i.length&&s&&t.issues.push({...s,keys:i}),nt(t))return t;const o=Rn(e.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return t.value=o.data,t}const sc=_("$ZodRecord",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>{const s=n.value;if(!ot(s))return n.issues.push({expected:"record",code:"invalid_type",input:s,inst:t}),n;const i=[],o=e.keyType._zod.values;if(o){n.value={};const a=new Set;for(const u of o)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){a.add(typeof u=="number"?u.toString():u);const l=e.valueType._zod.run({value:s[u],issues:[]},r);l instanceof Promise?i.push(l.then(f=>{f.issues.length&&n.issues.push(...rt(u,f.issues)),n.value[u]=f.value})):(l.issues.length&&n.issues.push(...rt(u,l.issues)),n.value[u]=l.value)}let c;for(const u in s)a.has(u)||(c=c??[],c.push(u));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:s,inst:t,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(s)){if(a==="__proto__")continue;let c=e.keyType._zod.run({value:a,issues:[]},r);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&js.test(a)&&c.issues.length){const f=e.keyType._zod.run({value:Number(a),issues:[]},r);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(c=f)}if(c.issues.length){e.mode==="loose"?n.value[a]=s[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(f=>Ue(f,r,Fe())),input:a,path:[a],inst:t});continue}const l=e.valueType._zod.run({value:s[a],issues:[]},r);l instanceof Promise?i.push(l.then(f=>{f.issues.length&&n.issues.push(...rt(a,f.issues)),n.value[c.value]=f.value})):(l.issues.length&&n.issues.push(...rt(a,l.issues)),n.value[c.value]=l.value)}}return i.length?Promise.all(i).then(()=>n):n}}),ic=_("$ZodEnum",(t,e)=>{ee.init(t,e);const n=Ns(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(s=>go.has(typeof s)).map(s=>typeof s=="string"?at(s):s.toString()).join("|")})$`),t._zod.parse=(s,i)=>{const o=s.value;return r.has(o)||s.issues.push({code:"invalid_value",values:n,input:o,inst:t}),s}}),oc=_("$ZodLiteral",(t,e)=>{if(ee.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(e.values);t._zod.values=n,t._zod.pattern=new RegExp(`^(${e.values.map(r=>typeof r=="string"?at(r):r?at(r.toString()):String(r)).join("|")})$`),t._zod.parse=(r,s)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:e.values,input:i,inst:t}),r}}),ac=_("$ZodTransform",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Rs(t.constructor.name);const s=e.transform(n.value,n);if(r.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(n.value=o,n));if(s instanceof Promise)throw new it;return n.value=s,n}});function xr(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Bs=_("$ZodOptional",(t,e)=>{ee.init(t,e),t._zod.optin="optional",t._zod.optout="optional",W(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),W(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Yn(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>xr(i,n.value)):xr(s,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),cc=_("$ZodExactOptional",(t,e)=>{Bs.init(t,e),W(t._zod,"values",()=>e.innerType._zod.values),W(t._zod,"pattern",()=>e.innerType._zod.pattern),t._zod.parse=(n,r)=>e.innerType._zod.run(n,r)}),uc=_("$ZodNullable",(t,e)=>{ee.init(t,e),W(t._zod,"optin",()=>e.innerType._zod.optin),W(t._zod,"optout",()=>e.innerType._zod.optout),W(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Yn(n.source)}|null)$`):void 0}),W(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),lc=_("$ZodDefault",(t,e)=>{ee.init(t,e),t._zod.optin="optional",W(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);if(n.value===void 0)return n.value=e.defaultValue,n;const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>Zr(i,e)):Zr(s,e)}});function Zr(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const dc=_("$ZodPrefault",(t,e)=>{ee.init(t,e),t._zod.optin="optional",W(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),fc=_("$ZodNonOptional",(t,e)=>{ee.init(t,e),W(t._zod,"values",()=>{const n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>Ar(i,t)):Ar(s,t)}});function Ar(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const hc=_("$ZodCatch",(t,e)=>{ee.init(t,e),W(t._zod,"optin",()=>e.innerType._zod.optin),W(t._zod,"optout",()=>e.innerType._zod.optout),W(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>(n.value=i.value,i.issues.length&&(n.value=e.catchValue({...n,error:{issues:i.issues.map(o=>Ue(o,r,Fe()))},input:n.value}),n.issues=[]),n)):(n.value=s.value,s.issues.length&&(n.value=e.catchValue({...n,error:{issues:s.issues.map(i=>Ue(i,r,Fe()))},input:n.value}),n.issues=[]),n)}}),mc=_("$ZodPipe",(t,e)=>{ee.init(t,e),W(t._zod,"values",()=>e.in._zod.values),W(t._zod,"optin",()=>e.in._zod.optin),W(t._zod,"optout",()=>e.out._zod.optout),W(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const i=e.out._zod.run(n,r);return i instanceof Promise?i.then(o=>Mt(o,e.in,r)):Mt(i,e.in,r)}const s=e.in._zod.run(n,r);return s instanceof Promise?s.then(i=>Mt(i,e.out,r)):Mt(s,e.out,r)}});function Mt(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const pc=_("$ZodReadonly",(t,e)=>{ee.init(t,e),W(t._zod,"propValues",()=>e.innerType._zod.propValues),W(t._zod,"values",()=>e.innerType._zod.values),W(t._zod,"optin",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optin}),W(t._zod,"optout",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optout}),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(jr):jr(s)}});function jr(t){return t.value=Object.freeze(t.value),t}const gc=_("$ZodCustom",(t,e)=>{Se.init(t,e),ee.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,s=e.fn(r);if(s instanceof Promise)return s.then(i=>Mr(i,n,r,t));Mr(s,n,r,t)}});function Mr(t,e,n,r){if(!t){const s={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(s.params=r._zod.def.params),e.issues.push(Tt(s))}}var Lr;class _c{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...n){const r=n[0];return this._map.set(e,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){const n=e._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const s={...r,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function yc(){return new _c}(Lr=globalThis).__zod_globalRegistry??(Lr.__zod_globalRegistry=yc());const vt=globalThis.__zod_globalRegistry;function vc(t,e){return new t({type:"string",...P(e)})}function bc(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...P(e)})}function Dr(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...P(e)})}function wc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...P(e)})}function kc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...P(e)})}function Sc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...P(e)})}function Tc(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...P(e)})}function zc(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...P(e)})}function $c(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...P(e)})}function Rc(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...P(e)})}function Pc(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...P(e)})}function Nc(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...P(e)})}function Ec(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...P(e)})}function Ic(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...P(e)})}function Cc(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...P(e)})}function Oc(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...P(e)})}function xc(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...P(e)})}function Zc(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...P(e)})}function Ac(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...P(e)})}function jc(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...P(e)})}function Mc(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...P(e)})}function Lc(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...P(e)})}function Dc(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...P(e)})}function qc(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...P(e)})}function Fc(t,e){return new t({type:"string",format:"date",check:"string_format",...P(e)})}function Uc(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...P(e)})}function Vc(t,e){return new t({type:"string",format:"duration",check:"string_format",...P(e)})}function Hc(t,e){return new t({type:"number",checks:[],...P(e)})}function Jc(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...P(e)})}function Bc(t,e){return new t({type:"boolean",...P(e)})}function Wc(t,e){return new t({type:"null",...P(e)})}function Gc(t){return new t({type:"unknown"})}function Kc(t,e){return new t({type:"never",...P(e)})}function qr(t,e){return new Ls({check:"less_than",...P(e),value:t,inclusive:!1})}function vn(t,e){return new Ls({check:"less_than",...P(e),value:t,inclusive:!0})}function Fr(t,e){return new Ds({check:"greater_than",...P(e),value:t,inclusive:!1})}function bn(t,e){return new Ds({check:"greater_than",...P(e),value:t,inclusive:!0})}function Ur(t,e){return new la({check:"multiple_of",...P(e),value:t})}function Ws(t,e){return new fa({check:"max_length",...P(e),maximum:t})}function Ft(t,e){return new ha({check:"min_length",...P(e),minimum:t})}function Gs(t,e){return new ma({check:"length_equals",...P(e),length:t})}function Yc(t,e){return new pa({check:"string_format",format:"regex",...P(e),pattern:t})}function Qc(t){return new ga({check:"string_format",format:"lowercase",...P(t)})}function Xc(t){return new _a({check:"string_format",format:"uppercase",...P(t)})}function eu(t,e){return new ya({check:"string_format",format:"includes",...P(e),includes:t})}function tu(t,e){return new va({check:"string_format",format:"starts_with",...P(e),prefix:t})}function nu(t,e){return new ba({check:"string_format",format:"ends_with",...P(e),suffix:t})}function ht(t){return new wa({check:"overwrite",tx:t})}function ru(t){return ht(e=>e.normalize(t))}function su(){return ht(t=>t.trim())}function iu(){return ht(t=>t.toLowerCase())}function ou(){return ht(t=>t.toUpperCase())}function au(){return ht(t=>mo(t))}function cu(t,e,n){return new t({type:"array",element:e,...P(n)})}function uu(t,e,n){const r=P(n);return r.abort??(r.abort=!0),new t({type:"custom",check:"custom",fn:e,...r})}function lu(t,e,n){return new t({type:"custom",check:"custom",fn:e,...P(n)})}function du(t){const e=fu(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(Tt(r,n.value,e._zod.def));else{const s=r;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),n.issues.push(Tt(s))}},t(n.value,n)));return e}function fu(t,e){const n=new Se({check:"custom",...P(e)});return n._zod.check=t,n}function Ut(t){let e=(t==null?void 0:t.target)??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:(t==null?void 0:t.metadata)??vt,target:e,unrepresentable:(t==null?void 0:t.unrepresentable)??"throw",override:(t==null?void 0:t.override)??(()=>{}),io:(t==null?void 0:t.io)??"output",counter:0,seen:new Map,cycles:(t==null?void 0:t.cycles)??"ref",reused:(t==null?void 0:t.reused)??"inline",external:(t==null?void 0:t.external)??void 0}}function X(t,e,n={path:[],schemaPath:[]}){var l,f;var r;const s=t._zod.def,i=e.seen.get(t);if(i)return i.count++,n.schemaPath.includes(t)&&(i.cycle=n.path),i.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};e.seen.set(t,o);const a=(f=(l=t._zod).toJSONSchema)==null?void 0:f.call(l);if(a)o.schema=a;else{const p={...n,schemaPath:[...n.schemaPath,t],path:n.path};if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,o.schema,p);else{const v=o.schema,T=e.processors[s.type];if(!T)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);T(t,e,v,p)}const m=t._zod.parent;m&&(o.ref||(o.ref=m),X(m,e,p),e.seen.get(m).isParent=!0)}const c=e.metadataRegistry.get(t);return c&&Object.assign(o.schema,c),e.io==="input"&&ve(t)&&(delete o.schema.examples,delete o.schema.default),e.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,e.seen.get(t).schema}function Vt(t,e){var o,a,c,u;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const l of t.seen.entries()){const f=(o=t.metadataRegistry.get(l[0]))==null?void 0:o.id;if(f){const p=r.get(f);if(p&&p!==l[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(f,l[0])}}const s=l=>{var T;const f=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const x=(T=t.external.registry.get(l[0]))==null?void 0:T.id,b=t.external.uri??(A=>A);if(x)return{ref:b(x)};const y=l[1].defId??l[1].schema.id??`schema${t.counter++}`;return l[1].defId=y,{defId:y,ref:`${b("__shared")}#/${f}/${y}`}}if(l[1]===n)return{ref:"#"};const m=`#/${f}/`,v=l[1].schema.id??`__schema${t.counter++}`;return{defId:v,ref:m+v}},i=l=>{if(l[1].schema.$ref)return;const f=l[1],{ref:p,defId:m}=s(l);f.def={...f.schema},m&&(f.defId=m);const v=f.schema;for(const T in v)delete v[T];v.$ref=p};if(t.cycles==="throw")for(const l of t.seen.entries()){const f=l[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
|
|
38
38
|
|
|
39
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const l of t.seen.entries()){const d=l[1];if(e===l[0]){i(l);continue}if(t.external){const m=(c=t.external.registry.get(l[0]))==null?void 0:c.id;if(e!==l[0]&&m){i(l);continue}}if((u=t.metadataRegistry.get(l[0]))==null?void 0:u.id){i(l);continue}if(d.cycle){i(l);continue}if(d.count>1&&t.reused==="ref"){i(l);continue}}}function Ht(t,e){var o,a,c;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=u=>{const l=t.seen.get(u);if(l.ref===null)return;const d=l.def??l.schema,p={...d},m=l.ref;if(l.ref=null,m){r(m);const T=t.seen.get(m),j=T.schema;if(j.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(d.allOf=d.allOf??[],d.allOf.push(j)):Object.assign(d,j),Object.assign(d,p),u._zod.parent===m)for(const v in d)v==="$ref"||v==="allOf"||v in p||delete d[v];if(j.$ref&&T.def)for(const v in d)v==="$ref"||v==="allOf"||v in T.def&&JSON.stringify(d[v])===JSON.stringify(T.def[v])&&delete d[v]}const S=u._zod.parent;if(S&&S!==m){r(S);const T=t.seen.get(S);if(T!=null&&T.schema.$ref&&(d.$ref=T.schema.$ref,T.def))for(const j in d)j==="$ref"||j==="allOf"||j in T.def&&JSON.stringify(d[j])===JSON.stringify(T.def[j])&&delete d[j]}t.override({zodSchema:u,jsonSchema:d,path:l.path??[]})};for(const u of[...t.seen.entries()].reverse())r(u[0]);const s={};if(t.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":t.target,(o=t.external)!=null&&o.uri){const u=(a=t.external.registry.get(e))==null?void 0:a.id;if(!u)throw new Error("Schema is missing an `id` property");s.$id=t.external.uri(u)}Object.assign(s,n.def??n.schema);const i=((c=t.external)==null?void 0:c.defs)??{};for(const u of t.seen.entries()){const l=u[1];l.def&&l.defId&&(i[l.defId]=l.def)}t.external||Object.keys(i).length>0&&(t.target==="draft-2020-12"?s.$defs=i:s.definitions=i);try{const u=JSON.parse(JSON.stringify(s));return Object.defineProperty(u,"~standard",{value:{...e["~standard"],jsonSchema:{input:Jt(e,"input",t.processors),output:Jt(e,"output",t.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function ve(t,e){const n=e??{seen:new Set};if(n.seen.has(t))return!1;n.seen.add(t);const r=t._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return ve(r.element,n);if(r.type==="set")return ve(r.valueType,n);if(r.type==="lazy")return ve(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return ve(r.innerType,n);if(r.type==="intersection")return ve(r.left,n)||ve(r.right,n);if(r.type==="record"||r.type==="map")return ve(r.keyType,n)||ve(r.valueType,n);if(r.type==="pipe")return ve(r.in,n)||ve(r.out,n);if(r.type==="object"){for(const s in r.shape)if(ve(r.shape[s],n))return!0;return!1}if(r.type==="union"){for(const s of r.options)if(ve(s,n))return!0;return!1}if(r.type==="tuple"){for(const s of r.items)if(ve(s,n))return!0;return!!(r.rest&&ve(r.rest,n))}return!1}const fu=(t,e={})=>n=>{const r=Ut({...n,processors:e});return Q(t,r),Vt(r,t),Ht(r,t)},Jt=(t,e,n={})=>r=>{const{libraryOptions:s,target:i}=r??{},o=Ut({...s??{},target:i,io:e,processors:n});return Q(t,o),Vt(o,t),Ht(o,t)},hu={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Gs=(t,e,n,r)=>{const s=n;s.type="string";const{minimum:i,maximum:o,format:a,patterns:c,contentEncoding:u}=t._zod.bag;if(typeof i=="number"&&(s.minLength=i),typeof o=="number"&&(s.maxLength=o),a&&(s.format=hu[a]??a,s.format===""&&delete s.format,a==="time"&&delete s.format),u&&(s.contentEncoding=u),c&&c.size>0){const l=[...c];l.length===1?s.pattern=l[0].source:l.length>1&&(s.allOf=[...l.map(d=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))])}},Ks=(t,e,n,r)=>{const s=n,{minimum:i,maximum:o,format:a,multipleOf:c,exclusiveMaximum:u,exclusiveMinimum:l}=t._zod.bag;typeof a=="string"&&a.includes("int")?s.type="integer":s.type="number",typeof l=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.minimum=l,s.exclusiveMinimum=!0):s.exclusiveMinimum=l),typeof i=="number"&&(s.minimum=i,typeof l=="number"&&e.target!=="draft-04"&&(l>=i?delete s.minimum:delete s.exclusiveMinimum)),typeof u=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.maximum=u,s.exclusiveMaximum=!0):s.exclusiveMaximum=u),typeof o=="number"&&(s.maximum=o,typeof u=="number"&&e.target!=="draft-04"&&(u<=o?delete s.maximum:delete s.exclusiveMaximum)),typeof c=="number"&&(s.multipleOf=c)},Ys=(t,e,n,r)=>{n.type="boolean"},mu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema")},pu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema")},Qs=(t,e,n,r)=>{e.target==="openapi-3.0"?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"},gu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema")},_u=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema")},Xs=(t,e,n,r)=>{n.not={}},yu=(t,e,n,r)=>{},ei=(t,e,n,r)=>{},vu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema")},ti=(t,e,n,r)=>{const s=t._zod.def,i=Rs(s.entries);i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},ni=(t,e,n,r)=>{const s=t._zod.def,i=[];for(const o of s.values)if(o===void 0){if(e.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(e.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,e.target==="draft-04"||e.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},bu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema")},wu=(t,e,n,r)=>{const s=n,i=t._zod.pattern;if(!i)throw new Error("Pattern not found in template literal");s.type="string",s.pattern=i.source},ku=(t,e,n,r)=>{const s=n,i={type:"string",format:"binary",contentEncoding:"binary"},{minimum:o,maximum:a,mime:c}=t._zod.bag;o!==void 0&&(i.minLength=o),a!==void 0&&(i.maxLength=a),c?c.length===1?(i.contentMediaType=c[0],Object.assign(s,i)):(Object.assign(s,i),s.anyOf=c.map(u=>({contentMediaType:u}))):Object.assign(s,i)},Su=(t,e,n,r)=>{n.type="boolean"},ri=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},Tu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Function types cannot be represented in JSON Schema")},si=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},zu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema")},$u=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema")},ii=(t,e,n,r)=>{const s=n,i=t._zod.def,{minimum:o,maximum:a}=t._zod.bag;typeof o=="number"&&(s.minItems=o),typeof a=="number"&&(s.maxItems=a),s.type="array",s.items=Q(i.element,e,{...r,path:[...r.path,"items"]})},oi=(t,e,n,r)=>{var u;const s=n,i=t._zod.def;s.type="object",s.properties={};const o=i.shape;for(const l in o)s.properties[l]=Q(o[l],e,{...r,path:[...r.path,"properties",l]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(l=>{const d=i.shape[l]._zod;return e.io==="input"?d.optin===void 0:d.optout===void 0}));c.size>0&&(s.required=Array.from(c)),((u=i.catchall)==null?void 0:u._zod.def.type)==="never"?s.additionalProperties=!1:i.catchall?i.catchall&&(s.additionalProperties=Q(i.catchall,e,{...r,path:[...r.path,"additionalProperties"]})):e.io==="output"&&(s.additionalProperties=!1)},ai=(t,e,n,r)=>{const s=t._zod.def,i=s.inclusive===!1,o=s.options.map((a,c)=>Q(a,e,{...r,path:[...r.path,i?"oneOf":"anyOf",c]}));i?n.oneOf=o:n.anyOf=o},ci=(t,e,n,r)=>{const s=t._zod.def,i=Q(s.left,e,{...r,path:[...r.path,"allOf",0]}),o=Q(s.right,e,{...r,path:[...r.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,c=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=c},Pu=(t,e,n,r)=>{const s=n,i=t._zod.def;s.type="array";const o=e.target==="draft-2020-12"?"prefixItems":"items",a=e.target==="draft-2020-12"||e.target==="openapi-3.0"?"items":"additionalItems",c=i.items.map((p,m)=>Q(p,e,{...r,path:[...r.path,o,m]})),u=i.rest?Q(i.rest,e,{...r,path:[...r.path,a,...e.target==="openapi-3.0"?[i.items.length]:[]]}):null;e.target==="draft-2020-12"?(s.prefixItems=c,u&&(s.items=u)):e.target==="openapi-3.0"?(s.items={anyOf:c},u&&s.items.anyOf.push(u),s.minItems=c.length,u||(s.maxItems=c.length)):(s.items=c,u&&(s.additionalItems=u));const{minimum:l,maximum:d}=t._zod.bag;typeof l=="number"&&(s.minItems=l),typeof d=="number"&&(s.maxItems=d)},ui=(t,e,n,r)=>{const s=n,i=t._zod.def;s.type="object";const o=i.keyType,a=o._zod.bag,c=a==null?void 0:a.patterns;if(i.mode==="loose"&&c&&c.size>0){const l=Q(i.valueType,e,{...r,path:[...r.path,"patternProperties","*"]});s.patternProperties={};for(const d of c)s.patternProperties[d.source]=l}else(e.target==="draft-07"||e.target==="draft-2020-12")&&(s.propertyNames=Q(i.keyType,e,{...r,path:[...r.path,"propertyNames"]})),s.additionalProperties=Q(i.valueType,e,{...r,path:[...r.path,"additionalProperties"]});const u=o._zod.values;if(u){const l=[...u].filter(d=>typeof d=="string"||typeof d=="number");l.length>0&&(s.required=l)}},li=(t,e,n,r)=>{const s=t._zod.def,i=Q(s.innerType,e,r),o=e.seen.get(t);e.target==="openapi-3.0"?(o.ref=s.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},di=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},fi=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},hi=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,e.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},mi=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType;let o;try{o=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},pi=(t,e,n,r)=>{const s=t._zod.def,i=e.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;Q(i,e,r);const o=e.seen.get(t);o.ref=i},gi=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,n.readOnly=!0},Ru=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},tr=(t,e,n,r)=>{const s=t._zod.def;Q(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},Nu=(t,e,n,r)=>{const s=t._zod.innerType;Q(s,e,r);const i=e.seen.get(t);i.ref=s},Ur={string:Gs,number:Ks,boolean:Ys,bigint:mu,symbol:pu,null:Qs,undefined:gu,void:_u,never:Xs,any:yu,unknown:ei,date:vu,enum:ti,literal:ni,nan:bu,template_literal:wu,file:ku,success:Su,custom:ri,function:Tu,transform:si,map:zu,set:$u,array:ii,object:oi,union:ai,intersection:ci,tuple:Pu,record:ui,nullable:li,nonoptional:di,default:fi,prefault:hi,catch:mi,pipe:pi,readonly:gi,promise:Ru,optional:tr,lazy:Nu};function Eu(t,e){if("_idmap"in t){const r=t,s=Ut({...e,processors:Ur}),i={};for(const c of r._idmap.entries()){const[u,l]=c;Q(l,s)}const o={},a={registry:r,uri:e==null?void 0:e.uri,defs:i};s.external=a;for(const c of r._idmap.entries()){const[u,l]=c;Vt(s,l),o[u]=Ht(s,l)}if(Object.keys(i).length>0){const c=s.target==="draft-2020-12"?"$defs":"definitions";o.__shared={[c]:i}}return{schemas:o}}const n=Ut({...e,processors:Ur});return Q(t,n),Vt(n,t),Ht(n,t)}const Cu=_("ZodISODateTime",(t,e)=>{xa.init(t,e),oe.init(t,e)});function _i(t){return Dc(Cu,t)}const Iu=_("ZodISODate",(t,e)=>{Za.init(t,e),oe.init(t,e)});function Ou(t){return qc(Iu,t)}const xu=_("ZodISOTime",(t,e)=>{Aa.init(t,e),oe.init(t,e)});function Zu(t){return Fc(xu,t)}const Au=_("ZodISODuration",(t,e)=>{ja.init(t,e),oe.init(t,e)});function ju(t){return Uc(Au,t)}const Mu=(t,e)=>{Is.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>$o(t,n)},flatten:{value:n=>zo(t,n)},addIssue:{value:n=>{t.issues.push(n),t.message=JSON.stringify(t.issues,$n,2)}},addIssues:{value:n=>{t.issues.push(...n),t.message=JSON.stringify(t.issues,$n,2)}},isEmpty:{get(){return t.issues.length===0}}})},Pe=_("ZodError",Mu,{Parent:Error}),Lu=un(Pe),Du=ln(Pe),qu=dn(Pe),Fu=fn(Pe),Uu=No(Pe),Vu=Eo(Pe),Hu=Co(Pe),Ju=Io(Pe),Bu=Oo(Pe),Wu=xo(Pe),Gu=Zo(Pe),Ku=Ao(Pe),re=_("ZodType",(t,e)=>(X.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:Jt(t,"input"),output:Jt(t,"output")}}),t.toJSONSchema=fu(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone(He(e,{checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),t.with=t.check,t.clone=(n,r)=>Me(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t),t.parse=(n,r)=>Lu(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>qu(t,n,r),t.parseAsync=async(n,r)=>Du(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>Fu(t,n,r),t.spa=t.safeParseAsync,t.encode=(n,r)=>Uu(t,n,r),t.decode=(n,r)=>Vu(t,n,r),t.encodeAsync=async(n,r)=>Hu(t,n,r),t.decodeAsync=async(n,r)=>Ju(t,n,r),t.safeEncode=(n,r)=>Bu(t,n,r),t.safeDecode=(n,r)=>Wu(t,n,r),t.safeEncodeAsync=async(n,r)=>Gu(t,n,r),t.safeDecodeAsync=async(n,r)=>Ku(t,n,r),t.refine=(n,r)=>t.check(ql(n,r)),t.superRefine=n=>t.check(Fl(n)),t.overwrite=n=>t.check(ht(n)),t.optional=()=>ce(t),t.exactOptional=()=>Rl(t),t.nullable=()=>Jr(t),t.nullish=()=>ce(Jr(t)),t.nonoptional=n=>xl(t,n),t.array=()=>V(t),t.or=n=>ee([t,n]),t.and=n=>nr(t,n),t.transform=n=>Nn(t,Ti(n)),t.default=n=>Cl(t,n),t.prefault=n=>Ol(t,n),t.catch=n=>Al(t,n),t.pipe=n=>Nn(t,n),t.readonly=()=>Ll(t),t.describe=n=>{const r=t.clone();return vt.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){var n;return(n=vt.get(t))==null?void 0:n.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return vt.get(t);const r=t.clone();return vt.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t.apply=n=>n(t),t)),yi=_("_ZodString",(t,e)=>{er.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>Gs(t,r,s);const n=t._zod.bag;t.format=n.format??null,t.minLength=n.minimum??null,t.maxLength=n.maximum??null,t.regex=(...r)=>t.check(Kc(...r)),t.includes=(...r)=>t.check(Xc(...r)),t.startsWith=(...r)=>t.check(eu(...r)),t.endsWith=(...r)=>t.check(tu(...r)),t.min=(...r)=>t.check(Ft(...r)),t.max=(...r)=>t.check(Bs(...r)),t.length=(...r)=>t.check(Ws(...r)),t.nonempty=(...r)=>t.check(Ft(1,...r)),t.lowercase=r=>t.check(Yc(r)),t.uppercase=r=>t.check(Qc(r)),t.trim=()=>t.check(ru()),t.normalize=(...r)=>t.check(nu(...r)),t.toLowerCase=()=>t.check(su()),t.toUpperCase=()=>t.check(iu()),t.slugify=()=>t.check(ou())}),Yu=_("ZodString",(t,e)=>{er.init(t,e),yi.init(t,e),t.email=n=>t.check(vc(Qu,n)),t.url=n=>t.check(Tc(Xu,n)),t.jwt=n=>t.check(Lc(ml,n)),t.emoji=n=>t.check(zc(el,n)),t.guid=n=>t.check(Lr(Vr,n)),t.uuid=n=>t.check(bc(Mt,n)),t.uuidv4=n=>t.check(wc(Mt,n)),t.uuidv6=n=>t.check(kc(Mt,n)),t.uuidv7=n=>t.check(Sc(Mt,n)),t.nanoid=n=>t.check($c(tl,n)),t.guid=n=>t.check(Lr(Vr,n)),t.cuid=n=>t.check(Pc(nl,n)),t.cuid2=n=>t.check(Rc(rl,n)),t.ulid=n=>t.check(Nc(sl,n)),t.base64=n=>t.check(Ac(dl,n)),t.base64url=n=>t.check(jc(fl,n)),t.xid=n=>t.check(Ec(il,n)),t.ksuid=n=>t.check(Cc(ol,n)),t.ipv4=n=>t.check(Ic(al,n)),t.ipv6=n=>t.check(Oc(cl,n)),t.cidrv4=n=>t.check(xc(ul,n)),t.cidrv6=n=>t.check(Zc(ll,n)),t.e164=n=>t.check(Mc(hl,n)),t.datetime=n=>t.check(_i(n)),t.date=n=>t.check(Ou(n)),t.time=n=>t.check(Zu(n)),t.duration=n=>t.check(ju(n))});function g(t){return yc(Yu,t)}const oe=_("ZodStringFormat",(t,e)=>{ne.init(t,e),yi.init(t,e)}),Qu=_("ZodEmail",(t,e)=>{za.init(t,e),oe.init(t,e)}),Vr=_("ZodGUID",(t,e)=>{Sa.init(t,e),oe.init(t,e)}),Mt=_("ZodUUID",(t,e)=>{Ta.init(t,e),oe.init(t,e)}),Xu=_("ZodURL",(t,e)=>{$a.init(t,e),oe.init(t,e)}),el=_("ZodEmoji",(t,e)=>{Pa.init(t,e),oe.init(t,e)}),tl=_("ZodNanoID",(t,e)=>{Ra.init(t,e),oe.init(t,e)}),nl=_("ZodCUID",(t,e)=>{Na.init(t,e),oe.init(t,e)}),rl=_("ZodCUID2",(t,e)=>{Ea.init(t,e),oe.init(t,e)}),sl=_("ZodULID",(t,e)=>{Ca.init(t,e),oe.init(t,e)}),il=_("ZodXID",(t,e)=>{Ia.init(t,e),oe.init(t,e)}),ol=_("ZodKSUID",(t,e)=>{Oa.init(t,e),oe.init(t,e)}),al=_("ZodIPv4",(t,e)=>{Ma.init(t,e),oe.init(t,e)}),cl=_("ZodIPv6",(t,e)=>{La.init(t,e),oe.init(t,e)}),ul=_("ZodCIDRv4",(t,e)=>{Da.init(t,e),oe.init(t,e)}),ll=_("ZodCIDRv6",(t,e)=>{qa.init(t,e),oe.init(t,e)}),dl=_("ZodBase64",(t,e)=>{Fa.init(t,e),oe.init(t,e)}),fl=_("ZodBase64URL",(t,e)=>{Va.init(t,e),oe.init(t,e)}),hl=_("ZodE164",(t,e)=>{Ha.init(t,e),oe.init(t,e)}),ml=_("ZodJWT",(t,e)=>{Ba.init(t,e),oe.init(t,e)}),vi=_("ZodNumber",(t,e)=>{qs.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>Ks(t,r,s),t.gt=(r,s)=>t.check(qr(r,s)),t.gte=(r,s)=>t.check(bn(r,s)),t.min=(r,s)=>t.check(bn(r,s)),t.lt=(r,s)=>t.check(Dr(r,s)),t.lte=(r,s)=>t.check(vn(r,s)),t.max=(r,s)=>t.check(vn(r,s)),t.int=r=>t.check(Hr(r)),t.safe=r=>t.check(Hr(r)),t.positive=r=>t.check(qr(0,r)),t.nonnegative=r=>t.check(bn(0,r)),t.negative=r=>t.check(Dr(0,r)),t.nonpositive=r=>t.check(vn(0,r)),t.multipleOf=(r,s)=>t.check(Fr(r,s)),t.step=(r,s)=>t.check(Fr(r,s)),t.finite=()=>t;const n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null});function Y(t){return Vc(vi,t)}const pl=_("ZodNumberFormat",(t,e)=>{Wa.init(t,e),vi.init(t,e)});function Hr(t){return Hc(pl,t)}const gl=_("ZodBoolean",(t,e)=>{Ga.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Ys(t,n,r)});function he(t){return Jc(gl,t)}const _l=_("ZodNull",(t,e)=>{Ka.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Qs(t,n,r)});function bi(t){return Bc(_l,t)}const yl=_("ZodUnknown",(t,e)=>{Ya.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ei()});function se(){return Wc(yl)}const vl=_("ZodNever",(t,e)=>{Qa.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Xs(t,n,r)});function bl(t){return Gc(vl,t)}const wl=_("ZodArray",(t,e)=>{Xa.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ii(t,n,r,s),t.element=e.element,t.min=(n,r)=>t.check(Ft(n,r)),t.nonempty=n=>t.check(Ft(1,n)),t.max=(n,r)=>t.check(Bs(n,r)),t.length=(n,r)=>t.check(Ws(n,r)),t.unwrap=()=>t.element});function V(t,e){return au(wl,t,e)}const wi=_("ZodObject",(t,e)=>{ec.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>oi(t,n,r,s),B(t,"shape",()=>e.shape),t.keyof=()=>ze(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:se()}),t.loose=()=>t.clone({...t._zod.def,catchall:se()}),t.strict=()=>t.clone({...t._zod.def,catchall:bl()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>bo(t,n),t.safeExtend=n=>wo(t,n),t.merge=n=>ko(t,n),t.pick=n=>yo(t,n),t.omit=n=>vo(t,n),t.partial=(...n)=>So(zi,t,n[0]),t.required=(...n)=>To($i,t,n[0])});function $(t,e){const n={type:"object",shape:t??{},...N(e)};return new wi(n)}function we(t,e){return new wi({type:"object",shape:t,catchall:se(),...N(e)})}const ki=_("ZodUnion",(t,e)=>{Hs.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ai(t,n,r,s),t.options=e.options});function ee(t,e){return new ki({type:"union",options:t,...N(e)})}const kl=_("ZodDiscriminatedUnion",(t,e)=>{ki.init(t,e),tc.init(t,e)});function Si(t,e,n){return new kl({type:"union",options:e,discriminator:t,...N(n)})}const Sl=_("ZodIntersection",(t,e)=>{nc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ci(t,n,r,s)});function nr(t,e){return new Sl({type:"intersection",left:t,right:e})}const Tl=_("ZodRecord",(t,e)=>{rc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ui(t,n,r,s),t.keyType=e.keyType,t.valueType=e.valueType});function ie(t,e,n){return new Tl({type:"record",keyType:t,valueType:e,...N(n)})}const Rn=_("ZodEnum",(t,e)=>{sc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>ti(t,r,s),t.enum=e.entries,t.options=Object.values(e.entries);const n=new Set(Object.keys(e.entries));t.extract=(r,s)=>{const i={};for(const o of r)if(n.has(o))i[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Rn({...e,checks:[],...N(s),entries:i})},t.exclude=(r,s)=>{const i={...e.entries};for(const o of r)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Rn({...e,checks:[],...N(s),entries:i})}});function ze(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new Rn({type:"enum",entries:n,...N(e)})}const zl=_("ZodLiteral",(t,e)=>{ic.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ni(t,n,r),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function I(t,e){return new zl({type:"literal",values:Array.isArray(t)?t:[t],...N(e)})}const $l=_("ZodTransform",(t,e)=>{oc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>si(t,n),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new $s(t.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(St(i,n.value,e));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),n.issues.push(St(o))}};const s=e.transform(n.value,n);return s instanceof Promise?s.then(i=>(n.value=i,n)):(n.value=s,n)}});function Ti(t){return new $l({type:"transform",transform:t})}const zi=_("ZodOptional",(t,e)=>{Js.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>tr(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function ce(t){return new zi({type:"optional",innerType:t})}const Pl=_("ZodExactOptional",(t,e)=>{ac.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>tr(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Rl(t){return new Pl({type:"optional",innerType:t})}const Nl=_("ZodNullable",(t,e)=>{cc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>li(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Jr(t){return new Nl({type:"nullable",innerType:t})}const El=_("ZodDefault",(t,e)=>{uc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>fi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function Cl(t,e){return new El({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Es(e)}})}const Il=_("ZodPrefault",(t,e)=>{lc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>hi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Ol(t,e){return new Il({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Es(e)}})}const $i=_("ZodNonOptional",(t,e)=>{dc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>di(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function xl(t,e){return new $i({type:"nonoptional",innerType:t,...N(e)})}const Zl=_("ZodCatch",(t,e)=>{fc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>mi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function Al(t,e){return new Zl({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const jl=_("ZodPipe",(t,e)=>{hc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>pi(t,n,r,s),t.in=e.in,t.out=e.out});function Nn(t,e){return new jl({type:"pipe",in:t,out:e})}const Ml=_("ZodReadonly",(t,e)=>{mc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>gi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Ll(t){return new Ml({type:"readonly",innerType:t})}const Pi=_("ZodCustom",(t,e)=>{pc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ri(t,n)});function Dl(t,e){return cu(Pi,t??(()=>!0),e)}function ql(t,e={}){return uu(Pi,t,e)}function Fl(t){return lu(t)}function Ri(t,e){return Nn(Ti(t),e)}const Ni="2025-11-25",Ul=[Ni,"2025-06-18","2025-03-26","2024-11-05","2024-10-07"],Ye="io.modelcontextprotocol/related-task",mn="2.0",me=Dl(t=>t!==null&&(typeof t=="object"||typeof t=="function")),Ei=ee([g(),Y().int()]),Ci=g();we({ttl:ee([Y(),bi()]).optional(),pollInterval:Y().optional()});const Vl=$({ttl:Y().optional()}),Hl=$({taskId:g()}),rr=we({progressToken:Ei.optional(),[Ye]:Hl.optional()}),$e=$({_meta:rr.optional()}),Pt=$e.extend({task:Vl.optional()}),Jl=t=>Pt.safeParse(t).success,pe=$({method:g(),params:$e.loose().optional()}),Re=$({_meta:rr.optional()}),Ne=$({method:g(),params:Re.loose().optional()}),ge=we({_meta:rr.optional()}),pn=ee([g(),Y().int()]),Ii=$({jsonrpc:I(mn),id:pn,...pe.shape}).strict(),Br=t=>Ii.safeParse(t).success,Oi=$({jsonrpc:I(mn),...Ne.shape}).strict(),Bl=t=>Oi.safeParse(t).success,sr=$({jsonrpc:I(mn),id:pn,result:ge}).strict(),Lt=t=>sr.safeParse(t).success;var x;(function(t){t[t.ConnectionClosed=-32e3]="ConnectionClosed",t[t.RequestTimeout=-32001]="RequestTimeout",t[t.ParseError=-32700]="ParseError",t[t.InvalidRequest=-32600]="InvalidRequest",t[t.MethodNotFound=-32601]="MethodNotFound",t[t.InvalidParams=-32602]="InvalidParams",t[t.InternalError=-32603]="InternalError",t[t.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(x||(x={}));const ir=$({jsonrpc:I(mn),id:pn.optional(),error:$({code:Y().int(),message:g(),data:se().optional()})}).strict(),Wl=t=>ir.safeParse(t).success,Gl=ee([Ii,Oi,sr,ir]);ee([sr,ir]);const or=ge.strict(),Kl=Re.extend({requestId:pn.optional(),reason:g().optional()}),ar=Ne.extend({method:I("notifications/cancelled"),params:Kl}),Yl=$({src:g(),mimeType:g().optional(),sizes:V(g()).optional(),theme:ze(["light","dark"]).optional()}),Rt=$({icons:V(Yl).optional()}),ct=$({name:g(),title:g().optional()}),xi=ct.extend({...ct.shape,...Rt.shape,version:g(),websiteUrl:g().optional(),description:g().optional()}),Ql=nr($({applyDefaults:he().optional()}),ie(g(),se())),Xl=Ri(t=>t&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0?{form:{}}:t,nr($({form:Ql.optional(),url:me.optional()}),ie(g(),se()).optional())),ed=we({list:me.optional(),cancel:me.optional(),requests:we({sampling:we({createMessage:me.optional()}).optional(),elicitation:we({create:me.optional()}).optional()}).optional()}),td=we({list:me.optional(),cancel:me.optional(),requests:we({tools:we({call:me.optional()}).optional()}).optional()}),nd=$({experimental:ie(g(),me).optional(),sampling:$({context:me.optional(),tools:me.optional()}).optional(),elicitation:Xl.optional(),roots:$({listChanged:he().optional()}).optional(),tasks:ed.optional()}),rd=$e.extend({protocolVersion:g(),capabilities:nd,clientInfo:xi}),Zi=pe.extend({method:I("initialize"),params:rd}),sd=$({experimental:ie(g(),me).optional(),logging:me.optional(),completions:me.optional(),prompts:$({listChanged:he().optional()}).optional(),resources:$({subscribe:he().optional(),listChanged:he().optional()}).optional(),tools:$({listChanged:he().optional()}).optional(),tasks:td.optional()}),id=ge.extend({protocolVersion:g(),capabilities:sd,serverInfo:xi,instructions:g().optional()}),Ai=Ne.extend({method:I("notifications/initialized"),params:Re.optional()}),cr=pe.extend({method:I("ping"),params:$e.optional()}),od=$({progress:Y(),total:ce(Y()),message:ce(g())}),ad=$({...Re.shape,...od.shape,progressToken:Ei}),ur=Ne.extend({method:I("notifications/progress"),params:ad}),cd=$e.extend({cursor:Ci.optional()}),Nt=pe.extend({params:cd.optional()}),Et=ge.extend({nextCursor:Ci.optional()}),ud=ze(["working","input_required","completed","failed","cancelled"]),Ct=$({taskId:g(),status:ud,ttl:ee([Y(),bi()]),createdAt:g(),lastUpdatedAt:g(),pollInterval:ce(Y()),statusMessage:ce(g())}),gn=ge.extend({task:Ct}),ld=Re.merge(Ct),Bt=Ne.extend({method:I("notifications/tasks/status"),params:ld}),lr=pe.extend({method:I("tasks/get"),params:$e.extend({taskId:g()})}),dr=ge.merge(Ct),fr=pe.extend({method:I("tasks/result"),params:$e.extend({taskId:g()})});ge.loose();const hr=Nt.extend({method:I("tasks/list")}),mr=Et.extend({tasks:V(Ct)}),pr=pe.extend({method:I("tasks/cancel"),params:$e.extend({taskId:g()})}),dd=ge.merge(Ct),ji=$({uri:g(),mimeType:ce(g()),_meta:ie(g(),se()).optional()}),Mi=ji.extend({text:g()}),gr=g().refine(t=>{try{return atob(t),!0}catch{return!1}},{message:"Invalid Base64 string"}),Li=ji.extend({blob:gr}),It=ze(["user","assistant"]),mt=$({audience:V(It).optional(),priority:Y().min(0).max(1).optional(),lastModified:_i({offset:!0}).optional()}),Di=$({...ct.shape,...Rt.shape,uri:g(),description:ce(g()),mimeType:ce(g()),annotations:mt.optional(),_meta:ce(we({}))}),fd=$({...ct.shape,...Rt.shape,uriTemplate:g(),description:ce(g()),mimeType:ce(g()),annotations:mt.optional(),_meta:ce(we({}))}),En=Nt.extend({method:I("resources/list")}),hd=Et.extend({resources:V(Di)}),Cn=Nt.extend({method:I("resources/templates/list")}),md=Et.extend({resourceTemplates:V(fd)}),_r=$e.extend({uri:g()}),pd=_r,In=pe.extend({method:I("resources/read"),params:pd}),gd=ge.extend({contents:V(ee([Mi,Li]))}),_d=Ne.extend({method:I("notifications/resources/list_changed"),params:Re.optional()}),yd=_r,vd=pe.extend({method:I("resources/subscribe"),params:yd}),bd=_r,wd=pe.extend({method:I("resources/unsubscribe"),params:bd}),kd=Re.extend({uri:g()}),Sd=Ne.extend({method:I("notifications/resources/updated"),params:kd}),Td=$({name:g(),description:ce(g()),required:ce(he())}),zd=$({...ct.shape,...Rt.shape,description:ce(g()),arguments:ce(V(Td)),_meta:ce(we({}))}),On=Nt.extend({method:I("prompts/list")}),$d=Et.extend({prompts:V(zd)}),Pd=$e.extend({name:g(),arguments:ie(g(),g()).optional()}),xn=pe.extend({method:I("prompts/get"),params:Pd}),yr=$({type:I("text"),text:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),vr=$({type:I("image"),data:gr,mimeType:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),br=$({type:I("audio"),data:gr,mimeType:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),Rd=$({type:I("tool_use"),name:g(),id:g(),input:ie(g(),se()),_meta:ie(g(),se()).optional()}),Nd=$({type:I("resource"),resource:ee([Mi,Li]),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),Ed=Di.extend({type:I("resource_link")}),wr=ee([yr,vr,br,Ed,Nd]),Cd=$({role:It,content:wr}),Id=ge.extend({description:g().optional(),messages:V(Cd)}),Od=Ne.extend({method:I("notifications/prompts/list_changed"),params:Re.optional()}),xd=$({title:g().optional(),readOnlyHint:he().optional(),destructiveHint:he().optional(),idempotentHint:he().optional(),openWorldHint:he().optional()}),Zd=$({taskSupport:ze(["required","optional","forbidden"]).optional()}),qi=$({...ct.shape,...Rt.shape,description:g().optional(),inputSchema:$({type:I("object"),properties:ie(g(),me).optional(),required:V(g()).optional()}).catchall(se()),outputSchema:$({type:I("object"),properties:ie(g(),me).optional(),required:V(g()).optional()}).catchall(se()).optional(),annotations:xd.optional(),execution:Zd.optional(),_meta:ie(g(),se()).optional()}),Zn=Nt.extend({method:I("tools/list")}),Ad=Et.extend({tools:V(qi)}),kr=ge.extend({content:V(wr).default([]),structuredContent:ie(g(),se()).optional(),isError:he().optional()});kr.or(ge.extend({toolResult:se()}));const jd=Pt.extend({name:g(),arguments:ie(g(),se()).optional()}),Wt=pe.extend({method:I("tools/call"),params:jd}),Md=Ne.extend({method:I("notifications/tools/list_changed"),params:Re.optional()});$({autoRefresh:he().default(!0),debounceMs:Y().int().nonnegative().default(300)});const Gt=ze(["debug","info","notice","warning","error","critical","alert","emergency"]),Ld=$e.extend({level:Gt}),Fi=pe.extend({method:I("logging/setLevel"),params:Ld}),Dd=Re.extend({level:Gt,logger:g().optional(),data:se()}),qd=Ne.extend({method:I("notifications/message"),params:Dd}),Fd=$({name:g().optional()}),Ud=$({hints:V(Fd).optional(),costPriority:Y().min(0).max(1).optional(),speedPriority:Y().min(0).max(1).optional(),intelligencePriority:Y().min(0).max(1).optional()}),Vd=$({mode:ze(["auto","required","none"]).optional()}),Hd=$({type:I("tool_result"),toolUseId:g().describe("The unique identifier for the corresponding tool call."),content:V(wr).default([]),structuredContent:$({}).loose().optional(),isError:he().optional(),_meta:ie(g(),se()).optional()}),Jd=Si("type",[yr,vr,br]),Kt=Si("type",[yr,vr,br,Rd,Hd]),Bd=$({role:It,content:ee([Kt,V(Kt)]),_meta:ie(g(),se()).optional()}),Wd=Pt.extend({messages:V(Bd),modelPreferences:Ud.optional(),systemPrompt:g().optional(),includeContext:ze(["none","thisServer","allServers"]).optional(),temperature:Y().optional(),maxTokens:Y().int(),stopSequences:V(g()).optional(),metadata:me.optional(),tools:V(qi).optional(),toolChoice:Vd.optional()}),Gd=pe.extend({method:I("sampling/createMessage"),params:Wd}),Sr=ge.extend({model:g(),stopReason:ce(ze(["endTurn","stopSequence","maxTokens"]).or(g())),role:It,content:Jd}),Ui=ge.extend({model:g(),stopReason:ce(ze(["endTurn","stopSequence","maxTokens","toolUse"]).or(g())),role:It,content:ee([Kt,V(Kt)])}),Kd=$({type:I("boolean"),title:g().optional(),description:g().optional(),default:he().optional()}),Yd=$({type:I("string"),title:g().optional(),description:g().optional(),minLength:Y().optional(),maxLength:Y().optional(),format:ze(["email","uri","date","date-time"]).optional(),default:g().optional()}),Qd=$({type:ze(["number","integer"]),title:g().optional(),description:g().optional(),minimum:Y().optional(),maximum:Y().optional(),default:Y().optional()}),Xd=$({type:I("string"),title:g().optional(),description:g().optional(),enum:V(g()),default:g().optional()}),ef=$({type:I("string"),title:g().optional(),description:g().optional(),oneOf:V($({const:g(),title:g()})),default:g().optional()}),tf=$({type:I("string"),title:g().optional(),description:g().optional(),enum:V(g()),enumNames:V(g()).optional(),default:g().optional()}),nf=ee([Xd,ef]),rf=$({type:I("array"),title:g().optional(),description:g().optional(),minItems:Y().optional(),maxItems:Y().optional(),items:$({type:I("string"),enum:V(g())}),default:V(g()).optional()}),sf=$({type:I("array"),title:g().optional(),description:g().optional(),minItems:Y().optional(),maxItems:Y().optional(),items:$({anyOf:V($({const:g(),title:g()}))}),default:V(g()).optional()}),of=ee([rf,sf]),af=ee([tf,nf,of]),cf=ee([af,Kd,Yd,Qd]),uf=Pt.extend({mode:I("form").optional(),message:g(),requestedSchema:$({type:I("object"),properties:ie(g(),cf),required:V(g()).optional()})}),lf=Pt.extend({mode:I("url"),message:g(),elicitationId:g(),url:g().url()}),df=ee([uf,lf]),ff=pe.extend({method:I("elicitation/create"),params:df}),hf=Re.extend({elicitationId:g()}),mf=Ne.extend({method:I("notifications/elicitation/complete"),params:hf}),Yt=ge.extend({action:ze(["accept","decline","cancel"]),content:Ri(t=>t===null?void 0:t,ie(g(),ee([g(),Y(),he(),V(g())])).optional())}),pf=$({type:I("ref/resource"),uri:g()}),gf=$({type:I("ref/prompt"),name:g()}),_f=$e.extend({ref:ee([gf,pf]),argument:$({name:g(),value:g()}),context:$({arguments:ie(g(),g()).optional()}).optional()}),An=pe.extend({method:I("completion/complete"),params:_f});function yf(t){if(t.params.ref.type!=="ref/prompt")throw new TypeError(`Expected CompleteRequestPrompt, but got ${t.params.ref.type}`)}function vf(t){if(t.params.ref.type!=="ref/resource")throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${t.params.ref.type}`)}const bf=ge.extend({completion:we({values:V(g()).max(100),total:ce(Y().int()),hasMore:ce(he())})}),wf=$({uri:g().startsWith("file://"),name:g().optional(),_meta:ie(g(),se()).optional()}),kf=pe.extend({method:I("roots/list"),params:$e.optional()}),Vi=ge.extend({roots:V(wf)}),Sf=Ne.extend({method:I("notifications/roots/list_changed"),params:Re.optional()});ee([cr,Zi,An,Fi,xn,On,En,Cn,In,vd,wd,Wt,Zn,lr,fr,hr,pr]);ee([ar,ur,Ai,Sf,Bt]);ee([or,Sr,Ui,Yt,Vi,dr,mr,gn]);ee([cr,Gd,ff,kf,lr,fr,hr,pr]);ee([ar,ur,qd,Sd,_d,Md,Od,Bt,mf]);ee([or,id,bf,Id,$d,hd,md,gd,kr,Ad,dr,mr,gn]);class C extends Error{constructor(e,n,r){super(`MCP error ${e}: ${n}`),this.code=e,this.data=r,this.name="McpError"}static fromError(e,n,r){if(e===x.UrlElicitationRequired&&r){const s=r;if(s.elicitations)return new Tf(s.elicitations,n)}return new C(e,n,r)}}class Tf extends C{constructor(e,n=`URL elicitation${e.length>1?"s":""} required`){super(x.UrlElicitationRequired,n,{elicitations:e})}get elicitations(){var e;return((e=this.data)==null?void 0:e.elicitations)??[]}}class zf{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;const e=this._buffer.indexOf(`
|
|
40
|
-
`);if(e===-1)return null;const n=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1)
|
|
41
|
-
`}class Rf{constructor(e=$r.stdin,n=$r.stdout){this._stdin=e,this._stdout=n,this._readBuffer=new zf,this._started=!1,this._ondata=r=>{this._readBuffer.append(r),this.processReadBuffer()},this._onerror=r=>{var s;(s=this.onerror)==null||s.call(this,r)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){var e,n;for(;;)try{const r=this._readBuffer.readMessage();if(r===null)break;(e=this.onmessage)==null||e.call(this,r)}catch(r){(n=this.onerror)==null||n.call(this,r)}}async close(){var n;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(n=this.onclose)==null||n.call(this)}send(e){return new Promise(n=>{const r=Pf(e);this._stdout.write(r)?n():this._stdout.once("drain",n)})}}const Nf=[/^https?:\/\/localhost(:\d+)?$/,/^https?:\/\/127\.0\.0\.1(:\d+)?$/,/^https?:\/\/playground\.wordpress\.net$/];function Wr(t){return t?Nf.some(e=>e.test(t)):!0}class Ef{constructor(){this.connections=new Map,this.sites=new Map,this.pendingRequests=new Map,this.requestId=0,this.sessionToken=co.randomUUID(),this.siteActivatedListeners=[]}getPort(){var n;const e=(n=this.httpServer)==null?void 0:n.address();if(!e)throw new Error("WebSocket server is not running");return e.port}startWebSocketServer(e=0){return new Promise((n,r)=>{const s=ao.createServer((o,a)=>{this.handleHttpRequest(o,a)});this.httpServer=s;const i=new oo.WebSocketServer({server:s,verifyClient:(o,a)=>{if(!Wr(o.origin)){console.error(`[MCP] Rejected WebSocket connection from origin: ${o.origin}`),a(!1,403,"Forbidden");return}if(new URL(o.req.url??"/",`http://${o.req.headers.host}`).searchParams.get("token")!==this.sessionToken){console.error("[MCP] Rejected WebSocket connection: invalid token"),a(!1,401,"Invalid token");return}a(!0)}});this.wss=i,s.on("error",o=>{o.code==="EADDRINUSE"&&console.error(`[MCP] Port ${e} is already in use. Kill the other process (lsof -i :${e}).`),r(o)}),s.listen(e,"127.0.0.1",()=>{const o=this.getPort();console.error(`[MCP] WebSocket server listening on ws://127.0.0.1:${o}`),n(i)}),i.on("connection",o=>{this.handleConnection(o)})})}handleHttpRequest(e,n){if(e.url==="/bridge-token"){const r=e.headers.origin;if(!r||!Wr(r)){n.writeHead(403),n.end("Forbidden");return}if(n.setHeader("Access-Control-Allow-Origin",r),n.setHeader("Access-Control-Allow-Methods","GET"),e.method==="OPTIONS"){n.writeHead(204),n.end();return}n.writeHead(200,{"Content-Type":"application/json"}),n.end(JSON.stringify({token:this.sessionToken}));return}n.writeHead(404),n.end()}handleConnection(e){let n;e.on("message",r=>{let s;try{s=JSON.parse(r.toString())}catch{console.error("[MCP] Failed to parse message");return}try{if(s.type==="register"){const i=!n;n=s.tabId,this.connections.set(n,e),this.updateSitesForTab(n,s.sites),i&&console.error(`[MCP] Tab registered: ${n} (${s.sites.length} sites)`);return}if(s.type==="response"){const i=this.pendingRequests.get(s.id);if(i)if(this.pendingRequests.delete(s.id),s.error){const o=typeof s.error=="string"?s.error:JSON.stringify(s.error);i.reject(new Error(o))}else i.resolve(s.value)}}catch(i){console.error("[MCP] Error handling message:",i)}}),e.on("close",()=>{if(n){console.error(`[MCP] Tab disconnected: ${n}`);for(const[r,s]of this.pendingRequests)s.tabId===n&&(s.reject(new Error("Browser tab disconnected")),this.pendingRequests.delete(r));this.connections.delete(n);for(const[r,s]of this.sites){s.reportedByTabs.delete(n);const i=s.activeInTabs.indexOf(n);i!==-1&&s.activeInTabs.splice(i,1),s.reportedByTabs.size===0&&this.sites.delete(r)}}})}updateSitesForTab(e,n){const r=new Set(n.map(s=>s.slug));for(const[s,i]of this.sites)if(!r.has(i.siteSlug)){i.reportedByTabs.delete(e);const o=i.activeInTabs.indexOf(e);o!==-1&&i.activeInTabs.splice(o,1),i.reportedByTabs.size===0&&this.sites.delete(s)}for(const s of n){const i=s.slug;let o=this.sites.get(i);if(o||(o={siteSlug:s.slug,siteName:s.name,storage:s.storage,reportedByTabs:new Set,activeInTabs:[]},this.sites.set(i,o)),o.siteName=s.name,o.storage=s.storage,o.reportedByTabs.add(e),s.isActive){const a=o.activeInTabs.length>0,c=o.activeInTabs.indexOf(e);if(c!==-1&&o.activeInTabs.splice(c,1),o.activeInTabs.unshift(e),!a)for(const u of this.siteActivatedListeners)u(i)}else{const a=o.activeInTabs.indexOf(e);a!==-1&&o.activeInTabs.splice(a,1)}}}sendCommand(e,n,r=[]){const s=this.sites.get(e);if(!s)return Promise.reject(new Error(`Unknown site: ${e}`));const i=n.startsWith("__");let o;if(i){if(this.connections.size===0)return Promise.reject(new Error("No browser tabs connected"));o=[...s.reportedByTabs].find(l=>this.connections.has(l))??this.connections.keys().next().value}else{if(s.activeInTabs.length===0)return Promise.reject(new Error(`Site "${s.siteName}" (${e}) is not active in any tab. Use open_site_in_new_tab to activate it.`));o=s.activeInTabs[0]}const a=this.connections.get(o);if(!a)return Promise.reject(new Error("Target browser tab disconnected"));const c=String(++this.requestId);return new Promise((u,l)=>{const p=setTimeout(()=>{this.pendingRequests.delete(c),l(new Error(`Command "${n}" timed out after 300 seconds`))},3e5);this.pendingRequests.set(c,{resolve:m=>{clearTimeout(p),u(m)},reject:m=>{clearTimeout(p),l(m)},tabId:o}),a.send(JSON.stringify({id:c,type:"command",method:n,args:r,siteSlug:s.siteSlug}))})}waitForSiteActive(e,n){const r=this.sites.get(e);return r&&r.activeInTabs.length>0?Promise.resolve(r):new Promise((s,i)=>{const o=setTimeout(()=>{this.removeSiteActivatedListener(a),i(new Error(`Timed out waiting for site ${e} to become active`))},n),a=c=>{c===e&&(clearTimeout(o),this.removeSiteActivatedListener(a),s(this.sites.get(e)))};this.siteActivatedListeners.push(a)})}removeSiteActivatedListener(e){const n=this.siteActivatedListeners.indexOf(e);n!==-1&&this.siteActivatedListeners.splice(n,1)}listSites(){return[...this.sites.entries()].map(([e,n])=>({siteId:e,name:n.siteName,storage:Qe.formatStorageLabel(n.storage),isActive:n.activeInTabs.length>0}))}getTabCount(){return this.connections.size}isConnected(){return this.connections.size>0}async close(){if(this.wss)for(const e of this.wss.clients)e.close();return new Promise(e=>{const n=()=>{this.httpServer?this.httpServer.close(()=>e()):e()};this.wss?this.wss.close(()=>n()):n()})}}var J;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function n(s){throw new Error}t.assertNever=n,t.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},t.getValidEnumValues=s=>{const i=t.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return t.objectValues(o)},t.objectValues=s=>t.objectKeys(s).map(function(i){return s[i]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},t.find=(s,i)=>{for(const o of s)if(i(o))return o},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}t.joinValues=r,t.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(J||(J={}));var Gr;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Gr||(Gr={}));const P=J.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),De=t=>{switch(typeof t){case"undefined":return P.undefined;case"string":return P.string;case"number":return Number.isNaN(t)?P.nan:P.number;case"boolean":return P.boolean;case"function":return P.function;case"bigint":return P.bigint;case"symbol":return P.symbol;case"object":return Array.isArray(t)?P.array:t===null?P.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?P.promise:typeof Map<"u"&&t instanceof Map?P.map:typeof Set<"u"&&t instanceof Set?P.set:typeof Date<"u"&&t instanceof Date?P.date:P.object;default:return P.unknown}},w=J.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 je extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,c=0;for(;c<o.path.length;){const u=o.path[c];c===o.path.length-1?(a[u]=a[u]||{_errors:[]},a[u]._errors.push(n(o))):a[u]=a[u]||{_errors:[]},a=a[u],c++}}};return s(this),r}static assert(e){if(!(e instanceof je))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,J.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n=Object.create(null),r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}je.create=t=>new je(t);const jn=(t,e)=>{let n;switch(t.code){case w.invalid_type:t.received===P.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case w.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,J.jsonStringifyReplacer)}`;break;case w.unrecognized_keys:n=`Unrecognized key(s) in object: ${J.joinValues(t.keys,", ")}`;break;case w.invalid_union:n="Invalid input";break;case w.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${J.joinValues(t.options)}`;break;case w.invalid_enum_value:n=`Invalid enum value. Expected ${J.joinValues(t.options)}, received '${t.received}'`;break;case w.invalid_arguments:n="Invalid function arguments";break;case w.invalid_return_type:n="Invalid function return type";break;case w.invalid_date:n="Invalid date";break;case w.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:J.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case w.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case w.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case w.custom:n="Invalid input";break;case w.invalid_intersection_types:n="Intersection results could not be merged";break;case w.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case w.not_finite:n="Number must be finite";break;default:n=e.defaultError,J.assertNever(t)}return{message:n}};let Cf=jn;function If(){return Cf}const Of=t=>{const{data:e,path:n,errorMaps:r,issueData:s}=t,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)a=u(o,{data:e,defaultError:a}).message;return{...s,path:i,message:a}};function z(t,e){const n=If(),r=Of({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===jn?void 0:jn].filter(s=>!!s)});t.common.issues.push(r)}class be{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const s of n){if(s.status==="aborted")return M;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return be.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return M;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:e.value,value:r}}}const M=Object.freeze({status:"aborted"}),bt=t=>({status:"dirty",value:t}),Ee=t=>({status:"valid",value:t}),Kr=t=>t.status==="aborted",Yr=t=>t.status==="dirty",ut=t=>t.status==="valid",Qt=t=>typeof Promise<"u"&&t instanceof Promise;var E;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(E||(E={}));class xe{constructor(e,n,r,s){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=s}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}}const Qr=(t,e)=>{if(ut(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new je(t.common.issues);return this._error=n,this._error}}};function L(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:s}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,a)=>{const{message:c}=t;return o.code==="invalid_enum_value"?{message:c??a.defaultError}:typeof a.data>"u"?{message:c??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:c??n??a.defaultError}},description:s}}class U{get description(){return this._def.description}_getType(e){return De(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:De(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new be,ctx:{common:e.parent.common,data:e.data,parsedType:De(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(Qt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){const r={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)},s=this._parseSync({data:e,path:r.path,parent:r});return Qr(r,s)}"~validate"(e){var r,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)};if(!this["~standard"].async)try{const i=this._parseSync({data:e,path:[],parent:n});return ut(i)?{value:i.value}:{issues:n.common.issues}}catch(i){(s=(r=i==null?void 0:i.message)==null?void 0:r.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(i=>ut(i)?{value:i.value}:{issues:n.common.issues})}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)},s=this._parse({data:e,path:r.path,parent:r}),i=await(Qt(s)?s:Promise.resolve(s));return Qr(r,i)}refine(e,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=e(s),a=()=>i.addIssue({code:w.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(e){return new dt({schema:this,typeName:k.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:n=>this["~validate"](n)}}optional(){return qe.create(this,this._def)}nullable(){return ft.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Oe.create(this)}promise(){return rn.create(this,this._def)}or(e){return en.create([this,e],this._def)}and(e){return tn.create(this,e,this._def)}transform(e){return new dt({...L(this._def),schema:this,typeName:k.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Dn({...L(this._def),innerType:this,defaultValue:n,typeName:k.ZodDefault})}brand(){return new nh({typeName:k.ZodBranded,type:this,...L(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new qn({...L(this._def),innerType:this,catchValue:n,typeName:k.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Tr.create(this,e)}readonly(){return Fn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const xf=/^c[^\s-]{8,}$/i,Zf=/^[0-9a-z]+$/,Af=/^[0-9A-HJKMNP-TV-Z]{26}$/i,jf=/^[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,Mf=/^[a-z0-9_-]{21}$/i,Lf=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Df=/^[-+]?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)?)??$/,qf=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ff="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let wn;const Uf=/^(?:(?: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])$/,Vf=/^(?:(?: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])$/,Hf=/^(([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]))$/,Jf=/^(([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])$/,Bf=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Wf=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Hi="((\\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])))",Gf=new RegExp(`^${Hi}$`);function Ji(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Kf(t){return new RegExp(`^${Ji(t)}$`)}function Yf(t){let e=`${Hi}T${Ji(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Qf(t,e){return!!((e==="v4"||!e)&&Uf.test(t)||(e==="v6"||!e)&&Hf.test(t))}function Xf(t,e){if(!Lf.test(t))return!1;try{const[n]=t.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function eh(t,e){return!!((e==="v4"||!e)&&Vf.test(t)||(e==="v6"||!e)&&Jf.test(t))}class Ae extends U{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==P.string){const i=this._getOrReturnCtx(e);return z(i,{code:w.invalid_type,expected:P.string,received:i.parsedType}),M}const r=new be;let s;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:w.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:w.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=e.data.length>i.value,a=e.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(e,s),o?z(s,{code:w.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&z(s,{code:w.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")qf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"email",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")wn||(wn=new RegExp(Ff,"u")),wn.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"emoji",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")jf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"uuid",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")Mf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"nanoid",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")xf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cuid",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Zf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cuid2",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Af.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"ulid",code:w.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),z(s,{validation:"url",code:w.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"regex",code:w.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?Yf(i).test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?Gf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?Kf(i).test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:w.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?Df.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"duration",code:w.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?Qf(e.data,i.version)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"ip",code:w.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?Xf(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"jwt",code:w.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?eh(e.data,i.version)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cidr",code:w.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?Bf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"base64",code:w.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Wf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"base64url",code:w.invalid_string,message:i.message}),r.dirty()):J.assertNever(i);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(s=>e.test(s),{validation:n,code:w.invalid_string,...E.errToObj(r)})}_addCheck(e){return new Ae({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...E.errToObj(e)})}url(e){return this._addCheck({kind:"url",...E.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...E.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...E.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...E.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...E.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...E.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...E.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...E.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...E.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...E.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...E.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...E.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...E.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...E.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...E.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...E.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...E.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...E.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...E.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...E.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...E.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...E.errToObj(n)})}nonempty(e){return this.min(1,E.errToObj(e))}trim(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Ae.create=t=>new Ae({checks:[],typeName:k.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...L(t)});function th(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(t.toFixed(s).replace(".","")),o=Number.parseInt(e.toFixed(s).replace(".",""));return i%o/10**s}class Tt extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==P.number){const i=this._getOrReturnCtx(e);return z(i,{code:w.invalid_type,expected:P.number,received:i.parsedType}),M}let r;const s=new be;for(const i of this._def.checks)i.kind==="int"?J.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:w.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?th(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:w.not_finite,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,E.toString(n))}gt(e,n){return this.setLimit("min",e,!1,E.toString(n))}lte(e,n){return this.setLimit("max",e,!0,E.toString(n))}lt(e,n){return this.setLimit("max",e,!1,E.toString(n))}setLimit(e,n,r,s){return new Tt({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:E.toString(s)}]})}_addCheck(e){return new Tt({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:E.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:E.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:E.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:E.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:E.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:E.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&J.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}Tt.create=t=>new Tt({checks:[],typeName:k.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...L(t)});class zt extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==P.bigint)return this._getInvalidInput(e);let r;const s=new be;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),z(r,{code:w.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return z(n,{code:w.invalid_type,expected:P.bigint,received:n.parsedType}),M}gte(e,n){return this.setLimit("min",e,!0,E.toString(n))}gt(e,n){return this.setLimit("min",e,!1,E.toString(n))}lte(e,n){return this.setLimit("max",e,!0,E.toString(n))}lt(e,n){return this.setLimit("max",e,!1,E.toString(n))}setLimit(e,n,r,s){return new zt({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:E.toString(s)}]})}_addCheck(e){return new zt({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:E.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:E.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}zt.create=t=>new zt({checks:[],typeName:k.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...L(t)});class Mn extends U{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==P.boolean){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.boolean,received:r.parsedType}),M}return Ee(e.data)}}Mn.create=t=>new Mn({typeName:k.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...L(t)});class Xt extends U{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==P.date){const i=this._getOrReturnCtx(e);return z(i,{code:w.invalid_type,expected:P.date,received:i.parsedType}),M}if(Number.isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return z(i,{code:w.invalid_date}),M}const r=new be;let s;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:w.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:w.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):J.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Xt({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:E.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:E.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}Xt.create=t=>new Xt({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:k.ZodDate,...L(t)});class Xr extends U{_parse(e){if(this._getType(e)!==P.symbol){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.symbol,received:r.parsedType}),M}return Ee(e.data)}}Xr.create=t=>new Xr({typeName:k.ZodSymbol,...L(t)});class es extends U{_parse(e){if(this._getType(e)!==P.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.undefined,received:r.parsedType}),M}return Ee(e.data)}}es.create=t=>new es({typeName:k.ZodUndefined,...L(t)});class ts extends U{_parse(e){if(this._getType(e)!==P.null){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.null,received:r.parsedType}),M}return Ee(e.data)}}ts.create=t=>new ts({typeName:k.ZodNull,...L(t)});class ns extends U{constructor(){super(...arguments),this._any=!0}_parse(e){return Ee(e.data)}}ns.create=t=>new ns({typeName:k.ZodAny,...L(t)});class rs extends U{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ee(e.data)}}rs.create=t=>new rs({typeName:k.ZodUnknown,...L(t)});class Ve extends U{_parse(e){const n=this._getOrReturnCtx(e);return z(n,{code:w.invalid_type,expected:P.never,received:n.parsedType}),M}}Ve.create=t=>new Ve({typeName:k.ZodNever,...L(t)});class ss extends U{_parse(e){if(this._getType(e)!==P.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.void,received:r.parsedType}),M}return Ee(e.data)}}ss.create=t=>new ss({typeName:k.ZodVoid,...L(t)});class Oe extends U{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),s=this._def;if(n.parsedType!==P.array)return z(n,{code:w.invalid_type,expected:P.array,received:n.parsedType}),M;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(o||a)&&(z(n,{code:o?w.too_big:w.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(z(n,{code:w.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(z(n,{code:w.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>s.type._parseAsync(new xe(n,o,n.path,a)))).then(o=>be.mergeArray(r,o));const i=[...n.data].map((o,a)=>s.type._parseSync(new xe(n,o,n.path,a)));return be.mergeArray(r,i)}get element(){return this._def.type}min(e,n){return new Oe({...this._def,minLength:{value:e,message:E.toString(n)}})}max(e,n){return new Oe({...this._def,maxLength:{value:e,message:E.toString(n)}})}length(e,n){return new Oe({...this._def,exactLength:{value:e,message:E.toString(n)}})}nonempty(e){return this.min(1,e)}}Oe.create=(t,e)=>new Oe({type:t,minLength:null,maxLength:null,exactLength:null,typeName:k.ZodArray,...L(e)});function tt(t){if(t instanceof le){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=qe.create(tt(r))}return new le({...t._def,shape:()=>e})}else return t instanceof Oe?new Oe({...t._def,type:tt(t.element)}):t instanceof qe?qe.create(tt(t.unwrap())):t instanceof ft?ft.create(tt(t.unwrap())):t instanceof Xe?Xe.create(t.items.map(e=>tt(e))):t}class le extends U{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=J.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==P.object){const u=this._getOrReturnCtx(e);return z(u,{code:w.invalid_type,expected:P.object,received:u.parsedType}),M}const{status:r,ctx:s}=this._processInputParams(e),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof Ve&&this._def.unknownKeys==="strip"))for(const u in s.data)o.includes(u)||a.push(u);const c=[];for(const u of o){const l=i[u],d=s.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new xe(s,d,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Ve){const u=this._def.unknownKeys;if(u==="passthrough")for(const l of a)c.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(u==="strict")a.length>0&&(z(s,{code:w.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const l of a){const d=s.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new xe(s,d,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const l of c){const d=await l.key,p=await l.value;u.push({key:d,value:p,alwaysSet:l.alwaysSet})}return u}).then(u=>be.mergeObjectSync(r,u)):be.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return E.errToObj,new le({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var i,o;const s=((o=(i=this._def).errorMap)==null?void 0:o.call(i,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:E.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new le({...this._def,unknownKeys:"strip"})}passthrough(){return new le({...this._def,unknownKeys:"passthrough"})}extend(e){return new le({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new le({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:k.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new le({...this._def,catchall:e})}pick(e){const n={};for(const r of J.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new le({...this._def,shape:()=>n})}omit(e){const n={};for(const r of J.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new le({...this._def,shape:()=>n})}deepPartial(){return tt(this)}partial(e){const n={};for(const r of J.objectKeys(this.shape)){const s=this.shape[r];e&&!e[r]?n[r]=s:n[r]=s.optional()}return new le({...this._def,shape:()=>n})}required(e){const n={};for(const r of J.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof qe;)i=i._def.innerType;n[r]=i}return new le({...this._def,shape:()=>n})}keyof(){return Bi(J.objectKeys(this.shape))}}le.create=(t,e)=>new le({shape:()=>t,unknownKeys:"strip",catchall:Ve.create(),typeName:k.ZodObject,...L(e)});le.strictCreate=(t,e)=>new le({shape:()=>t,unknownKeys:"strict",catchall:Ve.create(),typeName:k.ZodObject,...L(e)});le.lazycreate=(t,e)=>new le({shape:t,unknownKeys:"strip",catchall:Ve.create(),typeName:k.ZodObject,...L(e)});class en extends U{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new je(a.ctx.common.issues));return z(n,{code:w.invalid_union,unionErrors:o}),M}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},l=c._parseSync({data:n.data,path:n.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!i&&(i={result:l,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(c=>new je(c));return z(n,{code:w.invalid_union,unionErrors:a}),M}}get options(){return this._def.options}}en.create=(t,e)=>new en({options:t,typeName:k.ZodUnion,...L(e)});function Ln(t,e){const n=De(t),r=De(e);if(t===e)return{valid:!0,data:t};if(n===P.object&&r===P.object){const s=J.objectKeys(e),i=J.objectKeys(t).filter(a=>s.indexOf(a)!==-1),o={...t,...e};for(const a of i){const c=Ln(t[a],e[a]);if(!c.valid)return{valid:!1};o[a]=c.data}return{valid:!0,data:o}}else if(n===P.array&&r===P.array){if(t.length!==e.length)return{valid:!1};const s=[];for(let i=0;i<t.length;i++){const o=t[i],a=e[i],c=Ln(o,a);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return n===P.date&&r===P.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class tn extends U{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),s=(i,o)=>{if(Kr(i)||Kr(o))return M;const a=Ln(i.value,o.value);return a.valid?((Yr(i)||Yr(o))&&n.dirty(),{status:n.value,value:a.data}):(z(r,{code:w.invalid_intersection_types}),M)};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(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}tn.create=(t,e,n)=>new tn({left:t,right:e,typeName:k.ZodIntersection,...L(n)});class Xe extends U{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==P.array)return z(r,{code:w.invalid_type,expected:P.array,received:r.parsedType}),M;if(r.data.length<this._def.items.length)return z(r,{code:w.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),M;!this._def.rest&&r.data.length>this._def.items.length&&(z(r,{code:w.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new xe(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>be.mergeArray(n,o)):be.mergeArray(n,i)}get items(){return this._def.items}rest(e){return new Xe({...this._def,rest:e})}}Xe.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Xe({items:t,typeName:k.ZodTuple,rest:null,...L(e)})};class nn extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==P.object)return z(r,{code:w.invalid_type,expected:P.object,received:r.parsedType}),M;const s=[],i=this._def.keyType,o=this._def.valueType;for(const a in r.data)s.push({key:i._parse(new xe(r,a,r.path,a)),value:o._parse(new xe(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?be.mergeObjectAsync(n,s):be.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof U?new nn({keyType:e,valueType:n,typeName:k.ZodRecord,...L(r)}):new nn({keyType:Ae.create(),valueType:e,typeName:k.ZodRecord,...L(n)})}}class is extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==P.map)return z(r,{code:w.invalid_type,expected:P.map,received:r.parsedType}),M;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new xe(r,a,r.path,[u,"key"])),value:i._parse(new xe(r,c,r.path,[u,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of o){const u=await c.key,l=await c.value;if(u.status==="aborted"||l.status==="aborted")return M;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const c of o){const u=c.key,l=c.value;if(u.status==="aborted"||l.status==="aborted")return M;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}}}}is.create=(t,e,n)=>new is({valueType:e,keyType:t,typeName:k.ZodMap,...L(n)});class $t extends U{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==P.set)return z(r,{code:w.invalid_type,expected:P.set,received:r.parsedType}),M;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(z(r,{code:w.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(z(r,{code:w.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(c){const u=new Set;for(const l of c){if(l.status==="aborted")return M;l.status==="dirty"&&n.dirty(),u.add(l.value)}return{status:n.value,value:u}}const a=[...r.data.values()].map((c,u)=>i._parse(new xe(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>o(c)):o(a)}min(e,n){return new $t({...this._def,minSize:{value:e,message:E.toString(n)}})}max(e,n){return new $t({...this._def,maxSize:{value:e,message:E.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}$t.create=(t,e)=>new $t({valueType:t,minSize:null,maxSize:null,typeName:k.ZodSet,...L(e)});class os extends U{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}os.create=(t,e)=>new os({getter:t,typeName:k.ZodLazy,...L(e)});class as extends U{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return z(n,{received:n.data,code:w.invalid_literal,expected:this._def.value}),M}return{status:"valid",value:e.data}}get value(){return this._def.value}}as.create=(t,e)=>new as({value:t,typeName:k.ZodLiteral,...L(e)});function Bi(t,e){return new lt({values:t,typeName:k.ZodEnum,...L(e)})}class lt extends U{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{expected:J.joinValues(r),received:n.parsedType,code:w.invalid_type}),M}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{received:n.data,code:w.invalid_enum_value,options:r}),M}return Ee(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return lt.create(e,{...this._def,...n})}exclude(e,n=this._def){return lt.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}lt.create=Bi;class cs extends U{_parse(e){const n=J.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==P.string&&r.parsedType!==P.number){const s=J.objectValues(n);return z(r,{expected:J.joinValues(s),received:r.parsedType,code:w.invalid_type}),M}if(this._cache||(this._cache=new Set(J.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const s=J.objectValues(n);return z(r,{received:r.data,code:w.invalid_enum_value,options:s}),M}return Ee(e.data)}get enum(){return this._def.values}}cs.create=(t,e)=>new cs({values:t,typeName:k.ZodNativeEnum,...L(e)});class rn extends U{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==P.promise&&n.common.async===!1)return z(n,{code:w.invalid_type,expected:P.promise,received:n.parsedType}),M;const r=n.parsedType===P.promise?n.data:Promise.resolve(n.data);return Ee(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}rn.create=(t,e)=>new rn({type:t,typeName:k.ZodPromise,...L(e)});class dt extends U{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===k.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:o=>{z(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return M;const c=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return c.status==="aborted"?M:c.status==="dirty"||n.value==="dirty"?bt(c.value):c});{if(n.value==="aborted")return M;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?M:a.status==="dirty"||n.value==="dirty"?bt(a.value):a}}if(s.type==="refinement"){const o=a=>{const c=s.refinement(a,i);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?M:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?M:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!ut(o))return M;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>ut(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:n.value,value:a})):M);J.assertNever(s)}}dt.create=(t,e,n)=>new dt({schema:t,typeName:k.ZodEffects,effect:e,...L(n)});dt.createWithPreprocess=(t,e,n)=>new dt({schema:e,effect:{type:"preprocess",transform:t},typeName:k.ZodEffects,...L(n)});class qe extends U{_parse(e){return this._getType(e)===P.undefined?Ee(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}qe.create=(t,e)=>new qe({innerType:t,typeName:k.ZodOptional,...L(e)});class ft extends U{_parse(e){return this._getType(e)===P.null?Ee(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ft.create=(t,e)=>new ft({innerType:t,typeName:k.ZodNullable,...L(e)});class Dn extends U{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===P.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Dn.create=(t,e)=>new Dn({innerType:t,typeName:k.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...L(e)});class qn extends U{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Qt(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new je(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new je(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}qn.create=(t,e)=>new qn({innerType:t,typeName:k.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...L(e)});class us extends U{_parse(e){if(this._getType(e)!==P.nan){const r=this._getOrReturnCtx(e);return z(r,{code:w.invalid_type,expected:P.nan,received:r.parsedType}),M}return{status:"valid",value:e.data}}}us.create=t=>new us({typeName:k.ZodNaN,...L(t)});class nh extends U{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Tr extends U{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?M:i.status==="dirty"?(n.dirty(),bt(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?M:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,n){return new Tr({in:e,out:n,typeName:k.ZodPipeline})}}class Fn extends U{_parse(e){const n=this._def.innerType._parse(e),r=s=>(ut(s)&&(s.value=Object.freeze(s.value)),s);return Qt(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Fn.create=(t,e)=>new Fn({innerType:t,typeName:k.ZodReadonly,...L(e)});var k;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(k||(k={}));const Dt=Ae.create,rh=Mn.create;Ve.create;Oe.create;const Un=le.create;en.create;tn.create;Xe.create;const sh=nn.create;lt.create;rn.create;qe.create;ft.create;const ih=_("ZodMiniType",(t,e)=>{if(!t._zod)throw new Error("Uninitialized schema in ZodMiniType.");X.init(t,e),t.def=e,t.type=e.type,t.parse=(n,r)=>Po(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>Qn(t,n,r),t.parseAsync=async(n,r)=>Ro(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>Xn(t,n,r),t.check=(...n)=>t.clone({...e,checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0}),t.with=t.check,t.clone=(n,r)=>Me(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t),t.apply=n=>n(t)}),oh=_("ZodMiniObject",(t,e)=>{Vs.init(t,e),ih.init(t,e),B(t,"shape",()=>e.shape)});function ls(t,e){const n={type:"object",shape:t??{},...N(e)};return new oh(n)}function Ze(t){return!!t._zod}function st(t){const e=Object.values(t);if(e.length===0)return ls({});const n=e.every(Ze),r=e.every(s=>!Ze(s));if(n)return ls(t);if(r)return Un(t);throw new Error("Mixed Zod versions detected in object shape.")}function wt(t,e){return Ze(t)?Qn(t,e):t.safeParse(e)}async function kn(t,e){return Ze(t)?await Xn(t,e):await t.safeParseAsync(e)}function Ot(t){var n,r;if(!t)return;let e;if(Ze(t)?e=(r=(n=t._zod)==null?void 0:n.def)==null?void 0:r.shape:e=t.shape,!!e){if(typeof e=="function")try{return e()}catch{return}return e}}function gt(t){var e;if(t){if(typeof t=="object"){const n=t,r=t;if(!n._def&&!r._zod){const s=Object.values(t);if(s.length>0&&s.every(i=>typeof i=="object"&&i!==null&&(i._def!==void 0||i._zod!==void 0||typeof i.parse=="function")))return st(t)}}if(Ze(t)){const r=(e=t._zod)==null?void 0:e.def;if(r&&(r.type==="object"||r.shape!==void 0))return t}else if(t.shape!==void 0)return t}}function Sn(t){if(t&&typeof t=="object"){if("message"in t&&typeof t.message=="string")return t.message;if("issues"in t&&Array.isArray(t.issues)&&t.issues.length>0){const e=t.issues[0];if(e&&typeof e=="object"&&"message"in e)return String(e.message)}try{return JSON.stringify(t)}catch{return String(t)}}return String(t)}function ah(t){return t.description}function ch(t){var n,r,s;if(Ze(t))return((r=(n=t._zod)==null?void 0:n.def)==null?void 0:r.type)==="optional";const e=t;return typeof t.isOptional=="function"?t.isOptional():((s=e._def)==null?void 0:s.typeName)==="ZodOptional"}function Wi(t){var s;if(Ze(t)){const o=(s=t._zod)==null?void 0:s.def;if(o){if(o.value!==void 0)return o.value;if(Array.isArray(o.values)&&o.values.length>0)return o.values[0]}}const n=t._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}const r=t.value;if(r!==void 0)return r}function Ke(t){return t==="completed"||t==="failed"||t==="cancelled"}const uh=Symbol("Let zodToJsonSchema decide on which parser to use"),ds={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"},lh=t=>typeof t=="string"?{...ds,name:t}:{...ds,...t},dh=t=>{const e=lh(t),n=e.name!==void 0?[...e.basePath,e.definitionPath,e.name]:e.basePath;return{...e,flags:{hasReferencedOpenAiAnyType:!1},currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(e.definitions).map(([r,s])=>[s._def,{def:s._def,path:[...e.basePath,e.definitionPath,r],jsonSchema:void 0}]))}};function Gi(t,e,n,r){r!=null&&r.errorMessages&&n&&(t.errorMessage={...t.errorMessage,[e]:n})}function K(t,e,n,r,s){t[e]=n,Gi(t,e,r,s)}const Ki=(t,e)=>{let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];n++);return[(t.length-n).toString(),...e.slice(n)].join("/")};function ke(t){if(t.target!=="openAi")return{};const e=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:t.$refStrategy==="relative"?Ki(e,t.currentPath):e.join("/")}}function fh(t,e){var r,s,i;const n={type:"array"};return(r=t.type)!=null&&r._def&&((i=(s=t.type)==null?void 0:s._def)==null?void 0:i.typeName)!==k.ZodAny&&(n.items=W(t.type._def,{...e,currentPath:[...e.currentPath,"items"]})),t.minLength&&K(n,"minItems",t.minLength.value,t.minLength.message,e),t.maxLength&&K(n,"maxItems",t.maxLength.value,t.maxLength.message,e),t.exactLength&&(K(n,"minItems",t.exactLength.value,t.exactLength.message,e),K(n,"maxItems",t.exactLength.value,t.exactLength.message,e)),n}function hh(t,e){const n={type:"integer",format:"int64"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"min":e.target==="jsonSchema7"?r.inclusive?K(n,"minimum",r.value,r.message,e):K(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),K(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?K(n,"maximum",r.value,r.message,e):K(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),K(n,"maximum",r.value,r.message,e));break;case"multipleOf":K(n,"multipleOf",r.value,r.message,e);break}return n}function mh(){return{type:"boolean"}}function Yi(t,e){return W(t.type._def,e)}const ph=(t,e)=>W(t.innerType._def,e);function Qi(t,e,n){const r=n??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((s,i)=>Qi(t,e,s))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return gh(t,e)}}const gh=(t,e)=>{const n={type:"integer",format:"unix-time"};if(e.target==="openApi3")return n;for(const r of t.checks)switch(r.kind){case"min":K(n,"minimum",r.value,r.message,e);break;case"max":K(n,"maximum",r.value,r.message,e);break}return n};function _h(t,e){return{...W(t.innerType._def,e),default:t.defaultValue()}}function yh(t,e){return e.effectStrategy==="input"?W(t.schema._def,e):ke(e)}function vh(t){return{type:"string",enum:Array.from(t.values)}}const bh=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function wh(t,e){const n=[W(t.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),W(t.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(i=>!!i);let r=e.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0;const s=[];return n.forEach(i=>{if(bh(i))s.push(...i.allOf),i.unevaluatedProperties===void 0&&(r=void 0);else{let o=i;if("additionalProperties"in i&&i.additionalProperties===!1){const{additionalProperties:a,...c}=i;o=c}else r=void 0;s.push(o)}}),s.length?{allOf:s,...r}:void 0}function kh(t,e){const n=typeof t.value;return n!=="bigint"&&n!=="number"&&n!=="boolean"&&n!=="string"?{type:Array.isArray(t.value)?"array":"object"}:e.target==="openApi3"?{type:n==="bigint"?"integer":n,enum:[t.value]}:{type:n==="bigint"?"integer":n,const:t.value}}let Tn;const Ce={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(Tn===void 0&&(Tn=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Tn),uuid:/^[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}$/,ipv4:/^(?:(?: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])$/,ipv4Cidr:/^(?:(?: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])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([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])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function Xi(t,e){const n={type:"string"};if(t.checks)for(const r of t.checks)switch(r.kind){case"min":K(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e);break;case"max":K(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"email":switch(e.emailStrategy){case"format:email":Ie(n,"email",r.message,e);break;case"format:idn-email":Ie(n,"idn-email",r.message,e);break;case"pattern:zod":ye(n,Ce.email,r.message,e);break}break;case"url":Ie(n,"uri",r.message,e);break;case"uuid":Ie(n,"uuid",r.message,e);break;case"regex":ye(n,r.regex,r.message,e);break;case"cuid":ye(n,Ce.cuid,r.message,e);break;case"cuid2":ye(n,Ce.cuid2,r.message,e);break;case"startsWith":ye(n,RegExp(`^${zn(r.value,e)}`),r.message,e);break;case"endsWith":ye(n,RegExp(`${zn(r.value,e)}$`),r.message,e);break;case"datetime":Ie(n,"date-time",r.message,e);break;case"date":Ie(n,"date",r.message,e);break;case"time":Ie(n,"time",r.message,e);break;case"duration":Ie(n,"duration",r.message,e);break;case"length":K(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e),K(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"includes":{ye(n,RegExp(zn(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&Ie(n,"ipv4",r.message,e),r.version!=="v4"&&Ie(n,"ipv6",r.message,e);break}case"base64url":ye(n,Ce.base64url,r.message,e);break;case"jwt":ye(n,Ce.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&ye(n,Ce.ipv4Cidr,r.message,e),r.version!=="v4"&&ye(n,Ce.ipv6Cidr,r.message,e);break}case"emoji":ye(n,Ce.emoji(),r.message,e);break;case"ulid":{ye(n,Ce.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{Ie(n,"binary",r.message,e);break}case"contentEncoding:base64":{K(n,"contentEncoding","base64",r.message,e);break}case"pattern:zod":{ye(n,Ce.base64,r.message,e);break}}break}case"nanoid":ye(n,Ce.nanoid,r.message,e)}return n}function zn(t,e){return e.patternStrategy==="escape"?Th(t):t}const Sh=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Th(t){let e="";for(let n=0;n<t.length;n++)Sh.has(t[n])||(e+="\\"),e+=t[n];return e}function Ie(t,e,n,r){var s;t.format||(s=t.anyOf)!=null&&s.some(i=>i.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&r.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.anyOf.push({format:e,...n&&r.errorMessages&&{errorMessage:{format:n}}})):K(t,"format",e,n,r)}function ye(t,e,n,r){var s;t.pattern||(s=t.allOf)!=null&&s.some(i=>i.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&r.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.allOf.push({pattern:fs(e,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):K(t,"pattern",fs(e,r),n,r)}function fs(t,e){var c;if(!e.applyRegexFlags||!t.flags)return t.source;const n={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},r=n.i?t.source.toLowerCase():t.source;let s="",i=!1,o=!1,a=!1;for(let u=0;u<r.length;u++){if(i){s+=r[u],i=!1;continue}if(n.i){if(o){if(r[u].match(/[a-z]/)){a?(s+=r[u],s+=`${r[u-2]}-${r[u]}`.toUpperCase(),a=!1):r[u+1]==="-"&&((c=r[u+2])!=null&&c.match(/[a-z]/))?(s+=r[u],a=!0):s+=`${r[u]}${r[u].toUpperCase()}`;continue}}else if(r[u].match(/[a-z]/)){s+=`[${r[u]}${r[u].toUpperCase()}]`;continue}}if(n.m){if(r[u]==="^"){s+=`(^|(?<=[\r
|
|
39
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const l of t.seen.entries()){const f=l[1];if(e===l[0]){i(l);continue}if(t.external){const m=(c=t.external.registry.get(l[0]))==null?void 0:c.id;if(e!==l[0]&&m){i(l);continue}}if((u=t.metadataRegistry.get(l[0]))==null?void 0:u.id){i(l);continue}if(f.cycle){i(l);continue}if(f.count>1&&t.reused==="ref"){i(l);continue}}}function Ht(t,e){var o,a,c;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=u=>{const l=t.seen.get(u);if(l.ref===null)return;const f=l.def??l.schema,p={...f},m=l.ref;if(l.ref=null,m){r(m);const T=t.seen.get(m),x=T.schema;if(x.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(x)):Object.assign(f,x),Object.assign(f,p),u._zod.parent===m)for(const y in f)y==="$ref"||y==="allOf"||y in p||delete f[y];if(x.$ref&&T.def)for(const y in f)y==="$ref"||y==="allOf"||y in T.def&&JSON.stringify(f[y])===JSON.stringify(T.def[y])&&delete f[y]}const v=u._zod.parent;if(v&&v!==m){r(v);const T=t.seen.get(v);if(T!=null&&T.schema.$ref&&(f.$ref=T.schema.$ref,T.def))for(const x in f)x==="$ref"||x==="allOf"||x in T.def&&JSON.stringify(f[x])===JSON.stringify(T.def[x])&&delete f[x]}t.override({zodSchema:u,jsonSchema:f,path:l.path??[]})};for(const u of[...t.seen.entries()].reverse())r(u[0]);const s={};if(t.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":t.target,(o=t.external)!=null&&o.uri){const u=(a=t.external.registry.get(e))==null?void 0:a.id;if(!u)throw new Error("Schema is missing an `id` property");s.$id=t.external.uri(u)}Object.assign(s,n.def??n.schema);const i=((c=t.external)==null?void 0:c.defs)??{};for(const u of t.seen.entries()){const l=u[1];l.def&&l.defId&&(i[l.defId]=l.def)}t.external||Object.keys(i).length>0&&(t.target==="draft-2020-12"?s.$defs=i:s.definitions=i);try{const u=JSON.parse(JSON.stringify(s));return Object.defineProperty(u,"~standard",{value:{...e["~standard"],jsonSchema:{input:Jt(e,"input",t.processors),output:Jt(e,"output",t.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function ve(t,e){const n=e??{seen:new Set};if(n.seen.has(t))return!1;n.seen.add(t);const r=t._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return ve(r.element,n);if(r.type==="set")return ve(r.valueType,n);if(r.type==="lazy")return ve(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return ve(r.innerType,n);if(r.type==="intersection")return ve(r.left,n)||ve(r.right,n);if(r.type==="record"||r.type==="map")return ve(r.keyType,n)||ve(r.valueType,n);if(r.type==="pipe")return ve(r.in,n)||ve(r.out,n);if(r.type==="object"){for(const s in r.shape)if(ve(r.shape[s],n))return!0;return!1}if(r.type==="union"){for(const s of r.options)if(ve(s,n))return!0;return!1}if(r.type==="tuple"){for(const s of r.items)if(ve(s,n))return!0;return!!(r.rest&&ve(r.rest,n))}return!1}const hu=(t,e={})=>n=>{const r=Ut({...n,processors:e});return X(t,r),Vt(r,t),Ht(r,t)},Jt=(t,e,n={})=>r=>{const{libraryOptions:s,target:i}=r??{},o=Ut({...s??{},target:i,io:e,processors:n});return X(t,o),Vt(o,t),Ht(o,t)},mu={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Ks=(t,e,n,r)=>{const s=n;s.type="string";const{minimum:i,maximum:o,format:a,patterns:c,contentEncoding:u}=t._zod.bag;if(typeof i=="number"&&(s.minLength=i),typeof o=="number"&&(s.maxLength=o),a&&(s.format=mu[a]??a,s.format===""&&delete s.format,a==="time"&&delete s.format),u&&(s.contentEncoding=u),c&&c.size>0){const l=[...c];l.length===1?s.pattern=l[0].source:l.length>1&&(s.allOf=[...l.map(f=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},Ys=(t,e,n,r)=>{const s=n,{minimum:i,maximum:o,format:a,multipleOf:c,exclusiveMaximum:u,exclusiveMinimum:l}=t._zod.bag;typeof a=="string"&&a.includes("int")?s.type="integer":s.type="number",typeof l=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.minimum=l,s.exclusiveMinimum=!0):s.exclusiveMinimum=l),typeof i=="number"&&(s.minimum=i,typeof l=="number"&&e.target!=="draft-04"&&(l>=i?delete s.minimum:delete s.exclusiveMinimum)),typeof u=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.maximum=u,s.exclusiveMaximum=!0):s.exclusiveMaximum=u),typeof o=="number"&&(s.maximum=o,typeof u=="number"&&e.target!=="draft-04"&&(u<=o?delete s.maximum:delete s.exclusiveMaximum)),typeof c=="number"&&(s.multipleOf=c)},Qs=(t,e,n,r)=>{n.type="boolean"},pu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema")},gu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema")},Xs=(t,e,n,r)=>{e.target==="openapi-3.0"?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"},_u=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema")},yu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema")},ei=(t,e,n,r)=>{n.not={}},vu=(t,e,n,r)=>{},ti=(t,e,n,r)=>{},bu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema")},ni=(t,e,n,r)=>{const s=t._zod.def,i=Ns(s.entries);i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},ri=(t,e,n,r)=>{const s=t._zod.def,i=[];for(const o of s.values)if(o===void 0){if(e.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(e.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,e.target==="draft-04"||e.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},wu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema")},ku=(t,e,n,r)=>{const s=n,i=t._zod.pattern;if(!i)throw new Error("Pattern not found in template literal");s.type="string",s.pattern=i.source},Su=(t,e,n,r)=>{const s=n,i={type:"string",format:"binary",contentEncoding:"binary"},{minimum:o,maximum:a,mime:c}=t._zod.bag;o!==void 0&&(i.minLength=o),a!==void 0&&(i.maxLength=a),c?c.length===1?(i.contentMediaType=c[0],Object.assign(s,i)):(Object.assign(s,i),s.anyOf=c.map(u=>({contentMediaType:u}))):Object.assign(s,i)},Tu=(t,e,n,r)=>{n.type="boolean"},si=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},zu=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Function types cannot be represented in JSON Schema")},ii=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},$u=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema")},Ru=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema")},oi=(t,e,n,r)=>{const s=n,i=t._zod.def,{minimum:o,maximum:a}=t._zod.bag;typeof o=="number"&&(s.minItems=o),typeof a=="number"&&(s.maxItems=a),s.type="array",s.items=X(i.element,e,{...r,path:[...r.path,"items"]})},ai=(t,e,n,r)=>{var u;const s=n,i=t._zod.def;s.type="object",s.properties={};const o=i.shape;for(const l in o)s.properties[l]=X(o[l],e,{...r,path:[...r.path,"properties",l]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(l=>{const f=i.shape[l]._zod;return e.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(s.required=Array.from(c)),((u=i.catchall)==null?void 0:u._zod.def.type)==="never"?s.additionalProperties=!1:i.catchall?i.catchall&&(s.additionalProperties=X(i.catchall,e,{...r,path:[...r.path,"additionalProperties"]})):e.io==="output"&&(s.additionalProperties=!1)},ci=(t,e,n,r)=>{const s=t._zod.def,i=s.inclusive===!1,o=s.options.map((a,c)=>X(a,e,{...r,path:[...r.path,i?"oneOf":"anyOf",c]}));i?n.oneOf=o:n.anyOf=o},ui=(t,e,n,r)=>{const s=t._zod.def,i=X(s.left,e,{...r,path:[...r.path,"allOf",0]}),o=X(s.right,e,{...r,path:[...r.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,c=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=c},Pu=(t,e,n,r)=>{const s=n,i=t._zod.def;s.type="array";const o=e.target==="draft-2020-12"?"prefixItems":"items",a=e.target==="draft-2020-12"||e.target==="openapi-3.0"?"items":"additionalItems",c=i.items.map((p,m)=>X(p,e,{...r,path:[...r.path,o,m]})),u=i.rest?X(i.rest,e,{...r,path:[...r.path,a,...e.target==="openapi-3.0"?[i.items.length]:[]]}):null;e.target==="draft-2020-12"?(s.prefixItems=c,u&&(s.items=u)):e.target==="openapi-3.0"?(s.items={anyOf:c},u&&s.items.anyOf.push(u),s.minItems=c.length,u||(s.maxItems=c.length)):(s.items=c,u&&(s.additionalItems=u));const{minimum:l,maximum:f}=t._zod.bag;typeof l=="number"&&(s.minItems=l),typeof f=="number"&&(s.maxItems=f)},li=(t,e,n,r)=>{const s=n,i=t._zod.def;s.type="object";const o=i.keyType,a=o._zod.bag,c=a==null?void 0:a.patterns;if(i.mode==="loose"&&c&&c.size>0){const l=X(i.valueType,e,{...r,path:[...r.path,"patternProperties","*"]});s.patternProperties={};for(const f of c)s.patternProperties[f.source]=l}else(e.target==="draft-07"||e.target==="draft-2020-12")&&(s.propertyNames=X(i.keyType,e,{...r,path:[...r.path,"propertyNames"]})),s.additionalProperties=X(i.valueType,e,{...r,path:[...r.path,"additionalProperties"]});const u=o._zod.values;if(u){const l=[...u].filter(f=>typeof f=="string"||typeof f=="number");l.length>0&&(s.required=l)}},di=(t,e,n,r)=>{const s=t._zod.def,i=X(s.innerType,e,r),o=e.seen.get(t);e.target==="openapi-3.0"?(o.ref=s.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},fi=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},hi=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},mi=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,e.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},pi=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType;let o;try{o=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},gi=(t,e,n,r)=>{const s=t._zod.def,i=e.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;X(i,e,r);const o=e.seen.get(t);o.ref=i},_i=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType,n.readOnly=!0},Nu=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},nr=(t,e,n,r)=>{const s=t._zod.def;X(s.innerType,e,r);const i=e.seen.get(t);i.ref=s.innerType},Eu=(t,e,n,r)=>{const s=t._zod.innerType;X(s,e,r);const i=e.seen.get(t);i.ref=s},Vr={string:Ks,number:Ys,boolean:Qs,bigint:pu,symbol:gu,null:Xs,undefined:_u,void:yu,never:ei,any:vu,unknown:ti,date:bu,enum:ni,literal:ri,nan:wu,template_literal:ku,file:Su,success:Tu,custom:si,function:zu,transform:ii,map:$u,set:Ru,array:oi,object:ai,union:ci,intersection:ui,tuple:Pu,record:li,nullable:di,nonoptional:fi,default:hi,prefault:mi,catch:pi,pipe:gi,readonly:_i,promise:Nu,optional:nr,lazy:Eu};function Iu(t,e){if("_idmap"in t){const r=t,s=Ut({...e,processors:Vr}),i={};for(const c of r._idmap.entries()){const[u,l]=c;X(l,s)}const o={},a={registry:r,uri:e==null?void 0:e.uri,defs:i};s.external=a;for(const c of r._idmap.entries()){const[u,l]=c;Vt(s,l),o[u]=Ht(s,l)}if(Object.keys(i).length>0){const c=s.target==="draft-2020-12"?"$defs":"definitions";o.__shared={[c]:i}}return{schemas:o}}const n=Ut({...e,processors:Vr});return X(t,n),Vt(n,t),Ht(n,t)}const Cu=_("ZodISODateTime",(t,e)=>{Za.init(t,e),oe.init(t,e)});function yi(t){return qc(Cu,t)}const Ou=_("ZodISODate",(t,e)=>{Aa.init(t,e),oe.init(t,e)});function xu(t){return Fc(Ou,t)}const Zu=_("ZodISOTime",(t,e)=>{ja.init(t,e),oe.init(t,e)});function Au(t){return Uc(Zu,t)}const ju=_("ZodISODuration",(t,e)=>{Ma.init(t,e),oe.init(t,e)});function Mu(t){return Vc(ju,t)}const Lu=(t,e)=>{Os.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>Ro(t,n)},flatten:{value:n=>$o(t,n)},addIssue:{value:n=>{t.issues.push(n),t.message=JSON.stringify(t.issues,$n,2)}},addIssues:{value:n=>{t.issues.push(...n),t.message=JSON.stringify(t.issues,$n,2)}},isEmpty:{get(){return t.issues.length===0}}})},Re=_("ZodError",Lu,{Parent:Error}),Du=un(Re),qu=ln(Re),Fu=dn(Re),Uu=fn(Re),Vu=Eo(Re),Hu=Io(Re),Ju=Co(Re),Bu=Oo(Re),Wu=xo(Re),Gu=Zo(Re),Ku=Ao(Re),Yu=jo(Re),re=_("ZodType",(t,e)=>(ee.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:Jt(t,"input"),output:Jt(t,"output")}}),t.toJSONSchema=hu(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone(He(e,{checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),t.with=t.check,t.clone=(n,r)=>Me(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t),t.parse=(n,r)=>Du(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>Fu(t,n,r),t.parseAsync=async(n,r)=>qu(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>Uu(t,n,r),t.spa=t.safeParseAsync,t.encode=(n,r)=>Vu(t,n,r),t.decode=(n,r)=>Hu(t,n,r),t.encodeAsync=async(n,r)=>Ju(t,n,r),t.decodeAsync=async(n,r)=>Bu(t,n,r),t.safeEncode=(n,r)=>Wu(t,n,r),t.safeDecode=(n,r)=>Gu(t,n,r),t.safeEncodeAsync=async(n,r)=>Ku(t,n,r),t.safeDecodeAsync=async(n,r)=>Yu(t,n,r),t.refine=(n,r)=>t.check(Fl(n,r)),t.superRefine=n=>t.check(Ul(n)),t.overwrite=n=>t.check(ht(n)),t.optional=()=>ce(t),t.exactOptional=()=>Nl(t),t.nullable=()=>Br(t),t.nullish=()=>ce(Br(t)),t.nonoptional=n=>Zl(t,n),t.array=()=>H(t),t.or=n=>te([t,n]),t.and=n=>rr(t,n),t.transform=n=>Nn(t,zi(n)),t.default=n=>Cl(t,n),t.prefault=n=>xl(t,n),t.catch=n=>jl(t,n),t.pipe=n=>Nn(t,n),t.readonly=()=>Dl(t),t.describe=n=>{const r=t.clone();return vt.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){var n;return(n=vt.get(t))==null?void 0:n.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return vt.get(t);const r=t.clone();return vt.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t.apply=n=>n(t),t)),vi=_("_ZodString",(t,e)=>{tr.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>Ks(t,r,s);const n=t._zod.bag;t.format=n.format??null,t.minLength=n.minimum??null,t.maxLength=n.maximum??null,t.regex=(...r)=>t.check(Yc(...r)),t.includes=(...r)=>t.check(eu(...r)),t.startsWith=(...r)=>t.check(tu(...r)),t.endsWith=(...r)=>t.check(nu(...r)),t.min=(...r)=>t.check(Ft(...r)),t.max=(...r)=>t.check(Ws(...r)),t.length=(...r)=>t.check(Gs(...r)),t.nonempty=(...r)=>t.check(Ft(1,...r)),t.lowercase=r=>t.check(Qc(r)),t.uppercase=r=>t.check(Xc(r)),t.trim=()=>t.check(su()),t.normalize=(...r)=>t.check(ru(...r)),t.toLowerCase=()=>t.check(iu()),t.toUpperCase=()=>t.check(ou()),t.slugify=()=>t.check(au())}),Qu=_("ZodString",(t,e)=>{tr.init(t,e),vi.init(t,e),t.email=n=>t.check(bc(Xu,n)),t.url=n=>t.check(zc(el,n)),t.jwt=n=>t.check(Dc(pl,n)),t.emoji=n=>t.check($c(tl,n)),t.guid=n=>t.check(Dr(Hr,n)),t.uuid=n=>t.check(wc(Lt,n)),t.uuidv4=n=>t.check(kc(Lt,n)),t.uuidv6=n=>t.check(Sc(Lt,n)),t.uuidv7=n=>t.check(Tc(Lt,n)),t.nanoid=n=>t.check(Rc(nl,n)),t.guid=n=>t.check(Dr(Hr,n)),t.cuid=n=>t.check(Pc(rl,n)),t.cuid2=n=>t.check(Nc(sl,n)),t.ulid=n=>t.check(Ec(il,n)),t.base64=n=>t.check(jc(fl,n)),t.base64url=n=>t.check(Mc(hl,n)),t.xid=n=>t.check(Ic(ol,n)),t.ksuid=n=>t.check(Cc(al,n)),t.ipv4=n=>t.check(Oc(cl,n)),t.ipv6=n=>t.check(xc(ul,n)),t.cidrv4=n=>t.check(Zc(ll,n)),t.cidrv6=n=>t.check(Ac(dl,n)),t.e164=n=>t.check(Lc(ml,n)),t.datetime=n=>t.check(yi(n)),t.date=n=>t.check(xu(n)),t.time=n=>t.check(Au(n)),t.duration=n=>t.check(Mu(n))});function g(t){return vc(Qu,t)}const oe=_("ZodStringFormat",(t,e)=>{ne.init(t,e),vi.init(t,e)}),Xu=_("ZodEmail",(t,e)=>{$a.init(t,e),oe.init(t,e)}),Hr=_("ZodGUID",(t,e)=>{Ta.init(t,e),oe.init(t,e)}),Lt=_("ZodUUID",(t,e)=>{za.init(t,e),oe.init(t,e)}),el=_("ZodURL",(t,e)=>{Ra.init(t,e),oe.init(t,e)}),tl=_("ZodEmoji",(t,e)=>{Pa.init(t,e),oe.init(t,e)}),nl=_("ZodNanoID",(t,e)=>{Na.init(t,e),oe.init(t,e)}),rl=_("ZodCUID",(t,e)=>{Ea.init(t,e),oe.init(t,e)}),sl=_("ZodCUID2",(t,e)=>{Ia.init(t,e),oe.init(t,e)}),il=_("ZodULID",(t,e)=>{Ca.init(t,e),oe.init(t,e)}),ol=_("ZodXID",(t,e)=>{Oa.init(t,e),oe.init(t,e)}),al=_("ZodKSUID",(t,e)=>{xa.init(t,e),oe.init(t,e)}),cl=_("ZodIPv4",(t,e)=>{La.init(t,e),oe.init(t,e)}),ul=_("ZodIPv6",(t,e)=>{Da.init(t,e),oe.init(t,e)}),ll=_("ZodCIDRv4",(t,e)=>{qa.init(t,e),oe.init(t,e)}),dl=_("ZodCIDRv6",(t,e)=>{Fa.init(t,e),oe.init(t,e)}),fl=_("ZodBase64",(t,e)=>{Ua.init(t,e),oe.init(t,e)}),hl=_("ZodBase64URL",(t,e)=>{Ha.init(t,e),oe.init(t,e)}),ml=_("ZodE164",(t,e)=>{Ja.init(t,e),oe.init(t,e)}),pl=_("ZodJWT",(t,e)=>{Wa.init(t,e),oe.init(t,e)}),bi=_("ZodNumber",(t,e)=>{Fs.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>Ys(t,r,s),t.gt=(r,s)=>t.check(Fr(r,s)),t.gte=(r,s)=>t.check(bn(r,s)),t.min=(r,s)=>t.check(bn(r,s)),t.lt=(r,s)=>t.check(qr(r,s)),t.lte=(r,s)=>t.check(vn(r,s)),t.max=(r,s)=>t.check(vn(r,s)),t.int=r=>t.check(Jr(r)),t.safe=r=>t.check(Jr(r)),t.positive=r=>t.check(Fr(0,r)),t.nonnegative=r=>t.check(bn(0,r)),t.negative=r=>t.check(qr(0,r)),t.nonpositive=r=>t.check(vn(0,r)),t.multipleOf=(r,s)=>t.check(Ur(r,s)),t.step=(r,s)=>t.check(Ur(r,s)),t.finite=()=>t;const n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null});function Q(t){return Hc(bi,t)}const gl=_("ZodNumberFormat",(t,e)=>{Ga.init(t,e),bi.init(t,e)});function Jr(t){return Jc(gl,t)}const _l=_("ZodBoolean",(t,e)=>{Ka.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Qs(t,n,r)});function he(t){return Bc(_l,t)}const yl=_("ZodNull",(t,e)=>{Ya.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Xs(t,n,r)});function wi(t){return Wc(yl,t)}const vl=_("ZodUnknown",(t,e)=>{Qa.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ti()});function se(){return Gc(vl)}const bl=_("ZodNever",(t,e)=>{Xa.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ei(t,n,r)});function wl(t){return Kc(bl,t)}const kl=_("ZodArray",(t,e)=>{ec.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>oi(t,n,r,s),t.element=e.element,t.min=(n,r)=>t.check(Ft(n,r)),t.nonempty=n=>t.check(Ft(1,n)),t.max=(n,r)=>t.check(Ws(n,r)),t.length=(n,r)=>t.check(Gs(n,r)),t.unwrap=()=>t.element});function H(t,e){return cu(kl,t,e)}const ki=_("ZodObject",(t,e)=>{tc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ai(t,n,r,s),W(t,"shape",()=>e.shape),t.keyof=()=>ze(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:se()}),t.loose=()=>t.clone({...t._zod.def,catchall:se()}),t.strict=()=>t.clone({...t._zod.def,catchall:wl()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>wo(t,n),t.safeExtend=n=>ko(t,n),t.merge=n=>So(t,n),t.pick=n=>vo(t,n),t.omit=n=>bo(t,n),t.partial=(...n)=>To($i,t,n[0]),t.required=(...n)=>zo(Ri,t,n[0])});function $(t,e){const n={type:"object",shape:t??{},...P(e)};return new ki(n)}function we(t,e){return new ki({type:"object",shape:t,catchall:se(),...P(e)})}const Si=_("ZodUnion",(t,e)=>{Js.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ci(t,n,r,s),t.options=e.options});function te(t,e){return new Si({type:"union",options:t,...P(e)})}const Sl=_("ZodDiscriminatedUnion",(t,e)=>{Si.init(t,e),nc.init(t,e)});function Ti(t,e,n){return new Sl({type:"union",options:e,discriminator:t,...P(n)})}const Tl=_("ZodIntersection",(t,e)=>{rc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ui(t,n,r,s)});function rr(t,e){return new Tl({type:"intersection",left:t,right:e})}const zl=_("ZodRecord",(t,e)=>{sc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>li(t,n,r,s),t.keyType=e.keyType,t.valueType=e.valueType});function ie(t,e,n){return new zl({type:"record",keyType:t,valueType:e,...P(n)})}const Pn=_("ZodEnum",(t,e)=>{ic.init(t,e),re.init(t,e),t._zod.processJSONSchema=(r,s,i)=>ni(t,r,s),t.enum=e.entries,t.options=Object.values(e.entries);const n=new Set(Object.keys(e.entries));t.extract=(r,s)=>{const i={};for(const o of r)if(n.has(o))i[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Pn({...e,checks:[],...P(s),entries:i})},t.exclude=(r,s)=>{const i={...e.entries};for(const o of r)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Pn({...e,checks:[],...P(s),entries:i})}});function ze(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new Pn({type:"enum",entries:n,...P(e)})}const $l=_("ZodLiteral",(t,e)=>{oc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ri(t,n,r),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function I(t,e){return new $l({type:"literal",values:Array.isArray(t)?t:[t],...P(e)})}const Rl=_("ZodTransform",(t,e)=>{ac.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>ii(t,n),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Rs(t.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(Tt(i,n.value,e));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),n.issues.push(Tt(o))}};const s=e.transform(n.value,n);return s instanceof Promise?s.then(i=>(n.value=i,n)):(n.value=s,n)}});function zi(t){return new Rl({type:"transform",transform:t})}const $i=_("ZodOptional",(t,e)=>{Bs.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>nr(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function ce(t){return new $i({type:"optional",innerType:t})}const Pl=_("ZodExactOptional",(t,e)=>{cc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>nr(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Nl(t){return new Pl({type:"optional",innerType:t})}const El=_("ZodNullable",(t,e)=>{uc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>di(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Br(t){return new El({type:"nullable",innerType:t})}const Il=_("ZodDefault",(t,e)=>{lc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>hi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function Cl(t,e){return new Il({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Is(e)}})}const Ol=_("ZodPrefault",(t,e)=>{dc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>mi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function xl(t,e){return new Ol({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Is(e)}})}const Ri=_("ZodNonOptional",(t,e)=>{fc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>fi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Zl(t,e){return new Ri({type:"nonoptional",innerType:t,...P(e)})}const Al=_("ZodCatch",(t,e)=>{hc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>pi(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function jl(t,e){return new Al({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const Ml=_("ZodPipe",(t,e)=>{mc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>gi(t,n,r,s),t.in=e.in,t.out=e.out});function Nn(t,e){return new Ml({type:"pipe",in:t,out:e})}const Ll=_("ZodReadonly",(t,e)=>{pc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>_i(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function Dl(t){return new Ll({type:"readonly",innerType:t})}const Pi=_("ZodCustom",(t,e)=>{gc.init(t,e),re.init(t,e),t._zod.processJSONSchema=(n,r,s)=>si(t,n)});function ql(t,e){return uu(Pi,t??(()=>!0),e)}function Fl(t,e={}){return lu(Pi,t,e)}function Ul(t){return du(t)}function Ni(t,e){return Nn(zi(t),e)}const Ei="2025-11-25",Vl=[Ei,"2025-06-18","2025-03-26","2024-11-05","2024-10-07"],Ye="io.modelcontextprotocol/related-task",mn="2.0",me=ql(t=>t!==null&&(typeof t=="object"||typeof t=="function")),Ii=te([g(),Q().int()]),Ci=g();we({ttl:te([Q(),wi()]).optional(),pollInterval:Q().optional()});const Hl=$({ttl:Q().optional()}),Jl=$({taskId:g()}),sr=we({progressToken:Ii.optional(),[Ye]:Jl.optional()}),$e=$({_meta:sr.optional()}),Pt=$e.extend({task:Hl.optional()}),Bl=t=>Pt.safeParse(t).success,pe=$({method:g(),params:$e.loose().optional()}),Pe=$({_meta:sr.optional()}),Ne=$({method:g(),params:Pe.loose().optional()}),ge=we({_meta:sr.optional()}),pn=te([g(),Q().int()]),Oi=$({jsonrpc:I(mn),id:pn,...pe.shape}).strict(),Wr=t=>Oi.safeParse(t).success,xi=$({jsonrpc:I(mn),...Ne.shape}).strict(),Wl=t=>xi.safeParse(t).success,ir=$({jsonrpc:I(mn),id:pn,result:ge}).strict(),Dt=t=>ir.safeParse(t).success;var O;(function(t){t[t.ConnectionClosed=-32e3]="ConnectionClosed",t[t.RequestTimeout=-32001]="RequestTimeout",t[t.ParseError=-32700]="ParseError",t[t.InvalidRequest=-32600]="InvalidRequest",t[t.MethodNotFound=-32601]="MethodNotFound",t[t.InvalidParams=-32602]="InvalidParams",t[t.InternalError=-32603]="InternalError",t[t.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(O||(O={}));const or=$({jsonrpc:I(mn),id:pn.optional(),error:$({code:Q().int(),message:g(),data:se().optional()})}).strict(),Gl=t=>or.safeParse(t).success,Kl=te([Oi,xi,ir,or]);te([ir,or]);const ar=ge.strict(),Yl=Pe.extend({requestId:pn.optional(),reason:g().optional()}),cr=Ne.extend({method:I("notifications/cancelled"),params:Yl}),Ql=$({src:g(),mimeType:g().optional(),sizes:H(g()).optional(),theme:ze(["light","dark"]).optional()}),Nt=$({icons:H(Ql).optional()}),ct=$({name:g(),title:g().optional()}),Zi=ct.extend({...ct.shape,...Nt.shape,version:g(),websiteUrl:g().optional(),description:g().optional()}),Xl=rr($({applyDefaults:he().optional()}),ie(g(),se())),ed=Ni(t=>t&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0?{form:{}}:t,rr($({form:Xl.optional(),url:me.optional()}),ie(g(),se()).optional())),td=we({list:me.optional(),cancel:me.optional(),requests:we({sampling:we({createMessage:me.optional()}).optional(),elicitation:we({create:me.optional()}).optional()}).optional()}),nd=we({list:me.optional(),cancel:me.optional(),requests:we({tools:we({call:me.optional()}).optional()}).optional()}),rd=$({experimental:ie(g(),me).optional(),sampling:$({context:me.optional(),tools:me.optional()}).optional(),elicitation:ed.optional(),roots:$({listChanged:he().optional()}).optional(),tasks:td.optional()}),sd=$e.extend({protocolVersion:g(),capabilities:rd,clientInfo:Zi}),Ai=pe.extend({method:I("initialize"),params:sd}),id=$({experimental:ie(g(),me).optional(),logging:me.optional(),completions:me.optional(),prompts:$({listChanged:he().optional()}).optional(),resources:$({subscribe:he().optional(),listChanged:he().optional()}).optional(),tools:$({listChanged:he().optional()}).optional(),tasks:nd.optional()}),od=ge.extend({protocolVersion:g(),capabilities:id,serverInfo:Zi,instructions:g().optional()}),ji=Ne.extend({method:I("notifications/initialized"),params:Pe.optional()}),ur=pe.extend({method:I("ping"),params:$e.optional()}),ad=$({progress:Q(),total:ce(Q()),message:ce(g())}),cd=$({...Pe.shape,...ad.shape,progressToken:Ii}),lr=Ne.extend({method:I("notifications/progress"),params:cd}),ud=$e.extend({cursor:Ci.optional()}),Et=pe.extend({params:ud.optional()}),It=ge.extend({nextCursor:Ci.optional()}),ld=ze(["working","input_required","completed","failed","cancelled"]),Ct=$({taskId:g(),status:ld,ttl:te([Q(),wi()]),createdAt:g(),lastUpdatedAt:g(),pollInterval:ce(Q()),statusMessage:ce(g())}),gn=ge.extend({task:Ct}),dd=Pe.merge(Ct),Bt=Ne.extend({method:I("notifications/tasks/status"),params:dd}),dr=pe.extend({method:I("tasks/get"),params:$e.extend({taskId:g()})}),fr=ge.merge(Ct),hr=pe.extend({method:I("tasks/result"),params:$e.extend({taskId:g()})});ge.loose();const mr=Et.extend({method:I("tasks/list")}),pr=It.extend({tasks:H(Ct)}),gr=pe.extend({method:I("tasks/cancel"),params:$e.extend({taskId:g()})}),fd=ge.merge(Ct),Mi=$({uri:g(),mimeType:ce(g()),_meta:ie(g(),se()).optional()}),Li=Mi.extend({text:g()}),_r=g().refine(t=>{try{return atob(t),!0}catch{return!1}},{message:"Invalid Base64 string"}),Di=Mi.extend({blob:_r}),Ot=ze(["user","assistant"]),mt=$({audience:H(Ot).optional(),priority:Q().min(0).max(1).optional(),lastModified:yi({offset:!0}).optional()}),qi=$({...ct.shape,...Nt.shape,uri:g(),description:ce(g()),mimeType:ce(g()),annotations:mt.optional(),_meta:ce(we({}))}),hd=$({...ct.shape,...Nt.shape,uriTemplate:g(),description:ce(g()),mimeType:ce(g()),annotations:mt.optional(),_meta:ce(we({}))}),En=Et.extend({method:I("resources/list")}),md=It.extend({resources:H(qi)}),In=Et.extend({method:I("resources/templates/list")}),pd=It.extend({resourceTemplates:H(hd)}),yr=$e.extend({uri:g()}),gd=yr,Cn=pe.extend({method:I("resources/read"),params:gd}),_d=ge.extend({contents:H(te([Li,Di]))}),yd=Ne.extend({method:I("notifications/resources/list_changed"),params:Pe.optional()}),vd=yr,bd=pe.extend({method:I("resources/subscribe"),params:vd}),wd=yr,kd=pe.extend({method:I("resources/unsubscribe"),params:wd}),Sd=Pe.extend({uri:g()}),Td=Ne.extend({method:I("notifications/resources/updated"),params:Sd}),zd=$({name:g(),description:ce(g()),required:ce(he())}),$d=$({...ct.shape,...Nt.shape,description:ce(g()),arguments:ce(H(zd)),_meta:ce(we({}))}),On=Et.extend({method:I("prompts/list")}),Rd=It.extend({prompts:H($d)}),Pd=$e.extend({name:g(),arguments:ie(g(),g()).optional()}),xn=pe.extend({method:I("prompts/get"),params:Pd}),vr=$({type:I("text"),text:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),br=$({type:I("image"),data:_r,mimeType:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),wr=$({type:I("audio"),data:_r,mimeType:g(),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),Nd=$({type:I("tool_use"),name:g(),id:g(),input:ie(g(),se()),_meta:ie(g(),se()).optional()}),Ed=$({type:I("resource"),resource:te([Li,Di]),annotations:mt.optional(),_meta:ie(g(),se()).optional()}),Id=qi.extend({type:I("resource_link")}),kr=te([vr,br,wr,Id,Ed]),Cd=$({role:Ot,content:kr}),Od=ge.extend({description:g().optional(),messages:H(Cd)}),xd=Ne.extend({method:I("notifications/prompts/list_changed"),params:Pe.optional()}),Zd=$({title:g().optional(),readOnlyHint:he().optional(),destructiveHint:he().optional(),idempotentHint:he().optional(),openWorldHint:he().optional()}),Ad=$({taskSupport:ze(["required","optional","forbidden"]).optional()}),Fi=$({...ct.shape,...Nt.shape,description:g().optional(),inputSchema:$({type:I("object"),properties:ie(g(),me).optional(),required:H(g()).optional()}).catchall(se()),outputSchema:$({type:I("object"),properties:ie(g(),me).optional(),required:H(g()).optional()}).catchall(se()).optional(),annotations:Zd.optional(),execution:Ad.optional(),_meta:ie(g(),se()).optional()}),Zn=Et.extend({method:I("tools/list")}),jd=It.extend({tools:H(Fi)}),Sr=ge.extend({content:H(kr).default([]),structuredContent:ie(g(),se()).optional(),isError:he().optional()});Sr.or(ge.extend({toolResult:se()}));const Md=Pt.extend({name:g(),arguments:ie(g(),se()).optional()}),Wt=pe.extend({method:I("tools/call"),params:Md}),Ld=Ne.extend({method:I("notifications/tools/list_changed"),params:Pe.optional()});$({autoRefresh:he().default(!0),debounceMs:Q().int().nonnegative().default(300)});const Gt=ze(["debug","info","notice","warning","error","critical","alert","emergency"]),Dd=$e.extend({level:Gt}),Ui=pe.extend({method:I("logging/setLevel"),params:Dd}),qd=Pe.extend({level:Gt,logger:g().optional(),data:se()}),Fd=Ne.extend({method:I("notifications/message"),params:qd}),Ud=$({name:g().optional()}),Vd=$({hints:H(Ud).optional(),costPriority:Q().min(0).max(1).optional(),speedPriority:Q().min(0).max(1).optional(),intelligencePriority:Q().min(0).max(1).optional()}),Hd=$({mode:ze(["auto","required","none"]).optional()}),Jd=$({type:I("tool_result"),toolUseId:g().describe("The unique identifier for the corresponding tool call."),content:H(kr).default([]),structuredContent:$({}).loose().optional(),isError:he().optional(),_meta:ie(g(),se()).optional()}),Bd=Ti("type",[vr,br,wr]),Kt=Ti("type",[vr,br,wr,Nd,Jd]),Wd=$({role:Ot,content:te([Kt,H(Kt)]),_meta:ie(g(),se()).optional()}),Gd=Pt.extend({messages:H(Wd),modelPreferences:Vd.optional(),systemPrompt:g().optional(),includeContext:ze(["none","thisServer","allServers"]).optional(),temperature:Q().optional(),maxTokens:Q().int(),stopSequences:H(g()).optional(),metadata:me.optional(),tools:H(Fi).optional(),toolChoice:Hd.optional()}),Kd=pe.extend({method:I("sampling/createMessage"),params:Gd}),Tr=ge.extend({model:g(),stopReason:ce(ze(["endTurn","stopSequence","maxTokens"]).or(g())),role:Ot,content:Bd}),Vi=ge.extend({model:g(),stopReason:ce(ze(["endTurn","stopSequence","maxTokens","toolUse"]).or(g())),role:Ot,content:te([Kt,H(Kt)])}),Yd=$({type:I("boolean"),title:g().optional(),description:g().optional(),default:he().optional()}),Qd=$({type:I("string"),title:g().optional(),description:g().optional(),minLength:Q().optional(),maxLength:Q().optional(),format:ze(["email","uri","date","date-time"]).optional(),default:g().optional()}),Xd=$({type:ze(["number","integer"]),title:g().optional(),description:g().optional(),minimum:Q().optional(),maximum:Q().optional(),default:Q().optional()}),ef=$({type:I("string"),title:g().optional(),description:g().optional(),enum:H(g()),default:g().optional()}),tf=$({type:I("string"),title:g().optional(),description:g().optional(),oneOf:H($({const:g(),title:g()})),default:g().optional()}),nf=$({type:I("string"),title:g().optional(),description:g().optional(),enum:H(g()),enumNames:H(g()).optional(),default:g().optional()}),rf=te([ef,tf]),sf=$({type:I("array"),title:g().optional(),description:g().optional(),minItems:Q().optional(),maxItems:Q().optional(),items:$({type:I("string"),enum:H(g())}),default:H(g()).optional()}),of=$({type:I("array"),title:g().optional(),description:g().optional(),minItems:Q().optional(),maxItems:Q().optional(),items:$({anyOf:H($({const:g(),title:g()}))}),default:H(g()).optional()}),af=te([sf,of]),cf=te([nf,rf,af]),uf=te([cf,Yd,Qd,Xd]),lf=Pt.extend({mode:I("form").optional(),message:g(),requestedSchema:$({type:I("object"),properties:ie(g(),uf),required:H(g()).optional()})}),df=Pt.extend({mode:I("url"),message:g(),elicitationId:g(),url:g().url()}),ff=te([lf,df]),hf=pe.extend({method:I("elicitation/create"),params:ff}),mf=Pe.extend({elicitationId:g()}),pf=Ne.extend({method:I("notifications/elicitation/complete"),params:mf}),Yt=ge.extend({action:ze(["accept","decline","cancel"]),content:Ni(t=>t===null?void 0:t,ie(g(),te([g(),Q(),he(),H(g())])).optional())}),gf=$({type:I("ref/resource"),uri:g()}),_f=$({type:I("ref/prompt"),name:g()}),yf=$e.extend({ref:te([_f,gf]),argument:$({name:g(),value:g()}),context:$({arguments:ie(g(),g()).optional()}).optional()}),An=pe.extend({method:I("completion/complete"),params:yf});function vf(t){if(t.params.ref.type!=="ref/prompt")throw new TypeError(`Expected CompleteRequestPrompt, but got ${t.params.ref.type}`)}function bf(t){if(t.params.ref.type!=="ref/resource")throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${t.params.ref.type}`)}const wf=ge.extend({completion:we({values:H(g()).max(100),total:ce(Q().int()),hasMore:ce(he())})}),kf=$({uri:g().startsWith("file://"),name:g().optional(),_meta:ie(g(),se()).optional()}),Sf=pe.extend({method:I("roots/list"),params:$e.optional()}),Hi=ge.extend({roots:H(kf)}),Tf=Ne.extend({method:I("notifications/roots/list_changed"),params:Pe.optional()});te([ur,Ai,An,Ui,xn,On,En,In,Cn,bd,kd,Wt,Zn,dr,hr,mr,gr]);te([cr,lr,ji,Tf,Bt]);te([ar,Tr,Vi,Yt,Hi,fr,pr,gn]);te([ur,Kd,hf,Sf,dr,hr,mr,gr]);te([cr,lr,Fd,Td,yd,Ld,xd,Bt,pf]);te([ar,od,wf,Od,Rd,md,pd,_d,Sr,jd,fr,pr,gn]);class E extends Error{constructor(e,n,r){super(`MCP error ${e}: ${n}`),this.code=e,this.data=r,this.name="McpError"}static fromError(e,n,r){if(e===O.UrlElicitationRequired&&r){const s=r;if(s.elicitations)return new zf(s.elicitations,n)}return new E(e,n,r)}}class zf extends E{constructor(e,n=`URL elicitation${e.length>1?"s":""} required`){super(O.UrlElicitationRequired,n,{elicitations:e})}get elicitations(){var e;return((e=this.data)==null?void 0:e.elicitations)??[]}}class $f{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;const e=this._buffer.indexOf(`
|
|
40
|
+
`);if(e===-1)return null;const n=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),Rf(n)}clear(){this._buffer=void 0}}function Rf(t){return Kl.parse(JSON.parse(t))}function Pf(t){return JSON.stringify(t)+`
|
|
41
|
+
`}class Nf{constructor(e=Rr.stdin,n=Rr.stdout){this._stdin=e,this._stdout=n,this._readBuffer=new $f,this._started=!1,this._ondata=r=>{this._readBuffer.append(r),this.processReadBuffer()},this._onerror=r=>{var s;(s=this.onerror)==null||s.call(this,r)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){var e,n;for(;;)try{const r=this._readBuffer.readMessage();if(r===null)break;(e=this.onmessage)==null||e.call(this,r)}catch(r){(n=this.onerror)==null||n.call(this,r)}}async close(){var n;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(n=this.onclose)==null||n.call(this)}send(e){return new Promise(n=>{const r=Pf(e);this._stdout.write(r)?n():this._stdout.once("drain",n)})}}const Ef=[/^https?:\/\/localhost(:\d+)?$/,/^https?:\/\/127\.0\.0\.1(:\d+)?$/,/^https?:\/\/playground\.wordpress\.net$/];class If{constructor(e=[]){this.additionalAllowedOrigins=new Set,this.connections=new Map,this.sites=new Map,this.pendingRequests=new Map,this.requestId=0,this.sessionToken=uo.randomUUID(),this.siteActivatedListeners=[];for(const n of e)try{this.additionalAllowedOrigins.add(new URL(n).origin)}catch{}}getPort(){var n;const e=(n=this.httpServer)==null?void 0:n.address();if(!e)throw new Error("WebSocket server is not running");return e.port}startWebSocketServer(e=0){return new Promise((n,r)=>{const s=co.createServer((o,a)=>{this.handleHttpRequest(o,a)});this.httpServer=s;const i=new ao.WebSocketServer({server:s,verifyClient:(o,a)=>{if(!this.isAllowedOrigin(o.origin)){console.error(`[MCP] Rejected WebSocket connection from origin: ${o.origin}`),a(!1,403,"Forbidden");return}if(new URL(o.req.url??"/",`http://${o.req.headers.host}`).searchParams.get("token")!==this.sessionToken){console.error("[MCP] Rejected WebSocket connection: invalid token"),a(!1,401,"Invalid token");return}a(!0)}});this.wss=i,s.on("error",o=>{o.code==="EADDRINUSE"&&console.error(`[MCP] Port ${e} is already in use. Kill the other process (lsof -i :${e}).`),r(o)}),s.listen(e,"127.0.0.1",()=>{const o=this.getPort();console.error(`[MCP] WebSocket server listening on ws://127.0.0.1:${o}`),n(i)}),i.on("connection",o=>{this.handleConnection(o)})})}handleHttpRequest(e,n){if(e.url==="/bridge-token"){const r=e.headers.origin;if(!r||!this.isAllowedOrigin(r)){n.writeHead(403),n.end("Forbidden");return}if(n.setHeader("Access-Control-Allow-Origin",r),n.setHeader("Access-Control-Allow-Methods","GET"),e.method==="OPTIONS"){n.writeHead(204),n.end();return}n.writeHead(200,{"Content-Type":"application/json"}),n.end(JSON.stringify({token:this.sessionToken}));return}n.writeHead(404),n.end()}isAllowedOrigin(e){return e?this.additionalAllowedOrigins.has(e)||Ef.some(n=>n.test(e)):!0}handleConnection(e){let n;e.on("message",r=>{let s;try{s=JSON.parse(r.toString())}catch{console.error("[MCP] Failed to parse message");return}try{if(s.type==="register"){const i=!n;n=s.tabId,this.connections.set(n,e),this.updateSitesForTab(n,s.sites),i&&console.error(`[MCP] Tab registered: ${n} (${s.sites.length} sites)`);return}if(s.type==="response"){const i=this.pendingRequests.get(s.id);if(i)if(this.pendingRequests.delete(s.id),s.error){const o=typeof s.error=="string"?s.error:JSON.stringify(s.error);i.reject(new Error(o))}else i.resolve(s.value)}}catch(i){console.error("[MCP] Error handling message:",i)}}),e.on("close",()=>{if(n){console.error(`[MCP] Tab disconnected: ${n}`);for(const[r,s]of this.pendingRequests)s.tabId===n&&(s.reject(new Error("Browser tab disconnected")),this.pendingRequests.delete(r));this.connections.delete(n);for(const[r,s]of this.sites){s.reportedByTabs.delete(n);const i=s.activeInTabs.indexOf(n);i!==-1&&s.activeInTabs.splice(i,1),s.reportedByTabs.size===0&&this.sites.delete(r)}}})}updateSitesForTab(e,n){const r=new Set(n.map(s=>s.slug));for(const[s,i]of this.sites)if(!r.has(i.siteSlug)){i.reportedByTabs.delete(e);const o=i.activeInTabs.indexOf(e);o!==-1&&i.activeInTabs.splice(o,1),i.reportedByTabs.size===0&&this.sites.delete(s)}for(const s of n){const i=s.slug;let o=this.sites.get(i);if(o||(o={siteSlug:s.slug,siteName:s.name,storage:s.storage,reportedByTabs:new Set,activeInTabs:[]},this.sites.set(i,o)),o.siteName=s.name,o.storage=s.storage,o.reportedByTabs.add(e),s.isActive){const a=o.activeInTabs.length>0,c=o.activeInTabs.indexOf(e);if(c!==-1&&o.activeInTabs.splice(c,1),o.activeInTabs.unshift(e),!a)for(const u of this.siteActivatedListeners)u(i)}else{const a=o.activeInTabs.indexOf(e);a!==-1&&o.activeInTabs.splice(a,1)}}}sendCommand(e,n,r=[]){const s=this.sites.get(e);if(!s)return Promise.reject(new Error(`Unknown site: ${e}`));const i=n.startsWith("__");let o;if(i){if(this.connections.size===0)return Promise.reject(new Error("No browser tabs connected"));o=[...s.reportedByTabs].find(l=>this.connections.has(l))??this.connections.keys().next().value}else{if(s.activeInTabs.length===0)return Promise.reject(new Error(`Site "${s.siteName}" (${e}) is not active in any tab. Use open_site_in_new_tab to activate it.`));o=s.activeInTabs[0]}const a=this.connections.get(o);if(!a)return Promise.reject(new Error("Target browser tab disconnected"));const c=String(++this.requestId);return new Promise((u,l)=>{const p=setTimeout(()=>{this.pendingRequests.delete(c),l(new Error(`Command "${n}" timed out after 300 seconds`))},3e5);this.pendingRequests.set(c,{resolve:m=>{clearTimeout(p),u(m)},reject:m=>{clearTimeout(p),l(m)},tabId:o}),a.send(JSON.stringify({id:c,type:"command",method:n,args:r,siteSlug:s.siteSlug}))})}waitForSiteActive(e,n){const r=this.sites.get(e);return r&&r.activeInTabs.length>0?Promise.resolve(r):new Promise((s,i)=>{const o=setTimeout(()=>{this.removeSiteActivatedListener(a),i(new Error(`Timed out waiting for site ${e} to become active`))},n),a=c=>{c===e&&(clearTimeout(o),this.removeSiteActivatedListener(a),s(this.sites.get(e)))};this.siteActivatedListeners.push(a)})}removeSiteActivatedListener(e){const n=this.siteActivatedListeners.indexOf(e);n!==-1&&this.siteActivatedListeners.splice(n,1)}listSites(){return[...this.sites.entries()].map(([e,n])=>({siteId:e,name:n.siteName,storage:Qe.formatStorageLabel(n.storage),isActive:n.activeInTabs.length>0}))}getTabCount(){return this.connections.size}isConnected(){return this.connections.size>0}async close(){if(this.wss)for(const e of this.wss.clients)e.close();return new Promise(e=>{const n=()=>{this.httpServer?this.httpServer.close(()=>e()):e()};this.wss?this.wss.close(()=>n()):n()})}}var B;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function n(s){throw new Error}t.assertNever=n,t.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},t.getValidEnumValues=s=>{const i=t.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return t.objectValues(o)},t.objectValues=s=>t.objectKeys(s).map(function(i){return s[i]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},t.find=(s,i)=>{for(const o of s)if(i(o))return o},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}t.joinValues=r,t.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(B||(B={}));var Gr;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Gr||(Gr={}));const R=B.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),De=t=>{switch(typeof t){case"undefined":return R.undefined;case"string":return R.string;case"number":return Number.isNaN(t)?R.nan:R.number;case"boolean":return R.boolean;case"function":return R.function;case"bigint":return R.bigint;case"symbol":return R.symbol;case"object":return Array.isArray(t)?R.array:t===null?R.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?R.promise:typeof Map<"u"&&t instanceof Map?R.map:typeof Set<"u"&&t instanceof Set?R.set:typeof Date<"u"&&t instanceof Date?R.date:R.object;default:return R.unknown}},k=B.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 je extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,c=0;for(;c<o.path.length;){const u=o.path[c];c===o.path.length-1?(a[u]=a[u]||{_errors:[]},a[u]._errors.push(n(o))):a[u]=a[u]||{_errors:[]},a=a[u],c++}}};return s(this),r}static assert(e){if(!(e instanceof je))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,B.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n=Object.create(null),r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}je.create=t=>new je(t);const jn=(t,e)=>{let n;switch(t.code){case k.invalid_type:t.received===R.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case k.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,B.jsonStringifyReplacer)}`;break;case k.unrecognized_keys:n=`Unrecognized key(s) in object: ${B.joinValues(t.keys,", ")}`;break;case k.invalid_union:n="Invalid input";break;case k.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${B.joinValues(t.options)}`;break;case k.invalid_enum_value:n=`Invalid enum value. Expected ${B.joinValues(t.options)}, received '${t.received}'`;break;case k.invalid_arguments:n="Invalid function arguments";break;case k.invalid_return_type:n="Invalid function return type";break;case k.invalid_date:n="Invalid date";break;case k.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:B.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case k.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case k.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case k.custom:n="Invalid input";break;case k.invalid_intersection_types:n="Intersection results could not be merged";break;case k.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case k.not_finite:n="Number must be finite";break;default:n=e.defaultError,B.assertNever(t)}return{message:n}};let Cf=jn;function Of(){return Cf}const xf=t=>{const{data:e,path:n,errorMaps:r,issueData:s}=t,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)a=u(o,{data:e,defaultError:a}).message;return{...s,path:i,message:a}};function z(t,e){const n=Of(),r=xf({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===jn?void 0:jn].filter(s=>!!s)});t.common.issues.push(r)}class be{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const s of n){if(s.status==="aborted")return M;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return be.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return M;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:e.value,value:r}}}const M=Object.freeze({status:"aborted"}),bt=t=>({status:"dirty",value:t}),Ee=t=>({status:"valid",value:t}),Kr=t=>t.status==="aborted",Yr=t=>t.status==="dirty",ut=t=>t.status==="valid",Qt=t=>typeof Promise<"u"&&t instanceof Promise;var N;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(N||(N={}));class xe{constructor(e,n,r,s){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=s}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}}const Qr=(t,e)=>{if(ut(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new je(t.common.issues);return this._error=n,this._error}}};function D(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:s}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,a)=>{const{message:c}=t;return o.code==="invalid_enum_value"?{message:c??a.defaultError}:typeof a.data>"u"?{message:c??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:c??n??a.defaultError}},description:s}}class V{get description(){return this._def.description}_getType(e){return De(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:De(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new be,ctx:{common:e.parent.common,data:e.data,parsedType:De(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(Qt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){const r={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)},s=this._parseSync({data:e,path:r.path,parent:r});return Qr(r,s)}"~validate"(e){var r,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)};if(!this["~standard"].async)try{const i=this._parseSync({data:e,path:[],parent:n});return ut(i)?{value:i.value}:{issues:n.common.issues}}catch(i){(s=(r=i==null?void 0:i.message)==null?void 0:r.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(i=>ut(i)?{value:i.value}:{issues:n.common.issues})}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:De(e)},s=this._parse({data:e,path:r.path,parent:r}),i=await(Qt(s)?s:Promise.resolve(s));return Qr(r,i)}refine(e,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=e(s),a=()=>i.addIssue({code:k.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(e){return new dt({schema:this,typeName:S.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:n=>this["~validate"](n)}}optional(){return qe.create(this,this._def)}nullable(){return ft.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Oe.create(this)}promise(){return rn.create(this,this._def)}or(e){return en.create([this,e],this._def)}and(e){return tn.create(this,e,this._def)}transform(e){return new dt({...D(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new qn({...D(this._def),innerType:this,defaultValue:n,typeName:S.ZodDefault})}brand(){return new rh({typeName:S.ZodBranded,type:this,...D(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new Fn({...D(this._def),innerType:this,catchValue:n,typeName:S.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return zr.create(this,e)}readonly(){return Un.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Zf=/^c[^\s-]{8,}$/i,Af=/^[0-9a-z]+$/,jf=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Mf=/^[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,Lf=/^[a-z0-9_-]{21}$/i,Df=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,qf=/^[-+]?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)?)??$/,Ff=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Uf="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let wn;const Vf=/^(?:(?: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])$/,Hf=/^(?:(?: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])$/,Jf=/^(([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]))$/,Bf=/^(([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])$/,Wf=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Gf=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ji="((\\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])))",Kf=new RegExp(`^${Ji}$`);function Bi(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Yf(t){return new RegExp(`^${Bi(t)}$`)}function Qf(t){let e=`${Ji}T${Bi(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Xf(t,e){return!!((e==="v4"||!e)&&Vf.test(t)||(e==="v6"||!e)&&Jf.test(t))}function eh(t,e){if(!Df.test(t))return!1;try{const[n]=t.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function th(t,e){return!!((e==="v4"||!e)&&Hf.test(t)||(e==="v6"||!e)&&Bf.test(t))}class Ae extends V{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==R.string){const i=this._getOrReturnCtx(e);return z(i,{code:k.invalid_type,expected:R.string,received:i.parsedType}),M}const r=new be;let s;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:k.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:k.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=e.data.length>i.value,a=e.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(e,s),o?z(s,{code:k.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&z(s,{code:k.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")Ff.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"email",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")wn||(wn=new RegExp(Uf,"u")),wn.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"emoji",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")Mf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"uuid",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")Lf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"nanoid",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")Zf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cuid",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Af.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cuid2",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")jf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"ulid",code:k.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),z(s,{validation:"url",code:k.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"regex",code:k.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?Qf(i).test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?Kf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?Yf(i).test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{code:k.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?qf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"duration",code:k.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?Xf(e.data,i.version)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"ip",code:k.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?eh(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"jwt",code:k.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?th(e.data,i.version)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"cidr",code:k.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?Wf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"base64",code:k.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Gf.test(e.data)||(s=this._getOrReturnCtx(e,s),z(s,{validation:"base64url",code:k.invalid_string,message:i.message}),r.dirty()):B.assertNever(i);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(s=>e.test(s),{validation:n,code:k.invalid_string,...N.errToObj(r)})}_addCheck(e){return new Ae({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...N.errToObj(e)})}url(e){return this._addCheck({kind:"url",...N.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...N.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...N.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...N.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...N.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...N.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...N.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...N.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...N.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...N.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...N.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...N.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...N.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...N.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...N.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...N.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...N.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...N.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...N.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...N.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...N.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...N.errToObj(n)})}nonempty(e){return this.min(1,N.errToObj(e))}trim(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Ae({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Ae.create=t=>new Ae({checks:[],typeName:S.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...D(t)});function nh(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(t.toFixed(s).replace(".","")),o=Number.parseInt(e.toFixed(s).replace(".",""));return i%o/10**s}class zt extends V{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==R.number){const i=this._getOrReturnCtx(e);return z(i,{code:k.invalid_type,expected:R.number,received:i.parsedType}),M}let r;const s=new be;for(const i of this._def.checks)i.kind==="int"?B.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:k.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?nh(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:k.not_finite,message:i.message}),s.dirty()):B.assertNever(i);return{status:s.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,N.toString(n))}gt(e,n){return this.setLimit("min",e,!1,N.toString(n))}lte(e,n){return this.setLimit("max",e,!0,N.toString(n))}lt(e,n){return this.setLimit("max",e,!1,N.toString(n))}setLimit(e,n,r,s){return new zt({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:N.toString(s)}]})}_addCheck(e){return new zt({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:N.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:N.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:N.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:N.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:N.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:N.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:N.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:N.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:N.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&B.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}zt.create=t=>new zt({checks:[],typeName:S.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...D(t)});class $t extends V{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==R.bigint)return this._getInvalidInput(e);let r;const s=new be;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),z(r,{code:k.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):B.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return z(n,{code:k.invalid_type,expected:R.bigint,received:n.parsedType}),M}gte(e,n){return this.setLimit("min",e,!0,N.toString(n))}gt(e,n){return this.setLimit("min",e,!1,N.toString(n))}lte(e,n){return this.setLimit("max",e,!0,N.toString(n))}lt(e,n){return this.setLimit("max",e,!1,N.toString(n))}setLimit(e,n,r,s){return new $t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:N.toString(s)}]})}_addCheck(e){return new $t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:N.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:N.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:N.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:N.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:N.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}$t.create=t=>new $t({checks:[],typeName:S.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...D(t)});class Mn extends V{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==R.boolean){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.boolean,received:r.parsedType}),M}return Ee(e.data)}}Mn.create=t=>new Mn({typeName:S.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...D(t)});class Xt extends V{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==R.date){const i=this._getOrReturnCtx(e);return z(i,{code:k.invalid_type,expected:R.date,received:i.parsedType}),M}if(Number.isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return z(i,{code:k.invalid_date}),M}const r=new be;let s;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:k.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),z(s,{code:k.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):B.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Xt({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:N.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:N.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}Xt.create=t=>new Xt({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:S.ZodDate,...D(t)});class Xr extends V{_parse(e){if(this._getType(e)!==R.symbol){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.symbol,received:r.parsedType}),M}return Ee(e.data)}}Xr.create=t=>new Xr({typeName:S.ZodSymbol,...D(t)});class es extends V{_parse(e){if(this._getType(e)!==R.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.undefined,received:r.parsedType}),M}return Ee(e.data)}}es.create=t=>new es({typeName:S.ZodUndefined,...D(t)});class ts extends V{_parse(e){if(this._getType(e)!==R.null){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.null,received:r.parsedType}),M}return Ee(e.data)}}ts.create=t=>new ts({typeName:S.ZodNull,...D(t)});class ns extends V{constructor(){super(...arguments),this._any=!0}_parse(e){return Ee(e.data)}}ns.create=t=>new ns({typeName:S.ZodAny,...D(t)});class Ln extends V{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ee(e.data)}}Ln.create=t=>new Ln({typeName:S.ZodUnknown,...D(t)});class Ve extends V{_parse(e){const n=this._getOrReturnCtx(e);return z(n,{code:k.invalid_type,expected:R.never,received:n.parsedType}),M}}Ve.create=t=>new Ve({typeName:S.ZodNever,...D(t)});class rs extends V{_parse(e){if(this._getType(e)!==R.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.void,received:r.parsedType}),M}return Ee(e.data)}}rs.create=t=>new rs({typeName:S.ZodVoid,...D(t)});class Oe extends V{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),s=this._def;if(n.parsedType!==R.array)return z(n,{code:k.invalid_type,expected:R.array,received:n.parsedType}),M;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(o||a)&&(z(n,{code:o?k.too_big:k.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(z(n,{code:k.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(z(n,{code:k.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>s.type._parseAsync(new xe(n,o,n.path,a)))).then(o=>be.mergeArray(r,o));const i=[...n.data].map((o,a)=>s.type._parseSync(new xe(n,o,n.path,a)));return be.mergeArray(r,i)}get element(){return this._def.type}min(e,n){return new Oe({...this._def,minLength:{value:e,message:N.toString(n)}})}max(e,n){return new Oe({...this._def,maxLength:{value:e,message:N.toString(n)}})}length(e,n){return new Oe({...this._def,exactLength:{value:e,message:N.toString(n)}})}nonempty(e){return this.min(1,e)}}Oe.create=(t,e)=>new Oe({type:t,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...D(e)});function tt(t){if(t instanceof le){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=qe.create(tt(r))}return new le({...t._def,shape:()=>e})}else return t instanceof Oe?new Oe({...t._def,type:tt(t.element)}):t instanceof qe?qe.create(tt(t.unwrap())):t instanceof ft?ft.create(tt(t.unwrap())):t instanceof Xe?Xe.create(t.items.map(e=>tt(e))):t}class le extends V{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=B.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==R.object){const u=this._getOrReturnCtx(e);return z(u,{code:k.invalid_type,expected:R.object,received:u.parsedType}),M}const{status:r,ctx:s}=this._processInputParams(e),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof Ve&&this._def.unknownKeys==="strip"))for(const u in s.data)o.includes(u)||a.push(u);const c=[];for(const u of o){const l=i[u],f=s.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new xe(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Ve){const u=this._def.unknownKeys;if(u==="passthrough")for(const l of a)c.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(u==="strict")a.length>0&&(z(s,{code:k.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const l of a){const f=s.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new xe(s,f,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const l of c){const f=await l.key,p=await l.value;u.push({key:f,value:p,alwaysSet:l.alwaysSet})}return u}).then(u=>be.mergeObjectSync(r,u)):be.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return N.errToObj,new le({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var i,o;const s=((o=(i=this._def).errorMap)==null?void 0:o.call(i,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:N.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new le({...this._def,unknownKeys:"strip"})}passthrough(){return new le({...this._def,unknownKeys:"passthrough"})}extend(e){return new le({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new le({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:S.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new le({...this._def,catchall:e})}pick(e){const n={};for(const r of B.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new le({...this._def,shape:()=>n})}omit(e){const n={};for(const r of B.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new le({...this._def,shape:()=>n})}deepPartial(){return tt(this)}partial(e){const n={};for(const r of B.objectKeys(this.shape)){const s=this.shape[r];e&&!e[r]?n[r]=s:n[r]=s.optional()}return new le({...this._def,shape:()=>n})}required(e){const n={};for(const r of B.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof qe;)i=i._def.innerType;n[r]=i}return new le({...this._def,shape:()=>n})}keyof(){return Wi(B.objectKeys(this.shape))}}le.create=(t,e)=>new le({shape:()=>t,unknownKeys:"strip",catchall:Ve.create(),typeName:S.ZodObject,...D(e)});le.strictCreate=(t,e)=>new le({shape:()=>t,unknownKeys:"strict",catchall:Ve.create(),typeName:S.ZodObject,...D(e)});le.lazycreate=(t,e)=>new le({shape:t,unknownKeys:"strip",catchall:Ve.create(),typeName:S.ZodObject,...D(e)});class en extends V{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new je(a.ctx.common.issues));return z(n,{code:k.invalid_union,unionErrors:o}),M}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},l=c._parseSync({data:n.data,path:n.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!i&&(i={result:l,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(c=>new je(c));return z(n,{code:k.invalid_union,unionErrors:a}),M}}get options(){return this._def.options}}en.create=(t,e)=>new en({options:t,typeName:S.ZodUnion,...D(e)});function Dn(t,e){const n=De(t),r=De(e);if(t===e)return{valid:!0,data:t};if(n===R.object&&r===R.object){const s=B.objectKeys(e),i=B.objectKeys(t).filter(a=>s.indexOf(a)!==-1),o={...t,...e};for(const a of i){const c=Dn(t[a],e[a]);if(!c.valid)return{valid:!1};o[a]=c.data}return{valid:!0,data:o}}else if(n===R.array&&r===R.array){if(t.length!==e.length)return{valid:!1};const s=[];for(let i=0;i<t.length;i++){const o=t[i],a=e[i],c=Dn(o,a);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return n===R.date&&r===R.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class tn extends V{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),s=(i,o)=>{if(Kr(i)||Kr(o))return M;const a=Dn(i.value,o.value);return a.valid?((Yr(i)||Yr(o))&&n.dirty(),{status:n.value,value:a.data}):(z(r,{code:k.invalid_intersection_types}),M)};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(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}tn.create=(t,e,n)=>new tn({left:t,right:e,typeName:S.ZodIntersection,...D(n)});class Xe extends V{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==R.array)return z(r,{code:k.invalid_type,expected:R.array,received:r.parsedType}),M;if(r.data.length<this._def.items.length)return z(r,{code:k.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),M;!this._def.rest&&r.data.length>this._def.items.length&&(z(r,{code:k.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new xe(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>be.mergeArray(n,o)):be.mergeArray(n,i)}get items(){return this._def.items}rest(e){return new Xe({...this._def,rest:e})}}Xe.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Xe({items:t,typeName:S.ZodTuple,rest:null,...D(e)})};class nn extends V{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==R.object)return z(r,{code:k.invalid_type,expected:R.object,received:r.parsedType}),M;const s=[],i=this._def.keyType,o=this._def.valueType;for(const a in r.data)s.push({key:i._parse(new xe(r,a,r.path,a)),value:o._parse(new xe(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?be.mergeObjectAsync(n,s):be.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof V?new nn({keyType:e,valueType:n,typeName:S.ZodRecord,...D(r)}):new nn({keyType:Ae.create(),valueType:e,typeName:S.ZodRecord,...D(n)})}}class ss extends V{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==R.map)return z(r,{code:k.invalid_type,expected:R.map,received:r.parsedType}),M;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new xe(r,a,r.path,[u,"key"])),value:i._parse(new xe(r,c,r.path,[u,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of o){const u=await c.key,l=await c.value;if(u.status==="aborted"||l.status==="aborted")return M;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const c of o){const u=c.key,l=c.value;if(u.status==="aborted"||l.status==="aborted")return M;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}}}}ss.create=(t,e,n)=>new ss({valueType:e,keyType:t,typeName:S.ZodMap,...D(n)});class Rt extends V{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==R.set)return z(r,{code:k.invalid_type,expected:R.set,received:r.parsedType}),M;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(z(r,{code:k.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(z(r,{code:k.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(c){const u=new Set;for(const l of c){if(l.status==="aborted")return M;l.status==="dirty"&&n.dirty(),u.add(l.value)}return{status:n.value,value:u}}const a=[...r.data.values()].map((c,u)=>i._parse(new xe(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>o(c)):o(a)}min(e,n){return new Rt({...this._def,minSize:{value:e,message:N.toString(n)}})}max(e,n){return new Rt({...this._def,maxSize:{value:e,message:N.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Rt.create=(t,e)=>new Rt({valueType:t,minSize:null,maxSize:null,typeName:S.ZodSet,...D(e)});class is extends V{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}is.create=(t,e)=>new is({getter:t,typeName:S.ZodLazy,...D(e)});class os extends V{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return z(n,{received:n.data,code:k.invalid_literal,expected:this._def.value}),M}return{status:"valid",value:e.data}}get value(){return this._def.value}}os.create=(t,e)=>new os({value:t,typeName:S.ZodLiteral,...D(e)});function Wi(t,e){return new lt({values:t,typeName:S.ZodEnum,...D(e)})}class lt extends V{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{expected:B.joinValues(r),received:n.parsedType,code:k.invalid_type}),M}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{received:n.data,code:k.invalid_enum_value,options:r}),M}return Ee(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return lt.create(e,{...this._def,...n})}exclude(e,n=this._def){return lt.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}lt.create=Wi;class as extends V{_parse(e){const n=B.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==R.string&&r.parsedType!==R.number){const s=B.objectValues(n);return z(r,{expected:B.joinValues(s),received:r.parsedType,code:k.invalid_type}),M}if(this._cache||(this._cache=new Set(B.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const s=B.objectValues(n);return z(r,{received:r.data,code:k.invalid_enum_value,options:s}),M}return Ee(e.data)}get enum(){return this._def.values}}as.create=(t,e)=>new as({values:t,typeName:S.ZodNativeEnum,...D(e)});class rn extends V{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==R.promise&&n.common.async===!1)return z(n,{code:k.invalid_type,expected:R.promise,received:n.parsedType}),M;const r=n.parsedType===R.promise?n.data:Promise.resolve(n.data);return Ee(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}rn.create=(t,e)=>new rn({type:t,typeName:S.ZodPromise,...D(e)});class dt extends V{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:o=>{z(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return M;const c=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return c.status==="aborted"?M:c.status==="dirty"||n.value==="dirty"?bt(c.value):c});{if(n.value==="aborted")return M;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?M:a.status==="dirty"||n.value==="dirty"?bt(a.value):a}}if(s.type==="refinement"){const o=a=>{const c=s.refinement(a,i);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?M:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?M:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!ut(o))return M;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>ut(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:n.value,value:a})):M);B.assertNever(s)}}dt.create=(t,e,n)=>new dt({schema:t,typeName:S.ZodEffects,effect:e,...D(n)});dt.createWithPreprocess=(t,e,n)=>new dt({schema:e,effect:{type:"preprocess",transform:t},typeName:S.ZodEffects,...D(n)});class qe extends V{_parse(e){return this._getType(e)===R.undefined?Ee(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}qe.create=(t,e)=>new qe({innerType:t,typeName:S.ZodOptional,...D(e)});class ft extends V{_parse(e){return this._getType(e)===R.null?Ee(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ft.create=(t,e)=>new ft({innerType:t,typeName:S.ZodNullable,...D(e)});class qn extends V{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===R.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}qn.create=(t,e)=>new qn({innerType:t,typeName:S.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...D(e)});class Fn extends V{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Qt(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new je(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new je(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Fn.create=(t,e)=>new Fn({innerType:t,typeName:S.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...D(e)});class cs extends V{_parse(e){if(this._getType(e)!==R.nan){const r=this._getOrReturnCtx(e);return z(r,{code:k.invalid_type,expected:R.nan,received:r.parsedType}),M}return{status:"valid",value:e.data}}}cs.create=t=>new cs({typeName:S.ZodNaN,...D(t)});class rh extends V{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class zr extends V{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?M:i.status==="dirty"?(n.dirty(),bt(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?M:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,n){return new zr({in:e,out:n,typeName:S.ZodPipeline})}}class Un extends V{_parse(e){const n=this._def.innerType._parse(e),r=s=>(ut(s)&&(s.value=Object.freeze(s.value)),s);return Qt(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Un.create=(t,e)=>new Un({innerType:t,typeName:S.ZodReadonly,...D(e)});var S;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(S||(S={}));const wt=Ae.create,sh=Mn.create,us=Ln.create;Ve.create;Oe.create;const Vn=le.create,ih=en.create;tn.create;Xe.create;const ls=nn.create;lt.create;rn.create;qe.create;ft.create;const oh=_("ZodMiniType",(t,e)=>{if(!t._zod)throw new Error("Uninitialized schema in ZodMiniType.");ee.init(t,e),t.def=e,t.type=e.type,t.parse=(n,r)=>Po(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>Xn(t,n,r),t.parseAsync=async(n,r)=>No(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>er(t,n,r),t.check=(...n)=>t.clone({...e,checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0}),t.with=t.check,t.clone=(n,r)=>Me(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t),t.apply=n=>n(t)}),ah=_("ZodMiniObject",(t,e)=>{Hs.init(t,e),oh.init(t,e),W(t,"shape",()=>e.shape)});function ds(t,e){const n={type:"object",shape:t??{},...P(e)};return new ah(n)}function Ze(t){return!!t._zod}function st(t){const e=Object.values(t);if(e.length===0)return ds({});const n=e.every(Ze),r=e.every(s=>!Ze(s));if(n)return ds(t);if(r)return Vn(t);throw new Error("Mixed Zod versions detected in object shape.")}function kt(t,e){return Ze(t)?Xn(t,e):t.safeParse(e)}async function kn(t,e){return Ze(t)?await er(t,e):await t.safeParseAsync(e)}function xt(t){var n,r;if(!t)return;let e;if(Ze(t)?e=(r=(n=t._zod)==null?void 0:n.def)==null?void 0:r.shape:e=t.shape,!!e){if(typeof e=="function")try{return e()}catch{return}return e}}function gt(t){var e;if(t){if(typeof t=="object"){const n=t,r=t;if(!n._def&&!r._zod){const s=Object.values(t);if(s.length>0&&s.every(i=>typeof i=="object"&&i!==null&&(i._def!==void 0||i._zod!==void 0||typeof i.parse=="function")))return st(t)}}if(Ze(t)){const r=(e=t._zod)==null?void 0:e.def;if(r&&(r.type==="object"||r.shape!==void 0))return t}else if(t.shape!==void 0)return t}}function Sn(t){if(t&&typeof t=="object"){if("message"in t&&typeof t.message=="string")return t.message;if("issues"in t&&Array.isArray(t.issues)&&t.issues.length>0){const e=t.issues[0];if(e&&typeof e=="object"&&"message"in e)return String(e.message)}try{return JSON.stringify(t)}catch{return String(t)}}return String(t)}function ch(t){return t.description}function uh(t){var n,r,s;if(Ze(t))return((r=(n=t._zod)==null?void 0:n.def)==null?void 0:r.type)==="optional";const e=t;return typeof t.isOptional=="function"?t.isOptional():((s=e._def)==null?void 0:s.typeName)==="ZodOptional"}function Gi(t){var s;if(Ze(t)){const o=(s=t._zod)==null?void 0:s.def;if(o){if(o.value!==void 0)return o.value;if(Array.isArray(o.values)&&o.values.length>0)return o.values[0]}}const n=t._def;if(n){if(n.value!==void 0)return n.value;if(Array.isArray(n.values)&&n.values.length>0)return n.values[0]}const r=t.value;if(r!==void 0)return r}function Ke(t){return t==="completed"||t==="failed"||t==="cancelled"}const lh=Symbol("Let zodToJsonSchema decide on which parser to use"),fs={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"},dh=t=>typeof t=="string"?{...fs,name:t}:{...fs,...t},fh=t=>{const e=dh(t),n=e.name!==void 0?[...e.basePath,e.definitionPath,e.name]:e.basePath;return{...e,flags:{hasReferencedOpenAiAnyType:!1},currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(e.definitions).map(([r,s])=>[s._def,{def:s._def,path:[...e.basePath,e.definitionPath,r],jsonSchema:void 0}]))}};function Ki(t,e,n,r){r!=null&&r.errorMessages&&n&&(t.errorMessage={...t.errorMessage,[e]:n})}function Y(t,e,n,r,s){t[e]=n,Ki(t,e,r,s)}const Yi=(t,e)=>{let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];n++);return[(t.length-n).toString(),...e.slice(n)].join("/")};function ke(t){if(t.target!=="openAi")return{};const e=[...t.basePath,t.definitionPath,t.openAiAnyTypeName];return t.flags.hasReferencedOpenAiAnyType=!0,{$ref:t.$refStrategy==="relative"?Yi(e,t.currentPath):e.join("/")}}function hh(t,e){var r,s,i;const n={type:"array"};return(r=t.type)!=null&&r._def&&((i=(s=t.type)==null?void 0:s._def)==null?void 0:i.typeName)!==S.ZodAny&&(n.items=G(t.type._def,{...e,currentPath:[...e.currentPath,"items"]})),t.minLength&&Y(n,"minItems",t.minLength.value,t.minLength.message,e),t.maxLength&&Y(n,"maxItems",t.maxLength.value,t.maxLength.message,e),t.exactLength&&(Y(n,"minItems",t.exactLength.value,t.exactLength.message,e),Y(n,"maxItems",t.exactLength.value,t.exactLength.message,e)),n}function mh(t,e){const n={type:"integer",format:"int64"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"min":e.target==="jsonSchema7"?r.inclusive?Y(n,"minimum",r.value,r.message,e):Y(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),Y(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?Y(n,"maximum",r.value,r.message,e):Y(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),Y(n,"maximum",r.value,r.message,e));break;case"multipleOf":Y(n,"multipleOf",r.value,r.message,e);break}return n}function ph(){return{type:"boolean"}}function Qi(t,e){return G(t.type._def,e)}const gh=(t,e)=>G(t.innerType._def,e);function Xi(t,e,n){const r=n??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((s,i)=>Xi(t,e,s))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return _h(t,e)}}const _h=(t,e)=>{const n={type:"integer",format:"unix-time"};if(e.target==="openApi3")return n;for(const r of t.checks)switch(r.kind){case"min":Y(n,"minimum",r.value,r.message,e);break;case"max":Y(n,"maximum",r.value,r.message,e);break}return n};function yh(t,e){return{...G(t.innerType._def,e),default:t.defaultValue()}}function vh(t,e){return e.effectStrategy==="input"?G(t.schema._def,e):ke(e)}function bh(t){return{type:"string",enum:Array.from(t.values)}}const wh=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function kh(t,e){const n=[G(t.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),G(t.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(i=>!!i);let r=e.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0;const s=[];return n.forEach(i=>{if(wh(i))s.push(...i.allOf),i.unevaluatedProperties===void 0&&(r=void 0);else{let o=i;if("additionalProperties"in i&&i.additionalProperties===!1){const{additionalProperties:a,...c}=i;o=c}else r=void 0;s.push(o)}}),s.length?{allOf:s,...r}:void 0}function Sh(t,e){const n=typeof t.value;return n!=="bigint"&&n!=="number"&&n!=="boolean"&&n!=="string"?{type:Array.isArray(t.value)?"array":"object"}:e.target==="openApi3"?{type:n==="bigint"?"integer":n,enum:[t.value]}:{type:n==="bigint"?"integer":n,const:t.value}}let Tn;const Ie={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(Tn===void 0&&(Tn=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Tn),uuid:/^[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}$/,ipv4:/^(?:(?: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])$/,ipv4Cidr:/^(?:(?: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])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([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])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function eo(t,e){const n={type:"string"};if(t.checks)for(const r of t.checks)switch(r.kind){case"min":Y(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e);break;case"max":Y(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"email":switch(e.emailStrategy){case"format:email":Ce(n,"email",r.message,e);break;case"format:idn-email":Ce(n,"idn-email",r.message,e);break;case"pattern:zod":ye(n,Ie.email,r.message,e);break}break;case"url":Ce(n,"uri",r.message,e);break;case"uuid":Ce(n,"uuid",r.message,e);break;case"regex":ye(n,r.regex,r.message,e);break;case"cuid":ye(n,Ie.cuid,r.message,e);break;case"cuid2":ye(n,Ie.cuid2,r.message,e);break;case"startsWith":ye(n,RegExp(`^${zn(r.value,e)}`),r.message,e);break;case"endsWith":ye(n,RegExp(`${zn(r.value,e)}$`),r.message,e);break;case"datetime":Ce(n,"date-time",r.message,e);break;case"date":Ce(n,"date",r.message,e);break;case"time":Ce(n,"time",r.message,e);break;case"duration":Ce(n,"duration",r.message,e);break;case"length":Y(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e),Y(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"includes":{ye(n,RegExp(zn(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&Ce(n,"ipv4",r.message,e),r.version!=="v4"&&Ce(n,"ipv6",r.message,e);break}case"base64url":ye(n,Ie.base64url,r.message,e);break;case"jwt":ye(n,Ie.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&ye(n,Ie.ipv4Cidr,r.message,e),r.version!=="v4"&&ye(n,Ie.ipv6Cidr,r.message,e);break}case"emoji":ye(n,Ie.emoji(),r.message,e);break;case"ulid":{ye(n,Ie.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{Ce(n,"binary",r.message,e);break}case"contentEncoding:base64":{Y(n,"contentEncoding","base64",r.message,e);break}case"pattern:zod":{ye(n,Ie.base64,r.message,e);break}}break}case"nanoid":ye(n,Ie.nanoid,r.message,e)}return n}function zn(t,e){return e.patternStrategy==="escape"?zh(t):t}const Th=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function zh(t){let e="";for(let n=0;n<t.length;n++)Th.has(t[n])||(e+="\\"),e+=t[n];return e}function Ce(t,e,n,r){var s;t.format||(s=t.anyOf)!=null&&s.some(i=>i.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&r.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.anyOf.push({format:e,...n&&r.errorMessages&&{errorMessage:{format:n}}})):Y(t,"format",e,n,r)}function ye(t,e,n,r){var s;t.pattern||(s=t.allOf)!=null&&s.some(i=>i.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&r.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.allOf.push({pattern:hs(e,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):Y(t,"pattern",hs(e,r),n,r)}function hs(t,e){var c;if(!e.applyRegexFlags||!t.flags)return t.source;const n={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},r=n.i?t.source.toLowerCase():t.source;let s="",i=!1,o=!1,a=!1;for(let u=0;u<r.length;u++){if(i){s+=r[u],i=!1;continue}if(n.i){if(o){if(r[u].match(/[a-z]/)){a?(s+=r[u],s+=`${r[u-2]}-${r[u]}`.toUpperCase(),a=!1):r[u+1]==="-"&&((c=r[u+2])!=null&&c.match(/[a-z]/))?(s+=r[u],a=!0):s+=`${r[u]}${r[u].toUpperCase()}`;continue}}else if(r[u].match(/[a-z]/)){s+=`[${r[u]}${r[u].toUpperCase()}]`;continue}}if(n.m){if(r[u]==="^"){s+=`(^|(?<=[\r
|
|
42
42
|
]))`;continue}else if(r[u]==="$"){s+=`($|(?=[\r
|
|
43
43
|
]))`;continue}}if(n.s&&r[u]==="."){s+=o?`${r[u]}\r
|
|
44
44
|
`:`[${r[u]}\r
|
|
45
|
-
]`;continue}s+=r[u],r[u]==="\\"?i=!0:o&&r[u]==="]"?o=!1:!o&&r[u]==="["&&(o=!0)}try{new RegExp(s)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return s}function eo(t,e){var r,s,i,o,a,c;if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&((r=t.keyType)==null?void 0:r._def.typeName)===k.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((u,l)=>({...u,[l]:W(t.valueType._def,{...e,currentPath:[...e.currentPath,"properties",l]})??ke(e)}),{}),additionalProperties:e.rejectedAdditionalProperties};const n={type:"object",additionalProperties:W(t.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return n;if(((s=t.keyType)==null?void 0:s._def.typeName)===k.ZodString&&((i=t.keyType._def.checks)!=null&&i.length)){const{type:u,...l}=Xi(t.keyType._def,e);return{...n,propertyNames:l}}else{if(((o=t.keyType)==null?void 0:o._def.typeName)===k.ZodEnum)return{...n,propertyNames:{enum:t.keyType._def.values}};if(((a=t.keyType)==null?void 0:a._def.typeName)===k.ZodBranded&&t.keyType._def.type._def.typeName===k.ZodString&&((c=t.keyType._def.type._def.checks)!=null&&c.length)){const{type:u,...l}=Yi(t.keyType._def,e);return{...n,propertyNames:l}}}return n}function zh(t,e){if(e.mapStrategy==="record")return eo(t,e);const n=W(t.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||ke(e),r=W(t.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||ke(e);return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function $h(t){const e=t.values,r=Object.keys(t.values).filter(i=>typeof e[e[i]]!="number").map(i=>e[i]),s=Array.from(new Set(r.map(i=>typeof i)));return{type:s.length===1?s[0]==="string"?"string":"number":["string","number"],enum:r}}function Ph(t){return t.target==="openAi"?void 0:{not:ke({...t,currentPath:[...t.currentPath,"not"]})}}function Rh(t){return t.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}const sn={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Nh(t,e){if(e.target==="openApi3")return hs(t,e);const n=t.options instanceof Map?Array.from(t.options.values()):t.options;if(n.every(r=>r._def.typeName in sn&&(!r._def.checks||!r._def.checks.length))){const r=n.reduce((s,i)=>{const o=sn[i._def.typeName];return o&&!s.includes(o)?[...s,o]:s},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){const r=n.reduce((s,i)=>{const o=typeof i._def.value;switch(o){case"string":case"number":case"boolean":return[...s,o];case"bigint":return[...s,"integer"];case"object":if(i._def.value===null)return[...s,"null"];case"symbol":case"undefined":case"function":default:return s}},[]);if(r.length===n.length){const s=r.filter((i,o,a)=>a.indexOf(i)===o);return{type:s.length>1?s:s[0],enum:n.reduce((i,o)=>i.includes(o._def.value)?i:[...i,o._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,s)=>[...r,...s._def.values.filter(i=>!r.includes(i))],[])};return hs(t,e)}const hs=(t,e)=>{const n=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((r,s)=>W(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${s}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function Eh(t,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return e.target==="openApi3"?{type:sn[t.innerType._def.typeName],nullable:!0}:{type:[sn[t.innerType._def.typeName],"null"]};if(e.target==="openApi3"){const r=W(t.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const n=W(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function Ch(t,e){const n={type:"number"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"int":n.type="integer",Gi(n,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?K(n,"minimum",r.value,r.message,e):K(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),K(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?K(n,"maximum",r.value,r.message,e):K(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),K(n,"maximum",r.value,r.message,e));break;case"multipleOf":K(n,"multipleOf",r.value,r.message,e);break}return n}function Ih(t,e){const n=e.target==="openAi",r={type:"object",properties:{}},s=[],i=t.shape();for(const a in i){let c=i[a];if(c===void 0||c._def===void 0)continue;let u=xh(c);u&&n&&(c._def.typeName==="ZodOptional"&&(c=c._def.innerType),c.isNullable()||(c=c.nullable()),u=!1);const l=W(c._def,{...e,currentPath:[...e.currentPath,"properties",a],propertyPath:[...e.currentPath,"properties",a]});l!==void 0&&(r.properties[a]=l,u||s.push(a))}s.length&&(r.required=s);const o=Oh(t,e);return o!==void 0&&(r.additionalProperties=o),r}function Oh(t,e){if(t.catchall._def.typeName!=="ZodNever")return W(t.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function xh(t){try{return t.isOptional()}catch{return!0}}const Zh=(t,e)=>{var r;if(e.currentPath.toString()===((r=e.propertyPath)==null?void 0:r.toString()))return W(t.innerType._def,e);const n=W(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return n?{anyOf:[{not:ke(e)},n]}:ke(e)},Ah=(t,e)=>{if(e.pipeStrategy==="input")return W(t.in._def,e);if(e.pipeStrategy==="output")return W(t.out._def,e);const n=W(t.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=W(t.out._def,{...e,currentPath:[...e.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(s=>s!==void 0)}};function jh(t,e){return W(t.type._def,e)}function Mh(t,e){const r={type:"array",uniqueItems:!0,items:W(t.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return t.minSize&&K(r,"minItems",t.minSize.value,t.minSize.message,e),t.maxSize&&K(r,"maxItems",t.maxSize.value,t.maxSize.message,e),r}function Lh(t,e){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((n,r)=>W(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:W(t.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((n,r)=>W(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function Dh(t){return{not:ke(t)}}function qh(t){return ke(t)}const Fh=(t,e)=>W(t.innerType._def,e),Uh=(t,e,n)=>{switch(e){case k.ZodString:return Xi(t,n);case k.ZodNumber:return Ch(t,n);case k.ZodObject:return Ih(t,n);case k.ZodBigInt:return hh(t,n);case k.ZodBoolean:return mh();case k.ZodDate:return Qi(t,n);case k.ZodUndefined:return Dh(n);case k.ZodNull:return Rh(n);case k.ZodArray:return fh(t,n);case k.ZodUnion:case k.ZodDiscriminatedUnion:return Nh(t,n);case k.ZodIntersection:return wh(t,n);case k.ZodTuple:return Lh(t,n);case k.ZodRecord:return eo(t,n);case k.ZodLiteral:return kh(t,n);case k.ZodEnum:return vh(t);case k.ZodNativeEnum:return $h(t);case k.ZodNullable:return Eh(t,n);case k.ZodOptional:return Zh(t,n);case k.ZodMap:return zh(t,n);case k.ZodSet:return Mh(t,n);case k.ZodLazy:return()=>t.getter()._def;case k.ZodPromise:return jh(t,n);case k.ZodNaN:case k.ZodNever:return Ph(n);case k.ZodEffects:return yh(t,n);case k.ZodAny:return ke(n);case k.ZodUnknown:return qh(n);case k.ZodDefault:return _h(t,n);case k.ZodBranded:return Yi(t,n);case k.ZodReadonly:return Fh(t,n);case k.ZodCatch:return ph(t,n);case k.ZodPipeline:return Ah(t,n);case k.ZodFunction:case k.ZodVoid:case k.ZodSymbol:return;default:return(r=>{})()}};function W(t,e,n=!1){var a;const r=e.seen.get(t);if(e.override){const c=(a=e.override)==null?void 0:a.call(e,t,e,r,n);if(c!==uh)return c}if(r&&!n){const c=Vh(r,e);if(c!==void 0)return c}const s={def:t,path:e.currentPath,jsonSchema:void 0};e.seen.set(t,s);const i=Uh(t,t.typeName,e),o=typeof i=="function"?W(i(),e):i;if(o&&Hh(t,e,o),e.postProcess){const c=e.postProcess(o,t,e);return s.jsonSchema=o,c}return s.jsonSchema=o,o}const Vh=(t,e)=>{switch(e.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:Ki(e.currentPath,t.path)};case"none":case"seen":return t.path.length<e.currentPath.length&&t.path.every((n,r)=>e.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),ke(e)):e.$refStrategy==="seen"?ke(e):void 0}},Hh=(t,e,n)=>(t.description&&(n.description=t.description,e.markdownDescription&&(n.markdownDescription=t.description)),n),Jh=(t,e)=>{const n=dh(e);let r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((c,[u,l])=>({...c,[u]:W(l._def,{...n,currentPath:[...n.basePath,n.definitionPath,u]},!0)??ke(n)}),{}):void 0;const s=typeof e=="string"?e:(e==null?void 0:e.nameStrategy)==="title"||e==null?void 0:e.name,i=W(t._def,s===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??ke(n),o=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;o!==void 0&&(i.title=o),n.flags.hasReferencedOpenAiAnyType&&(r||(r={}),r[n.openAiAnyTypeName]||(r[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:n.$refStrategy==="relative"?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));const a=s===void 0?r?{...i,[n.definitionPath]:r}:i:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...r,[s]:i}};return n.target==="jsonSchema7"?a.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(a.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in a||"oneOf"in a||"allOf"in a||"type"in a&&Array.isArray(a.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),a};function Bh(t){return!t||t==="jsonSchema7"||t==="draft-7"?"draft-7":t==="jsonSchema2019-09"||t==="draft-2020-12"?"draft-2020-12":"draft-7"}function ms(t,e){return Ze(t)?Eu(t,{target:Bh(e==null?void 0:e.target),io:(e==null?void 0:e.pipeStrategy)??"input"}):Jh(t,{strictUnions:(e==null?void 0:e.strictUnions)??!0,pipeStrategy:(e==null?void 0:e.pipeStrategy)??"input"})}function ps(t){const e=Ot(t),n=e==null?void 0:e.method;if(!n)throw new Error("Schema is missing a method literal");const r=Wi(n);if(typeof r!="string")throw new Error("Schema method literal must be a string");return r}function gs(t,e){const n=wt(t,e);if(!n.success)throw n.error;return n.data}const Wh=6e4;class Gh{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this._pendingDebouncedNotifications=new Set,this._taskProgressTokens=new Map,this._requestResolvers=new Map,this.setNotificationHandler(ar,n=>{this._oncancel(n)}),this.setNotificationHandler(ur,n=>{this._onprogress(n)}),this.setRequestHandler(cr,n=>({})),this._taskStore=e==null?void 0:e.taskStore,this._taskMessageQueue=e==null?void 0:e.taskMessageQueue,this._taskStore&&(this.setRequestHandler(lr,async(n,r)=>{const s=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!s)throw new C(x.InvalidParams,"Failed to retrieve task: Task not found");return{...s}}),this.setRequestHandler(fr,async(n,r)=>{const s=async()=>{var a;const i=n.params.taskId;if(this._taskMessageQueue){let c;for(;c=await this._taskMessageQueue.dequeue(i,r.sessionId);){if(c.type==="response"||c.type==="error"){const u=c.message,l=u.id,d=this._requestResolvers.get(l);if(d)if(this._requestResolvers.delete(l),c.type==="response")d(u);else{const p=u,m=new C(p.error.code,p.error.message,p.error.data);d(m)}else{const p=c.type==="response"?"Response":"Error";this._onerror(new Error(`${p} handler missing for request ${l}`))}continue}await((a=this._transport)==null?void 0:a.send(c.message,{relatedRequestId:r.requestId}))}}const o=await this._taskStore.getTask(i,r.sessionId);if(!o)throw new C(x.InvalidParams,`Task not found: ${i}`);if(!Ke(o.status))return await this._waitForTaskUpdate(i,r.signal),await s();if(Ke(o.status)){const c=await this._taskStore.getTaskResult(i,r.sessionId);return this._clearTaskQueue(i),{...c,_meta:{...c._meta,[Ye]:{taskId:i}}}}return await s()};return await s()}),this.setRequestHandler(hr,async(n,r)=>{var s;try{const{tasks:i,nextCursor:o}=await this._taskStore.listTasks((s=n.params)==null?void 0:s.cursor,r.sessionId);return{tasks:i,nextCursor:o,_meta:{}}}catch(i){throw new C(x.InvalidParams,`Failed to list tasks: ${i instanceof Error?i.message:String(i)}`)}}),this.setRequestHandler(pr,async(n,r)=>{try{const s=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!s)throw new C(x.InvalidParams,`Task not found: ${n.params.taskId}`);if(Ke(s.status))throw new C(x.InvalidParams,`Cannot cancel task in terminal status: ${s.status}`);await this._taskStore.updateTaskStatus(n.params.taskId,"cancelled","Client cancelled task execution.",r.sessionId),this._clearTaskQueue(n.params.taskId);const i=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!i)throw new C(x.InvalidParams,`Task not found after cancellation: ${n.params.taskId}`);return{_meta:{},...i}}catch(s){throw s instanceof C?s:new C(x.InvalidRequest,`Failed to cancel task: ${s instanceof Error?s.message:String(s)}`)}}))}async _oncancel(e){if(!e.params.requestId)return;const n=this._requestHandlerAbortControllers.get(e.params.requestId);n==null||n.abort(e.params.reason)}_setupTimeout(e,n,r,s,i=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(s,n),startTime:Date.now(),timeout:n,maxTotalTimeout:r,resetTimeoutOnProgress:i,onTimeout:s})}_resetTimeout(e){const n=this._timeoutInfo.get(e);if(!n)return!1;const r=Date.now()-n.startTime;if(n.maxTotalTimeout&&r>=n.maxTotalTimeout)throw this._timeoutInfo.delete(e),C.fromError(x.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:n.maxTotalTimeout,totalElapsed:r});return clearTimeout(n.timeoutId),n.timeoutId=setTimeout(n.onTimeout,n.timeout),!0}_cleanupTimeout(e){const n=this._timeoutInfo.get(e);n&&(clearTimeout(n.timeoutId),this._timeoutInfo.delete(e))}async connect(e){var i,o,a;if(this._transport)throw new Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");this._transport=e;const n=(i=this.transport)==null?void 0:i.onclose;this._transport.onclose=()=>{n==null||n(),this._onclose()};const r=(o=this.transport)==null?void 0:o.onerror;this._transport.onerror=c=>{r==null||r(c),this._onerror(c)};const s=(a=this._transport)==null?void 0:a.onmessage;this._transport.onmessage=(c,u)=>{s==null||s(c,u),Lt(c)||Wl(c)?this._onresponse(c):Br(c)?this._onrequest(c,u):Bl(c)?this._onnotification(c):this._onerror(new Error(`Unknown message type: ${JSON.stringify(c)}`))},await this._transport.start()}_onclose(){var r;const e=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._taskProgressTokens.clear(),this._pendingDebouncedNotifications.clear();for(const s of this._requestHandlerAbortControllers.values())s.abort();this._requestHandlerAbortControllers.clear();const n=C.fromError(x.ConnectionClosed,"Connection closed");this._transport=void 0,(r=this.onclose)==null||r.call(this);for(const s of e.values())s(n)}_onerror(e){var n;(n=this.onerror)==null||n.call(this,e)}_onnotification(e){const n=this._notificationHandlers.get(e.method)??this.fallbackNotificationHandler;n!==void 0&&Promise.resolve().then(()=>n(e)).catch(r=>this._onerror(new Error(`Uncaught error in notification handler: ${r}`)))}_onrequest(e,n){var l,d,p,m;const r=this._requestHandlers.get(e.method)??this.fallbackRequestHandler,s=this._transport,i=(p=(d=(l=e.params)==null?void 0:l._meta)==null?void 0:d[Ye])==null?void 0:p.taskId;if(r===void 0){const S={jsonrpc:"2.0",id:e.id,error:{code:x.MethodNotFound,message:"Method not found"}};i&&this._taskMessageQueue?this._enqueueTaskMessage(i,{type:"error",message:S,timestamp:Date.now()},s==null?void 0:s.sessionId).catch(T=>this._onerror(new Error(`Failed to enqueue error response: ${T}`))):s==null||s.send(S).catch(T=>this._onerror(new Error(`Failed to send an error response: ${T}`)));return}const o=new AbortController;this._requestHandlerAbortControllers.set(e.id,o);const a=Jl(e.params)?e.params.task:void 0,c=this._taskStore?this.requestTaskStore(e,s==null?void 0:s.sessionId):void 0,u={signal:o.signal,sessionId:s==null?void 0:s.sessionId,_meta:(m=e.params)==null?void 0:m._meta,sendNotification:async S=>{if(o.signal.aborted)return;const T={relatedRequestId:e.id};i&&(T.relatedTask={taskId:i}),await this.notification(S,T)},sendRequest:async(S,T,j)=>{var Z;if(o.signal.aborted)throw new C(x.ConnectionClosed,"Request was cancelled");const y={...j,relatedRequestId:e.id};i&&!y.relatedTask&&(y.relatedTask={taskId:i});const v=((Z=y.relatedTask)==null?void 0:Z.taskId)??i;return v&&c&&await c.updateTaskStatus(v,"input_required"),await this.request(S,T,y)},authInfo:n==null?void 0:n.authInfo,requestId:e.id,requestInfo:n==null?void 0:n.requestInfo,taskId:i,taskStore:c,taskRequestedTtl:a==null?void 0:a.ttl,closeSSEStream:n==null?void 0:n.closeSSEStream,closeStandaloneSSEStream:n==null?void 0:n.closeStandaloneSSEStream};Promise.resolve().then(()=>{a&&this.assertTaskHandlerCapability(e.method)}).then(()=>r(e,u)).then(async S=>{if(o.signal.aborted)return;const T={result:S,jsonrpc:"2.0",id:e.id};i&&this._taskMessageQueue?await this._enqueueTaskMessage(i,{type:"response",message:T,timestamp:Date.now()},s==null?void 0:s.sessionId):await(s==null?void 0:s.send(T))},async S=>{if(o.signal.aborted)return;const T={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(S.code)?S.code:x.InternalError,message:S.message??"Internal error",...S.data!==void 0&&{data:S.data}}};i&&this._taskMessageQueue?await this._enqueueTaskMessage(i,{type:"error",message:T,timestamp:Date.now()},s==null?void 0:s.sessionId):await(s==null?void 0:s.send(T))}).catch(S=>this._onerror(new Error(`Failed to send response: ${S}`))).finally(()=>{this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){const{progressToken:n,...r}=e.params,s=Number(n),i=this._progressHandlers.get(s);if(!i){this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}const o=this._responseHandlers.get(s),a=this._timeoutInfo.get(s);if(a&&o&&a.resetTimeoutOnProgress)try{this._resetTimeout(s)}catch(c){this._responseHandlers.delete(s),this._progressHandlers.delete(s),this._cleanupTimeout(s),o(c);return}i(r)}_onresponse(e){const n=Number(e.id),r=this._requestResolvers.get(n);if(r){if(this._requestResolvers.delete(n),Lt(e))r(e);else{const o=new C(e.error.code,e.error.message,e.error.data);r(o)}return}const s=this._responseHandlers.get(n);if(s===void 0){this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}this._responseHandlers.delete(n),this._cleanupTimeout(n);let i=!1;if(Lt(e)&&e.result&&typeof e.result=="object"){const o=e.result;if(o.task&&typeof o.task=="object"){const a=o.task;typeof a.taskId=="string"&&(i=!0,this._taskProgressTokens.set(a.taskId,n))}}if(i||this._progressHandlers.delete(n),Lt(e))s(e);else{const o=C.fromError(e.error.code,e.error.message,e.error.data);s(o)}}get transport(){return this._transport}async close(){var e;await((e=this._transport)==null?void 0:e.close())}async*requestStream(e,n,r){var o,a;const{task:s}=r??{};if(!s){try{yield{type:"result",result:await this.request(e,n,r)}}catch(c){yield{type:"error",error:c instanceof C?c:new C(x.InternalError,String(c))}}return}let i;try{const c=await this.request(e,gn,r);if(c.task)i=c.task.taskId,yield{type:"taskCreated",task:c.task};else throw new C(x.InternalError,"Task creation did not return a task");for(;;){const u=await this.getTask({taskId:i},r);if(yield{type:"taskStatus",task:u},Ke(u.status)){u.status==="completed"?yield{type:"result",result:await this.getTaskResult({taskId:i},n,r)}:u.status==="failed"?yield{type:"error",error:new C(x.InternalError,`Task ${i} failed`)}:u.status==="cancelled"&&(yield{type:"error",error:new C(x.InternalError,`Task ${i} was cancelled`)});return}if(u.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:i},n,r)};return}const l=u.pollInterval??((o=this._options)==null?void 0:o.defaultTaskPollInterval)??1e3;await new Promise(d=>setTimeout(d,l)),(a=r==null?void 0:r.signal)==null||a.throwIfAborted()}}catch(c){yield{type:"error",error:c instanceof C?c:new C(x.InternalError,String(c))}}}request(e,n,r){const{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o,task:a,relatedTask:c}=r??{};return new Promise((u,l)=>{var v,Z,R,te,ue;const d=G=>{l(G)};if(!this._transport){d(new Error("Not connected"));return}if(((v=this._options)==null?void 0:v.enforceStrictCapabilities)===!0)try{this.assertCapabilityForMethod(e.method),a&&this.assertTaskCapability(e.method)}catch(G){d(G);return}(Z=r==null?void 0:r.signal)==null||Z.throwIfAborted();const p=this._requestMessageId++,m={...e,jsonrpc:"2.0",id:p};r!=null&&r.onprogress&&(this._progressHandlers.set(p,r.onprogress),m.params={...e.params,_meta:{...((R=e.params)==null?void 0:R._meta)||{},progressToken:p}}),a&&(m.params={...m.params,task:a}),c&&(m.params={...m.params,_meta:{...((te=m.params)==null?void 0:te._meta)||{},[Ye]:c}});const S=G=>{var fe;this._responseHandlers.delete(p),this._progressHandlers.delete(p),this._cleanupTimeout(p),(fe=this._transport)==null||fe.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:p,reason:String(G)}},{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o}).catch(Je=>this._onerror(new Error(`Failed to send cancellation: ${Je}`)));const _e=G instanceof C?G:new C(x.RequestTimeout,String(G));l(_e)};this._responseHandlers.set(p,G=>{var _e;if(!((_e=r==null?void 0:r.signal)!=null&&_e.aborted)){if(G instanceof Error)return l(G);try{const fe=wt(n,G.result);fe.success?u(fe.data):l(fe.error)}catch(fe){l(fe)}}}),(ue=r==null?void 0:r.signal)==null||ue.addEventListener("abort",()=>{var G;S((G=r==null?void 0:r.signal)==null?void 0:G.reason)});const T=(r==null?void 0:r.timeout)??Wh,j=()=>S(C.fromError(x.RequestTimeout,"Request timed out",{timeout:T}));this._setupTimeout(p,T,r==null?void 0:r.maxTotalTimeout,j,(r==null?void 0:r.resetTimeoutOnProgress)??!1);const y=c==null?void 0:c.taskId;if(y){const G=_e=>{const fe=this._responseHandlers.get(p);fe?fe(_e):this._onerror(new Error(`Response handler missing for side-channeled request ${p}`))};this._requestResolvers.set(p,G),this._enqueueTaskMessage(y,{type:"request",message:m,timestamp:Date.now()}).catch(_e=>{this._cleanupTimeout(p),l(_e)})}else this._transport.send(m,{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o}).catch(G=>{this._cleanupTimeout(p),l(G)})})}async getTask(e,n){return this.request({method:"tasks/get",params:e},dr,n)}async getTaskResult(e,n,r){return this.request({method:"tasks/result",params:e},n,r)}async listTasks(e,n){return this.request({method:"tasks/list",params:e},mr,n)}async cancelTask(e,n){return this.request({method:"tasks/cancel",params:e},dd,n)}async notification(e,n){var a,c,u,l;if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);const r=(a=n==null?void 0:n.relatedTask)==null?void 0:a.taskId;if(r){const d={...e,jsonrpc:"2.0",params:{...e.params,_meta:{...((c=e.params)==null?void 0:c._meta)||{},[Ye]:n.relatedTask}}};await this._enqueueTaskMessage(r,{type:"notification",message:d,timestamp:Date.now()});return}if((((u=this._options)==null?void 0:u.debouncedNotificationMethods)??[]).includes(e.method)&&!e.params&&!(n!=null&&n.relatedRequestId)&&!(n!=null&&n.relatedTask)){if(this._pendingDebouncedNotifications.has(e.method))return;this._pendingDebouncedNotifications.add(e.method),Promise.resolve().then(()=>{var p,m;if(this._pendingDebouncedNotifications.delete(e.method),!this._transport)return;let d={...e,jsonrpc:"2.0"};n!=null&&n.relatedTask&&(d={...d,params:{...d.params,_meta:{...((p=d.params)==null?void 0:p._meta)||{},[Ye]:n.relatedTask}}}),(m=this._transport)==null||m.send(d,n).catch(S=>this._onerror(S))});return}let o={...e,jsonrpc:"2.0"};n!=null&&n.relatedTask&&(o={...o,params:{...o.params,_meta:{...((l=o.params)==null?void 0:l._meta)||{},[Ye]:n.relatedTask}}}),await this._transport.send(o,n)}setRequestHandler(e,n){const r=ps(e);this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,(s,i)=>{const o=gs(e,s);return Promise.resolve(n(o,i))})}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,n){const r=ps(e);this._notificationHandlers.set(r,s=>{const i=gs(e,s);return Promise.resolve(n(i))})}removeNotificationHandler(e){this._notificationHandlers.delete(e)}_cleanupTaskProgressHandler(e){const n=this._taskProgressTokens.get(e);n!==void 0&&(this._progressHandlers.delete(n),this._taskProgressTokens.delete(e))}async _enqueueTaskMessage(e,n,r){var i;if(!this._taskStore||!this._taskMessageQueue)throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");const s=(i=this._options)==null?void 0:i.maxTaskQueueSize;await this._taskMessageQueue.enqueue(e,n,r,s)}async _clearTaskQueue(e,n){if(this._taskMessageQueue){const r=await this._taskMessageQueue.dequeueAll(e,n);for(const s of r)if(s.type==="request"&&Br(s.message)){const i=s.message.id,o=this._requestResolvers.get(i);o?(o(new C(x.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(i)):this._onerror(new Error(`Resolver missing for request ${i} during task ${e} cleanup`))}}}async _waitForTaskUpdate(e,n){var s,i;let r=((s=this._options)==null?void 0:s.defaultTaskPollInterval)??1e3;try{const o=await((i=this._taskStore)==null?void 0:i.getTask(e));o!=null&&o.pollInterval&&(r=o.pollInterval)}catch{}return new Promise((o,a)=>{if(n.aborted){a(new C(x.InvalidRequest,"Request cancelled"));return}const c=setTimeout(o,r);n.addEventListener("abort",()=>{clearTimeout(c),a(new C(x.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(e,n){const r=this._taskStore;if(!r)throw new Error("No task store configured");return{createTask:async s=>{if(!e)throw new Error("No request provided");return await r.createTask(s,e.id,{method:e.method,params:e.params},n)},getTask:async s=>{const i=await r.getTask(s,n);if(!i)throw new C(x.InvalidParams,"Failed to retrieve task: Task not found");return i},storeTaskResult:async(s,i,o)=>{await r.storeTaskResult(s,i,o,n);const a=await r.getTask(s,n);if(a){const c=Bt.parse({method:"notifications/tasks/status",params:a});await this.notification(c),Ke(a.status)&&this._cleanupTaskProgressHandler(s)}},getTaskResult:s=>r.getTaskResult(s,n),updateTaskStatus:async(s,i,o)=>{const a=await r.getTask(s,n);if(!a)throw new C(x.InvalidParams,`Task "${s}" not found - it may have been cleaned up`);if(Ke(a.status))throw new C(x.InvalidParams,`Cannot update task "${s}" from terminal status "${a.status}" to "${i}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await r.updateTaskStatus(s,i,o,n);const c=await r.getTask(s,n);if(c){const u=Bt.parse({method:"notifications/tasks/status",params:c});await this.notification(u),Ke(c.status)&&this._cleanupTaskProgressHandler(s)}},listTasks:s=>r.listTasks(s,n)}}}function _s(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Kh(t,e){const n={...t};for(const r in e){const s=r,i=e[s];if(i===void 0)continue;const o=n[s];_s(o)&&_s(i)?n[s]={...o,...i}:n[s]=i}return n}function Yh(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Vn={exports:{}},to={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.formatNames=t.fastFormats=t.fullFormats=void 0;function e(A,q){return{validate:A,compare:q}}t.fullFormats={date:e(i,o),time:e(c(!0),u),"date-time":e(p(!0),m),"iso-time":e(c(),l),"iso-date-time":e(p(),S),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:y,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:Je,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:Z,int32:{type:"number",validate:ue},int64:{type:"number",validate:G},float:{type:"number",validate:_e},double:{type:"number",validate:_e},password:!0,binary:!0},t.fastFormats={...t.fullFormats,date:e(/^\d\d\d\d-[0-1]\d-[0-3]\d$/,o),time:e(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,u),"date-time":e(/^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,m),"iso-time":e(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,l),"iso-date-time":e(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,S),uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i},t.formatNames=Object.keys(t.fullFormats);function n(A){return A%4===0&&(A%100!==0||A%400===0)}const r=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,s=[0,31,28,31,30,31,30,31,31,30,31,30,31];function i(A){const q=r.exec(A);if(!q)return!1;const ae=+q[1],F=+q[2],Te=+q[3];return F>=1&&F<=12&&Te>=1&&Te<=(F===2&&n(ae)?29:s[F])}function o(A,q){if(A&&q)return A>q?1:A<q?-1:0}const a=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;function c(A){return function(ae){const F=a.exec(ae);if(!F)return!1;const Te=+F[1],Be=+F[2],We=+F[3],_n=F[4],xt=F[5]==="-"?-1:1,Zt=+(F[6]||0),pt=+(F[7]||0);if(Zt>23||pt>59||A&&!_n)return!1;if(Te<=23&&Be<=59&&We<60)return!0;const Ge=Be-pt*xt,O=Te-Zt*xt-(Ge<0?1:0);return(O===23||O===-1)&&(Ge===59||Ge===-1)&&We<61}}function u(A,q){if(!(A&&q))return;const ae=new Date("2020-01-01T"+A).valueOf(),F=new Date("2020-01-01T"+q).valueOf();if(ae&&F)return ae-F}function l(A,q){if(!(A&&q))return;const ae=a.exec(A),F=a.exec(q);if(ae&&F)return A=ae[1]+ae[2]+ae[3],q=F[1]+F[2]+F[3],A>q?1:A<q?-1:0}const d=/t|\s/i;function p(A){const q=c(A);return function(F){const Te=F.split(d);return Te.length===2&&i(Te[0])&&q(Te[1])}}function m(A,q){if(!(A&&q))return;const ae=new Date(A).valueOf(),F=new Date(q).valueOf();if(ae&&F)return ae-F}function S(A,q){if(!(A&&q))return;const[ae,F]=A.split(d),[Te,Be]=q.split(d),We=o(ae,Te);if(We!==void 0)return We||u(F,Be)}const T=/\/|:/,j=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function y(A){return T.test(A)&&j.test(A)}const v=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;function Z(A){return v.lastIndex=0,v.test(A)}const R=-2147483648,te=2**31-1;function ue(A){return Number.isInteger(A)&&A<=te&&A>=R}function G(A){return Number.isInteger(A)}function _e(){return!0}const fe=/[^\\]\\Z/;function Je(A){if(fe.test(A))return!1;try{return new RegExp(A),!0}catch{return!1}}})(to);var no={},zr={},on={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.regexpCode=t.getEsmExportName=t.getProperty=t.safeStringify=t.stringify=t.strConcat=t.addCodeArg=t.str=t._=t.nil=t._Code=t.Name=t.IDENTIFIER=t._CodeOrName=void 0;class e{}t._CodeOrName=e,t.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class n extends e{constructor(v){if(super(),!t.IDENTIFIER.test(v))throw new Error("CodeGen: name must be a valid identifier");this.str=v}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}t.Name=n;class r extends e{constructor(v){super(),this._items=typeof v=="string"?[v]:v}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;const v=this._items[0];return v===""||v==='""'}get str(){var v;return(v=this._str)!==null&&v!==void 0?v:this._str=this._items.reduce((Z,R)=>`${Z}${R}`,"")}get names(){var v;return(v=this._names)!==null&&v!==void 0?v:this._names=this._items.reduce((Z,R)=>(R instanceof n&&(Z[R.str]=(Z[R.str]||0)+1),Z),{})}}t._Code=r,t.nil=new r("");function s(y,...v){const Z=[y[0]];let R=0;for(;R<v.length;)a(Z,v[R]),Z.push(y[++R]);return new r(Z)}t._=s;const i=new r("+");function o(y,...v){const Z=[m(y[0])];let R=0;for(;R<v.length;)Z.push(i),a(Z,v[R]),Z.push(i,m(y[++R]));return c(Z),new r(Z)}t.str=o;function a(y,v){v instanceof r?y.push(...v._items):v instanceof n?y.push(v):y.push(d(v))}t.addCodeArg=a;function c(y){let v=1;for(;v<y.length-1;){if(y[v]===i){const Z=u(y[v-1],y[v+1]);if(Z!==void 0){y.splice(v-1,3,Z);continue}y[v++]="+"}v++}}function u(y,v){if(v==='""')return y;if(y==='""')return v;if(typeof y=="string")return v instanceof n||y[y.length-1]!=='"'?void 0:typeof v!="string"?`${y.slice(0,-1)}${v}"`:v[0]==='"'?y.slice(0,-1)+v.slice(1):void 0;if(typeof v=="string"&&v[0]==='"'&&!(y instanceof n))return`"${y}${v.slice(1)}`}function l(y,v){return v.emptyStr()?y:y.emptyStr()?v:o`${y}${v}`}t.strConcat=l;function d(y){return typeof y=="number"||typeof y=="boolean"||y===null?y:m(Array.isArray(y)?y.join(","):y)}function p(y){return new r(m(y))}t.stringify=p;function m(y){return JSON.stringify(y).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}t.safeStringify=m;function S(y){return typeof y=="string"&&t.IDENTIFIER.test(y)?new r(`.${y}`):s`[${y}]`}t.getProperty=S;function T(y){if(typeof y=="string"&&t.IDENTIFIER.test(y))return new r(`${y}`);throw new Error(`CodeGen: invalid export name: ${y}, use explicit $id name mapping`)}t.getEsmExportName=T;function j(y){return new r(y.toString())}t.regexpCode=j})(on);var Hn={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ValueScope=t.ValueScopeName=t.Scope=t.varKinds=t.UsedValueState=void 0;const e=on;class n extends Error{constructor(u){super(`CodeGen: "code" for ${u} not defined`),this.value=u.value}}var r;(function(c){c[c.Started=0]="Started",c[c.Completed=1]="Completed"})(r||(t.UsedValueState=r={})),t.varKinds={const:new e.Name("const"),let:new e.Name("let"),var:new e.Name("var")};class s{constructor({prefixes:u,parent:l}={}){this._names={},this._prefixes=u,this._parent=l}toName(u){return u instanceof e.Name?u:this.name(u)}name(u){return new e.Name(this._newName(u))}_newName(u){const l=this._names[u]||this._nameGroup(u);return`${u}${l.index++}`}_nameGroup(u){var l,d;if(!((d=(l=this._parent)===null||l===void 0?void 0:l._prefixes)===null||d===void 0)&&d.has(u)||this._prefixes&&!this._prefixes.has(u))throw new Error(`CodeGen: prefix "${u}" is not allowed in this scope`);return this._names[u]={prefix:u,index:0}}}t.Scope=s;class i extends e.Name{constructor(u,l){super(l),this.prefix=u}setValue(u,{property:l,itemIndex:d}){this.value=u,this.scopePath=(0,e._)`.${new e.Name(l)}[${d}]`}}t.ValueScopeName=i;const o=(0,e._)`\n`;class a extends s{constructor(u){super(u),this._values={},this._scope=u.scope,this.opts={...u,_n:u.lines?o:e.nil}}get(){return this._scope}name(u){return new i(u,this._newName(u))}value(u,l){var d;if(l.ref===void 0)throw new Error("CodeGen: ref must be passed in value");const p=this.toName(u),{prefix:m}=p,S=(d=l.key)!==null&&d!==void 0?d:l.ref;let T=this._values[m];if(T){const v=T.get(S);if(v)return v}else T=this._values[m]=new Map;T.set(S,p);const j=this._scope[m]||(this._scope[m]=[]),y=j.length;return j[y]=l.ref,p.setValue(l,{property:m,itemIndex:y}),p}getValue(u,l){const d=this._values[u];if(d)return d.get(l)}scopeRefs(u,l=this._values){return this._reduceValues(l,d=>{if(d.scopePath===void 0)throw new Error(`CodeGen: name "${d}" has no value`);return(0,e._)`${u}${d.scopePath}`})}scopeCode(u=this._values,l,d){return this._reduceValues(u,p=>{if(p.value===void 0)throw new Error(`CodeGen: name "${p}" has no value`);return p.value.code},l,d)}_reduceValues(u,l,d={},p){let m=e.nil;for(const S in u){const T=u[S];if(!T)continue;const j=d[S]=d[S]||new Map;T.forEach(y=>{if(j.has(y))return;j.set(y,r.Started);let v=l(y);if(v){const Z=this.opts.es5?t.varKinds.var:t.varKinds.const;m=(0,e._)`${m}${Z} ${y} = ${v};${this.opts._n}`}else if(v=p==null?void 0:p(y))m=(0,e._)`${m}${v}${this.opts._n}`;else throw new n(y);j.set(y,r.Completed)})}return m}}t.ValueScope=a})(Hn);(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.or=t.and=t.not=t.CodeGen=t.operators=t.varKinds=t.ValueScopeName=t.ValueScope=t.Scope=t.Name=t.regexpCode=t.stringify=t.getProperty=t.nil=t.strConcat=t.str=t._=void 0;const e=on,n=Hn;var r=on;Object.defineProperty(t,"_",{enumerable:!0,get:function(){return r._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return r.str}}),Object.defineProperty(t,"strConcat",{enumerable:!0,get:function(){return r.strConcat}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return r.nil}}),Object.defineProperty(t,"getProperty",{enumerable:!0,get:function(){return r.getProperty}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return r.stringify}}),Object.defineProperty(t,"regexpCode",{enumerable:!0,get:function(){return r.regexpCode}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return r.Name}});var s=Hn;Object.defineProperty(t,"Scope",{enumerable:!0,get:function(){return s.Scope}}),Object.defineProperty(t,"ValueScope",{enumerable:!0,get:function(){return s.ValueScope}}),Object.defineProperty(t,"ValueScopeName",{enumerable:!0,get:function(){return s.ValueScopeName}}),Object.defineProperty(t,"varKinds",{enumerable:!0,get:function(){return s.varKinds}}),t.operators={GT:new e._Code(">"),GTE:new e._Code(">="),LT:new e._Code("<"),LTE:new e._Code("<="),EQ:new e._Code("==="),NEQ:new e._Code("!=="),NOT:new e._Code("!"),OR:new e._Code("||"),AND:new e._Code("&&"),ADD:new e._Code("+")};class i{optimizeNodes(){return this}optimizeNames(f,h){return this}}class o extends i{constructor(f,h,b){super(),this.varKind=f,this.name=h,this.rhs=b}render({es5:f,_n:h}){const b=f?n.varKinds.var:this.varKind,D=this.rhs===void 0?"":` = ${this.rhs}`;return`${b} ${this.name}${D};`+h}optimizeNames(f,h){if(f[this.name.str])return this.rhs&&(this.rhs=F(this.rhs,f,h)),this}get names(){return this.rhs instanceof e._CodeOrName?this.rhs.names:{}}}class a extends i{constructor(f,h,b){super(),this.lhs=f,this.rhs=h,this.sideEffects=b}render({_n:f}){return`${this.lhs} = ${this.rhs};`+f}optimizeNames(f,h){if(!(this.lhs instanceof e.Name&&!f[this.lhs.str]&&!this.sideEffects))return this.rhs=F(this.rhs,f,h),this}get names(){const f=this.lhs instanceof e.Name?{}:{...this.lhs.names};return ae(f,this.rhs)}}class c extends a{constructor(f,h,b,D){super(f,b,D),this.op=h}render({_n:f}){return`${this.lhs} ${this.op}= ${this.rhs};`+f}}class u extends i{constructor(f){super(),this.label=f,this.names={}}render({_n:f}){return`${this.label}:`+f}}class l extends i{constructor(f){super(),this.label=f,this.names={}}render({_n:f}){return`break${this.label?` ${this.label}`:""};`+f}}class d extends i{constructor(f){super(),this.error=f}render({_n:f}){return`throw ${this.error};`+f}get names(){return this.error.names}}class p extends i{constructor(f){super(),this.code=f}render({_n:f}){return`${this.code};`+f}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(f,h){return this.code=F(this.code,f,h),this}get names(){return this.code instanceof e._CodeOrName?this.code.names:{}}}class m extends i{constructor(f=[]){super(),this.nodes=f}render(f){return this.nodes.reduce((h,b)=>h+b.render(f),"")}optimizeNodes(){const{nodes:f}=this;let h=f.length;for(;h--;){const b=f[h].optimizeNodes();Array.isArray(b)?f.splice(h,1,...b):b?f[h]=b:f.splice(h,1)}return f.length>0?this:void 0}optimizeNames(f,h){const{nodes:b}=this;let D=b.length;for(;D--;){const H=b[D];H.optimizeNames(f,h)||(Te(f,H.names),b.splice(D,1))}return b.length>0?this:void 0}get names(){return this.nodes.reduce((f,h)=>q(f,h.names),{})}}class S extends m{render(f){return"{"+f._n+super.render(f)+"}"+f._n}}class T extends m{}class j extends S{}j.kind="else";class y extends S{constructor(f,h){super(h),this.condition=f}render(f){let h=`if(${this.condition})`+super.render(f);return this.else&&(h+="else "+this.else.render(f)),h}optimizeNodes(){super.optimizeNodes();const f=this.condition;if(f===!0)return this.nodes;let h=this.else;if(h){const b=h.optimizeNodes();h=this.else=Array.isArray(b)?new j(b):b}if(h)return f===!1?h instanceof y?h:h.nodes:this.nodes.length?this:new y(Be(f),h instanceof y?[h]:h.nodes);if(!(f===!1||!this.nodes.length))return this}optimizeNames(f,h){var b;if(this.else=(b=this.else)===null||b===void 0?void 0:b.optimizeNames(f,h),!!(super.optimizeNames(f,h)||this.else))return this.condition=F(this.condition,f,h),this}get names(){const f=super.names;return ae(f,this.condition),this.else&&q(f,this.else.names),f}}y.kind="if";class v extends S{}v.kind="for";class Z extends v{constructor(f){super(),this.iteration=f}render(f){return`for(${this.iteration})`+super.render(f)}optimizeNames(f,h){if(super.optimizeNames(f,h))return this.iteration=F(this.iteration,f,h),this}get names(){return q(super.names,this.iteration.names)}}class R extends v{constructor(f,h,b,D){super(),this.varKind=f,this.name=h,this.from=b,this.to=D}render(f){const h=f.es5?n.varKinds.var:this.varKind,{name:b,from:D,to:H}=this;return`for(${h} ${b}=${D}; ${b}<${H}; ${b}++)`+super.render(f)}get names(){const f=ae(super.names,this.from);return ae(f,this.to)}}class te extends v{constructor(f,h,b,D){super(),this.loop=f,this.varKind=h,this.name=b,this.iterable=D}render(f){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(f)}optimizeNames(f,h){if(super.optimizeNames(f,h))return this.iterable=F(this.iterable,f,h),this}get names(){return q(super.names,this.iterable.names)}}class ue extends S{constructor(f,h,b){super(),this.name=f,this.args=h,this.async=b}render(f){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(f)}}ue.kind="func";class G extends m{render(f){return"return "+super.render(f)}}G.kind="return";class _e extends S{render(f){let h="try"+super.render(f);return this.catch&&(h+=this.catch.render(f)),this.finally&&(h+=this.finally.render(f)),h}optimizeNodes(){var f,h;return super.optimizeNodes(),(f=this.catch)===null||f===void 0||f.optimizeNodes(),(h=this.finally)===null||h===void 0||h.optimizeNodes(),this}optimizeNames(f,h){var b,D;return super.optimizeNames(f,h),(b=this.catch)===null||b===void 0||b.optimizeNames(f,h),(D=this.finally)===null||D===void 0||D.optimizeNames(f,h),this}get names(){const f=super.names;return this.catch&&q(f,this.catch.names),this.finally&&q(f,this.finally.names),f}}class fe extends S{constructor(f){super(),this.error=f}render(f){return`catch(${this.error})`+super.render(f)}}fe.kind="catch";class Je extends S{render(f){return"finally"+super.render(f)}}Je.kind="finally";class A{constructor(f,h={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...h,_n:h.lines?`
|
|
46
|
-
`:""},this._extScope=f,this._scope=new n.Scope({parent:f}),this._nodes=[new T]}toString(){return this._root.render(this.opts)}name(f){return this._scope.name(f)}scopeName(f){return this._extScope.name(f)}scopeValue(f,h){const b=this._extScope.value(f,h);return(this._values[b.prefix]||(this._values[b.prefix]=new Set)).add(b),b}getScopeValue(f,h){return this._extScope.getValue(f,h)}scopeRefs(f){return this._extScope.scopeRefs(f,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(f,h,b,D){const H=this._scope.toName(h);return b!==void 0&&D&&(this._constants[H.str]=b),this._leafNode(new o(f,H,b)),H}const(f,h,b){return this._def(n.varKinds.const,f,h,b)}let(f,h,b){return this._def(n.varKinds.let,f,h,b)}var(f,h,b){return this._def(n.varKinds.var,f,h,b)}assign(f,h,b){return this._leafNode(new a(f,h,b))}add(f,h){return this._leafNode(new c(f,t.operators.ADD,h))}code(f){return typeof f=="function"?f():f!==e.nil&&this._leafNode(new p(f)),this}object(...f){const h=["{"];for(const[b,D]of f)h.length>1&&h.push(","),h.push(b),(b!==D||this.opts.es5)&&(h.push(":"),(0,e.addCodeArg)(h,D));return h.push("}"),new e._Code(h)}if(f,h,b){if(this._blockNode(new y(f)),h&&b)this.code(h).else().code(b).endIf();else if(h)this.code(h).endIf();else if(b)throw new Error('CodeGen: "else" body without "then" body');return this}elseIf(f){return this._elseNode(new y(f))}else(){return this._elseNode(new j)}endIf(){return this._endBlockNode(y,j)}_for(f,h){return this._blockNode(f),h&&this.code(h).endFor(),this}for(f,h){return this._for(new Z(f),h)}forRange(f,h,b,D,H=this.opts.es5?n.varKinds.var:n.varKinds.let){const de=this._scope.toName(f);return this._for(new R(H,de,h,b),()=>D(de))}forOf(f,h,b,D=n.varKinds.const){const H=this._scope.toName(f);if(this.opts.es5){const de=h instanceof e.Name?h:this.var("_arr",h);return this.forRange("_i",0,(0,e._)`${de}.length`,io=>{this.var(H,(0,e._)`${de}[${io}]`),b(H)})}return this._for(new te("of",D,H,h),()=>b(H))}forIn(f,h,b,D=this.opts.es5?n.varKinds.var:n.varKinds.const){if(this.opts.ownProperties)return this.forOf(f,(0,e._)`Object.keys(${h})`,b);const H=this._scope.toName(f);return this._for(new te("in",D,H,h),()=>b(H))}endFor(){return this._endBlockNode(v)}label(f){return this._leafNode(new u(f))}break(f){return this._leafNode(new l(f))}return(f){const h=new G;if(this._blockNode(h),this.code(f),h.nodes.length!==1)throw new Error('CodeGen: "return" should have one node');return this._endBlockNode(G)}try(f,h,b){if(!h&&!b)throw new Error('CodeGen: "try" without "catch" and "finally"');const D=new _e;if(this._blockNode(D),this.code(f),h){const H=this.name("e");this._currNode=D.catch=new fe(H),h(H)}return b&&(this._currNode=D.finally=new Je,this.code(b)),this._endBlockNode(fe,Je)}throw(f){return this._leafNode(new d(f))}block(f,h){return this._blockStarts.push(this._nodes.length),f&&this.code(f).endBlock(h),this}endBlock(f){const h=this._blockStarts.pop();if(h===void 0)throw new Error("CodeGen: not in self-balancing block");const b=this._nodes.length-h;if(b<0||f!==void 0&&b!==f)throw new Error(`CodeGen: wrong number of nodes: ${b} vs ${f} expected`);return this._nodes.length=h,this}func(f,h=e.nil,b,D){return this._blockNode(new ue(f,h,b)),D&&this.code(D).endFunc(),this}endFunc(){return this._endBlockNode(ue)}optimize(f=1){for(;f-- >0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(f){return this._currNode.nodes.push(f),this}_blockNode(f){this._currNode.nodes.push(f),this._nodes.push(f)}_endBlockNode(f,h){const b=this._currNode;if(b instanceof f||h&&b instanceof h)return this._nodes.pop(),this;throw new Error(`CodeGen: not in block "${h?`${f.kind}/${h.kind}`:f.kind}"`)}_elseNode(f){const h=this._currNode;if(!(h instanceof y))throw new Error('CodeGen: "else" without "if"');return this._currNode=h.else=f,this}get _root(){return this._nodes[0]}get _currNode(){const f=this._nodes;return f[f.length-1]}set _currNode(f){const h=this._nodes;h[h.length-1]=f}}t.CodeGen=A;function q(O,f){for(const h in f)O[h]=(O[h]||0)+(f[h]||0);return O}function ae(O,f){return f instanceof e._CodeOrName?q(O,f.names):O}function F(O,f,h){if(O instanceof e.Name)return b(O);if(!D(O))return O;return new e._Code(O._items.reduce((H,de)=>(de instanceof e.Name&&(de=b(de)),de instanceof e._Code?H.push(...de._items):H.push(de),H),[]));function b(H){const de=h[H.str];return de===void 0||f[H.str]!==1?H:(delete f[H.str],de)}function D(H){return H instanceof e._Code&&H._items.some(de=>de instanceof e.Name&&f[de.str]===1&&h[de.str]!==void 0)}}function Te(O,f){for(const h in f)O[h]=(O[h]||0)-(f[h]||0)}function Be(O){return typeof O=="boolean"||typeof O=="number"||O===null?!O:(0,e._)`!${Ge(O)}`}t.not=Be;const We=pt(t.operators.AND);function _n(...O){return O.reduce(We)}t.and=_n;const xt=pt(t.operators.OR);function Zt(...O){return O.reduce(xt)}t.or=Zt;function pt(O){return(f,h)=>f===e.nil?h:h===e.nil?f:(0,e._)`${Ge(f)} ${O} ${Ge(h)}`}function Ge(O){return O instanceof e.Name?O:(0,e._)`(${O})`}})(zr);(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.formatLimitDefinition=void 0;const e=zs,n=zr,r=n.operators,s={formatMaximum:{okStr:"<=",ok:r.LTE,fail:r.GT},formatMinimum:{okStr:">=",ok:r.GTE,fail:r.LT},formatExclusiveMaximum:{okStr:"<",ok:r.LT,fail:r.GTE},formatExclusiveMinimum:{okStr:">",ok:r.GT,fail:r.LTE}},i={message:({keyword:a,schemaCode:c})=>(0,n.str)`should be ${s[a].okStr} ${c}`,params:({keyword:a,schemaCode:c})=>(0,n._)`{comparison: ${s[a].okStr}, limit: ${c}}`};t.formatLimitDefinition={keyword:Object.keys(s),type:"string",schemaType:"string",$data:!0,error:i,code(a){const{gen:c,data:u,schemaCode:l,keyword:d,it:p}=a,{opts:m,self:S}=p;if(!m.validateFormats)return;const T=new e.KeywordCxt(p,S.RULES.all.format.definition,"format");T.$data?j():y();function j(){const Z=c.scopeValue("formats",{ref:S.formats,code:m.code.formats}),R=c.const("fmt",(0,n._)`${Z}[${T.schemaCode}]`);a.fail$data((0,n.or)((0,n._)`typeof ${R} != "object"`,(0,n._)`${R} instanceof RegExp`,(0,n._)`typeof ${R}.compare != "function"`,v(R)))}function y(){const Z=T.schema,R=S.formats[Z];if(!R||R===!0)return;if(typeof R!="object"||R instanceof RegExp||typeof R.compare!="function")throw new Error(`"${d}": format "${Z}" does not define "compare" function`);const te=c.scopeValue("formats",{key:Z,ref:R,code:m.code.formats?(0,n._)`${m.code.formats}${(0,n.getProperty)(Z)}`:void 0});a.fail$data(v(te))}function v(Z){return(0,n._)`${Z}.compare(${u}, ${l}) ${s[d].fail} 0`}},dependencies:["format"]};const o=a=>(a.addKeyword(t.formatLimitDefinition),a);t.default=o})(no);(function(t,e){Object.defineProperty(e,"__esModule",{value:!0});const n=to,r=no,s=zr,i=new s.Name("fullFormats"),o=new s.Name("fastFormats"),a=(u,l={keywords:!0})=>{if(Array.isArray(l))return c(u,l,n.fullFormats,i),u;const[d,p]=l.mode==="fast"?[n.fastFormats,o]:[n.fullFormats,i],m=l.formats||n.formatNames;return c(u,m,d,p),l.keywords&&(0,r.default)(u),u};a.get=(u,l="full")=>{const p=(l==="fast"?n.fastFormats:n.fullFormats)[u];if(!p)throw new Error(`Unknown format "${u}"`);return p};function c(u,l,d,p){var m,S;(m=(S=u.opts.code).formats)!==null&&m!==void 0||(S.formats=(0,s._)`require("ajv-formats/dist/formats").${p}`);for(const T of l)u.addFormat(T,d[T])}t.exports=e=a,Object.defineProperty(e,"__esModule",{value:!0}),e.default=a})(Vn,Vn.exports);var Qh=Vn.exports;const Xh=Yh(Qh);function em(){const t=new zs({strict:!1,validateFormats:!0,validateSchema:!1,allErrors:!0});return Xh(t),t}class tm{constructor(e){this._ajv=e??em()}getValidator(e){const n="$id"in e&&typeof e.$id=="string"?this._ajv.getSchema(e.$id)??this._ajv.compile(e):this._ajv.compile(e);return r=>n(r)?{valid:!0,data:r,errorMessage:void 0}:{valid:!1,data:void 0,errorMessage:this._ajv.errorsText(n.errors)}}}class nm{constructor(e){this._server=e}requestStream(e,n,r){return this._server.requestStream(e,n,r)}createMessageStream(e,n){var s;const r=this._server.getClientCapabilities();if((e.tools||e.toolChoice)&&!((s=r==null?void 0:r.sampling)!=null&&s.tools))throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){const i=e.messages[e.messages.length-1],o=Array.isArray(i.content)?i.content:[i.content],a=o.some(d=>d.type==="tool_result"),c=e.messages.length>1?e.messages[e.messages.length-2]:void 0,u=c?Array.isArray(c.content)?c.content:[c.content]:[],l=u.some(d=>d.type==="tool_use");if(a){if(o.some(d=>d.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!l)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(l){const d=new Set(u.filter(m=>m.type==="tool_use").map(m=>m.id)),p=new Set(o.filter(m=>m.type==="tool_result").map(m=>m.toolUseId));if(d.size!==p.size||![...d].every(m=>p.has(m)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return this.requestStream({method:"sampling/createMessage",params:e},Sr,n)}elicitInputStream(e,n){var o,a;const r=this._server.getClientCapabilities(),s=e.mode??"form";switch(s){case"url":{if(!((o=r==null?void 0:r.elicitation)!=null&&o.url))throw new Error("Client does not support url elicitation.");break}case"form":{if(!((a=r==null?void 0:r.elicitation)!=null&&a.form))throw new Error("Client does not support form elicitation.");break}}const i=s==="form"&&e.mode===void 0?{...e,mode:"form"}:e;return this.requestStream({method:"elicitation/create",params:i},Yt,n)}async getTask(e,n){return this._server.getTask({taskId:e},n)}async getTaskResult(e,n,r){return this._server.getTaskResult({taskId:e},n,r)}async listTasks(e,n){return this._server.listTasks(e?{cursor:e}:void 0,n)}async cancelTask(e,n){return this._server.cancelTask({taskId:e},n)}}function rm(t,e,n){var r;if(!t)throw new Error(`${n} does not support task creation (required for ${e})`);switch(e){case"tools/call":if(!((r=t.tools)!=null&&r.call))throw new Error(`${n} does not support task creation for tools/call (required for ${e})`);break}}function sm(t,e,n){var r,s;if(!t)throw new Error(`${n} does not support task creation (required for ${e})`);switch(e){case"sampling/createMessage":if(!((r=t.sampling)!=null&&r.createMessage))throw new Error(`${n} does not support task creation for sampling/createMessage (required for ${e})`);break;case"elicitation/create":if(!((s=t.elicitation)!=null&&s.create))throw new Error(`${n} does not support task creation for elicitation/create (required for ${e})`);break}}class im extends Gh{constructor(e,n){super(n),this._serverInfo=e,this._loggingLevels=new Map,this.LOG_LEVEL_SEVERITY=new Map(Gt.options.map((r,s)=>[r,s])),this.isMessageIgnored=(r,s)=>{const i=this._loggingLevels.get(s);return i?this.LOG_LEVEL_SEVERITY.get(r)<this.LOG_LEVEL_SEVERITY.get(i):!1},this._capabilities=(n==null?void 0:n.capabilities)??{},this._instructions=n==null?void 0:n.instructions,this._jsonSchemaValidator=(n==null?void 0:n.jsonSchemaValidator)??new tm,this.setRequestHandler(Zi,r=>this._oninitialize(r)),this.setNotificationHandler(Ai,()=>{var r;return(r=this.oninitialized)==null?void 0:r.call(this)}),this._capabilities.logging&&this.setRequestHandler(Fi,async(r,s)=>{var c;const i=s.sessionId||((c=s.requestInfo)==null?void 0:c.headers["mcp-session-id"])||void 0,{level:o}=r.params,a=Gt.safeParse(o);return a.success&&this._loggingLevels.set(i,a.data),{}})}get experimental(){return this._experimental||(this._experimental={tasks:new nm(this)}),this._experimental}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=Kh(this._capabilities,e)}setRequestHandler(e,n){var a;const r=Ot(e),s=r==null?void 0:r.method;if(!s)throw new Error("Schema is missing a method literal");let i;if(Ze(s)){const c=s,u=(a=c._zod)==null?void 0:a.def;i=(u==null?void 0:u.value)??c.value}else{const c=s,u=c._def;i=(u==null?void 0:u.value)??c.value}if(typeof i!="string")throw new Error("Schema method literal must be a string");if(i==="tools/call"){const c=async(u,l)=>{const d=wt(Wt,u);if(!d.success){const T=d.error instanceof Error?d.error.message:String(d.error);throw new C(x.InvalidParams,`Invalid tools/call request: ${T}`)}const{params:p}=d.data,m=await Promise.resolve(n(u,l));if(p.task){const T=wt(gn,m);if(!T.success){const j=T.error instanceof Error?T.error.message:String(T.error);throw new C(x.InvalidParams,`Invalid task creation result: ${j}`)}return T.data}const S=wt(kr,m);if(!S.success){const T=S.error instanceof Error?S.error.message:String(S.error);throw new C(x.InvalidParams,`Invalid tools/call result: ${T}`)}return S.data};return super.setRequestHandler(e,c)}return super.setRequestHandler(e,n)}assertCapabilityForMethod(e){var n,r,s;switch(e){case"sampling/createMessage":if(!((n=this._clientCapabilities)!=null&&n.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"elicitation/create":if(!((r=this._clientCapabilities)!=null&&r.elicitation))throw new Error(`Client does not support elicitation (required for ${e})`);break;case"roots/list":if(!((s=this._clientCapabilities)!=null&&s.roots))throw new Error(`Client does not support listing roots (required for ${e})`);break}}assertNotificationCapability(e){var n,r;switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case"notifications/elicitation/complete":if(!((r=(n=this._clientCapabilities)==null?void 0:n.elicitation)!=null&&r.url))throw new Error(`Client does not support URL elicitation (required for ${e})`);break}}assertRequestHandlerCapability(e){if(this._capabilities)switch(e){case"completion/complete":if(!this._capabilities.completions)throw new Error(`Server does not support completions (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw new Error(`Server does not support tasks capability (required for ${e})`);break}}assertTaskCapability(e){var n,r;sm((r=(n=this._clientCapabilities)==null?void 0:n.tasks)==null?void 0:r.requests,e,"Client")}assertTaskHandlerCapability(e){var n;this._capabilities&&rm((n=this._capabilities.tasks)==null?void 0:n.requests,e,"Server")}async _oninitialize(e){const n=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Ul.includes(n)?n:Ni,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},or)}async createMessage(e,n){var r,s;if((e.tools||e.toolChoice)&&!((s=(r=this._clientCapabilities)==null?void 0:r.sampling)!=null&&s.tools))throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){const i=e.messages[e.messages.length-1],o=Array.isArray(i.content)?i.content:[i.content],a=o.some(d=>d.type==="tool_result"),c=e.messages.length>1?e.messages[e.messages.length-2]:void 0,u=c?Array.isArray(c.content)?c.content:[c.content]:[],l=u.some(d=>d.type==="tool_use");if(a){if(o.some(d=>d.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!l)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(l){const d=new Set(u.filter(m=>m.type==="tool_use").map(m=>m.id)),p=new Set(o.filter(m=>m.type==="tool_result").map(m=>m.toolUseId));if(d.size!==p.size||![...d].every(m=>p.has(m)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return e.tools?this.request({method:"sampling/createMessage",params:e},Ui,n):this.request({method:"sampling/createMessage",params:e},Sr,n)}async elicitInput(e,n){var s,i,o,a;switch(e.mode??"form"){case"url":{if(!((i=(s=this._clientCapabilities)==null?void 0:s.elicitation)!=null&&i.url))throw new Error("Client does not support url elicitation.");const c=e;return this.request({method:"elicitation/create",params:c},Yt,n)}case"form":{if(!((a=(o=this._clientCapabilities)==null?void 0:o.elicitation)!=null&&a.form))throw new Error("Client does not support form elicitation.");const c=e.mode==="form"?e:{...e,mode:"form"},u=await this.request({method:"elicitation/create",params:c},Yt,n);if(u.action==="accept"&&u.content&&c.requestedSchema)try{const d=this._jsonSchemaValidator.getValidator(c.requestedSchema)(u.content);if(!d.valid)throw new C(x.InvalidParams,`Elicitation response content does not match requested schema: ${d.errorMessage}`)}catch(l){throw l instanceof C?l:new C(x.InternalError,`Error validating elicitation response: ${l instanceof Error?l.message:String(l)}`)}return u}}}createElicitationCompletionNotifier(e,n){var r,s;if(!((s=(r=this._clientCapabilities)==null?void 0:r.elicitation)!=null&&s.url))throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");return()=>this.notification({method:"notifications/elicitation/complete",params:{elicitationId:e}},n)}async listRoots(e,n){return this.request({method:"roots/list",params:e},Vi,n)}async sendLoggingMessage(e,n){if(this._capabilities.logging&&!this.isMessageIgnored(e.level,n))return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}const ro=Symbol.for("mcp.completable");function ys(t){return!!t&&typeof t=="object"&&ro in t}function om(t){const e=t[ro];return e==null?void 0:e.complete}var vs;(function(t){t.Completable="McpCompletable"})(vs||(vs={}));const am=/^[A-Za-z0-9._-]{1,128}$/;function cm(t){const e=[];if(t.length===0)return{isValid:!1,warnings:["Tool name cannot be empty"]};if(t.length>128)return{isValid:!1,warnings:[`Tool name exceeds maximum length of 128 characters (current: ${t.length})`]};if(t.includes(" ")&&e.push("Tool name contains spaces, which may cause parsing issues"),t.includes(",")&&e.push("Tool name contains commas, which may cause parsing issues"),(t.startsWith("-")||t.endsWith("-"))&&e.push("Tool name starts or ends with a dash, which may cause parsing issues in some contexts"),(t.startsWith(".")||t.endsWith("."))&&e.push("Tool name starts or ends with a dot, which may cause parsing issues in some contexts"),!am.test(t)){const n=t.split("").filter(r=>!/[A-Za-z0-9._-]/.test(r)).filter((r,s,i)=>i.indexOf(r)===s);return e.push(`Tool name contains invalid characters: ${n.map(r=>`"${r}"`).join(", ")}`,"Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)"),{isValid:!1,warnings:e}}return{isValid:!0,warnings:e}}function um(t,e){if(e.length>0){console.warn(`Tool name validation warning for "${t}":`);for(const n of e)console.warn(` - ${n}`);console.warn("Tool registration will proceed, but this may cause compatibility issues."),console.warn("Consider updating the tool name to conform to the MCP tool naming standard."),console.warn("See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.")}}function bs(t){const e=cm(t);return um(t,e.warnings),e.isValid}class lm{constructor(e){this._mcpServer=e}registerToolTask(e,n,r){const s={taskSupport:"required",...n.execution};if(s.taskSupport==="forbidden")throw new Error(`Cannot register task-based tool '${e}' with taskSupport 'forbidden'. Use registerTool() instead.`);return this._mcpServer._createRegisteredTool(e,n.title,n.description,n.inputSchema,n.outputSchema,n.annotations,s,n._meta,r)}}class dm{constructor(e,n){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new im(e,n)}get experimental(){return this._experimental||(this._experimental={tasks:new lm(this)}),this._experimental}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(Zn)),this.server.assertCanSetRequestHandler(Le(Wt)),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(Zn,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,n])=>{const r={name:e,title:n.title,description:n.description,inputSchema:(()=>{const s=gt(n.inputSchema);return s?ms(s,{strictUnions:!0,pipeStrategy:"input"}):fm})(),annotations:n.annotations,execution:n.execution,_meta:n._meta};if(n.outputSchema){const s=gt(n.outputSchema);s&&(r.outputSchema=ms(s,{strictUnions:!0,pipeStrategy:"output"}))}return r})})),this.server.setRequestHandler(Wt,async(e,n)=>{var r;try{const s=this._registeredTools[e.params.name];if(!s)throw new C(x.InvalidParams,`Tool ${e.params.name} not found`);if(!s.enabled)throw new C(x.InvalidParams,`Tool ${e.params.name} disabled`);const i=!!e.params.task,o=(r=s.execution)==null?void 0:r.taskSupport,a="createTask"in s.handler;if((o==="required"||o==="optional")&&!a)throw new C(x.InternalError,`Tool ${e.params.name} has taskSupport '${o}' but was not registered with registerToolTask`);if(o==="required"&&!i)throw new C(x.MethodNotFound,`Tool ${e.params.name} requires task augmentation (taskSupport: 'required')`);if(o==="optional"&&!i&&a)return await this.handleAutomaticTaskPolling(s,e,n);const c=await this.validateToolInput(s,e.params.arguments,e.params.name),u=await this.executeToolHandler(s,c,n);return i||await this.validateToolOutput(s,u,e.params.name),u}catch(s){if(s instanceof C&&s.code===x.UrlElicitationRequired)throw s;return this.createToolError(s instanceof Error?s.message:String(s))}}),this._toolHandlersInitialized=!0)}createToolError(e){return{content:[{type:"text",text:e}],isError:!0}}async validateToolInput(e,n,r){if(!e.inputSchema)return;const i=gt(e.inputSchema)??e.inputSchema,o=await kn(i,n);if(!o.success){const a="error"in o?o.error:"Unknown error",c=Sn(a);throw new C(x.InvalidParams,`Input validation error: Invalid arguments for tool ${r}: ${c}`)}return o.data}async validateToolOutput(e,n,r){if(!e.outputSchema||!("content"in n)||n.isError)return;if(!n.structuredContent)throw new C(x.InvalidParams,`Output validation error: Tool ${r} has an output schema but no structured content was provided`);const s=gt(e.outputSchema),i=await kn(s,n.structuredContent);if(!i.success){const o="error"in i?i.error:"Unknown error",a=Sn(o);throw new C(x.InvalidParams,`Output validation error: Invalid structured content for tool ${r}: ${a}`)}}async executeToolHandler(e,n,r){const s=e.handler;if("createTask"in s){if(!r.taskStore)throw new Error("No task store provided.");const o={...r,taskStore:r.taskStore};if(e.inputSchema){const a=s;return await Promise.resolve(a.createTask(n,o))}else{const a=s;return await Promise.resolve(a.createTask(o))}}if(e.inputSchema){const o=s;return await Promise.resolve(o(n,r))}else{const o=s;return await Promise.resolve(o(r))}}async handleAutomaticTaskPolling(e,n,r){if(!r.taskStore)throw new Error("No task store provided for task-capable tool.");const s=await this.validateToolInput(e,n.params.arguments,n.params.name),i=e.handler,o={...r,taskStore:r.taskStore},a=s?await Promise.resolve(i.createTask(s,o)):await Promise.resolve(i.createTask(o)),c=a.task.taskId;let u=a.task;const l=u.pollInterval??5e3;for(;u.status!=="completed"&&u.status!=="failed"&&u.status!=="cancelled";){await new Promise(p=>setTimeout(p,l));const d=await r.taskStore.getTask(c);if(!d)throw new C(x.InternalError,`Task ${c} not found during polling`);u=d}return await r.taskStore.getTaskResult(c)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(Le(An)),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(An,async e=>{switch(e.params.ref.type){case"ref/prompt":return yf(e),this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return vf(e),this.handleResourceCompletion(e,e.params.ref);default:throw new C(x.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,n){const r=this._registeredPrompts[n.name];if(!r)throw new C(x.InvalidParams,`Prompt ${n.name} not found`);if(!r.enabled)throw new C(x.InvalidParams,`Prompt ${n.name} disabled`);if(!r.argsSchema)return _t;const s=Ot(r.argsSchema),i=s==null?void 0:s[e.params.argument.name];if(!ys(i))return _t;const o=om(i);if(!o)return _t;const a=await o(e.params.argument.value,e.params.context);return ks(a)}async handleResourceCompletion(e,n){const r=Object.values(this._registeredResourceTemplates).find(o=>o.resourceTemplate.uriTemplate.toString()===n.uri);if(!r){if(this._registeredResources[n.uri])return _t;throw new C(x.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const s=r.resourceTemplate.completeCallback(e.params.argument.name);if(!s)return _t;const i=await s(e.params.argument.value,e.params.context);return ks(i)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(En)),this.server.assertCanSetRequestHandler(Le(Cn)),this.server.assertCanSetRequestHandler(Le(In)),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(En,async(e,n)=>{const r=Object.entries(this._registeredResources).filter(([i,o])=>o.enabled).map(([i,o])=>({uri:i,name:o.name,...o.metadata})),s=[];for(const i of Object.values(this._registeredResourceTemplates)){if(!i.resourceTemplate.listCallback)continue;const o=await i.resourceTemplate.listCallback(n);for(const a of o.resources)s.push({...i.metadata,...a})}return{resources:[...r,...s]}}),this.server.setRequestHandler(Cn,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([n,r])=>({name:n,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(In,async(e,n)=>{const r=new URL(e.params.uri),s=this._registeredResources[r.toString()];if(s){if(!s.enabled)throw new C(x.InvalidParams,`Resource ${r} disabled`);return s.readCallback(r,n)}for(const i of Object.values(this._registeredResourceTemplates)){const o=i.resourceTemplate.uriTemplate.match(r.toString());if(o)return i.readCallback(r,o,n)}throw new C(x.InvalidParams,`Resource ${r} not found`)}),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(On)),this.server.assertCanSetRequestHandler(Le(xn)),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(On,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,n])=>({name:e,title:n.title,description:n.description,arguments:n.argsSchema?mm(n.argsSchema):void 0}))})),this.server.setRequestHandler(xn,async(e,n)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new C(x.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new C(x.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const s=gt(r.argsSchema),i=await kn(s,e.params.arguments);if(!i.success){const c="error"in i?i.error:"Unknown error",u=Sn(c);throw new C(x.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${u}`)}const o=i.data,a=r.callback;return await Promise.resolve(a(o,n))}else{const s=r.callback;return await Promise.resolve(s(n))}}),this._promptHandlersInitialized=!0)}resource(e,n,...r){let s;typeof r[0]=="object"&&(s=r.shift());const i=r[0];if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const o=this._createRegisteredResource(e,void 0,n,s,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const o=this._createRegisteredResourceTemplate(e,void 0,n,s,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}}registerResource(e,n,r,s){if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const i=this._createRegisteredResource(e,r.title,n,r,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const i=this._createRegisteredResourceTemplate(e,r.title,n,r,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}}_createRegisteredResource(e,n,r,s,i){const o={name:e,title:n,metadata:s,readCallback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({uri:null}),update:a=>{typeof a.uri<"u"&&a.uri!==r&&(delete this._registeredResources[r],a.uri&&(this._registeredResources[a.uri]=o)),typeof a.name<"u"&&(o.name=a.name),typeof a.title<"u"&&(o.title=a.title),typeof a.metadata<"u"&&(o.metadata=a.metadata),typeof a.callback<"u"&&(o.readCallback=a.callback),typeof a.enabled<"u"&&(o.enabled=a.enabled),this.sendResourceListChanged()}};return this._registeredResources[r]=o,o}_createRegisteredResourceTemplate(e,n,r,s,i){const o={resourceTemplate:r,title:n,metadata:s,readCallback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:u=>{typeof u.name<"u"&&u.name!==e&&(delete this._registeredResourceTemplates[e],u.name&&(this._registeredResourceTemplates[u.name]=o)),typeof u.title<"u"&&(o.title=u.title),typeof u.template<"u"&&(o.resourceTemplate=u.template),typeof u.metadata<"u"&&(o.metadata=u.metadata),typeof u.callback<"u"&&(o.readCallback=u.callback),typeof u.enabled<"u"&&(o.enabled=u.enabled),this.sendResourceListChanged()}};this._registeredResourceTemplates[e]=o;const a=r.uriTemplate.variableNames;return Array.isArray(a)&&a.some(u=>!!r.completeCallback(u))&&this.setCompletionRequestHandler(),o}_createRegisteredPrompt(e,n,r,s,i){const o={title:n,description:r,argsSchema:s===void 0?void 0:st(s),callback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:a=>{typeof a.name<"u"&&a.name!==e&&(delete this._registeredPrompts[e],a.name&&(this._registeredPrompts[a.name]=o)),typeof a.title<"u"&&(o.title=a.title),typeof a.description<"u"&&(o.description=a.description),typeof a.argsSchema<"u"&&(o.argsSchema=st(a.argsSchema)),typeof a.callback<"u"&&(o.callback=a.callback),typeof a.enabled<"u"&&(o.enabled=a.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=o,s&&Object.values(s).some(c=>{var l;const u=c instanceof uo.ZodOptional?(l=c._def)==null?void 0:l.innerType:c;return ys(u)})&&this.setCompletionRequestHandler(),o}_createRegisteredTool(e,n,r,s,i,o,a,c,u){bs(e);const l={title:n,description:r,inputSchema:ws(s),outputSchema:ws(i),annotations:o,execution:a,_meta:c,handler:u,enabled:!0,disable:()=>l.update({enabled:!1}),enable:()=>l.update({enabled:!0}),remove:()=>l.update({name:null}),update:d=>{typeof d.name<"u"&&d.name!==e&&(typeof d.name=="string"&&bs(d.name),delete this._registeredTools[e],d.name&&(this._registeredTools[d.name]=l)),typeof d.title<"u"&&(l.title=d.title),typeof d.description<"u"&&(l.description=d.description),typeof d.paramsSchema<"u"&&(l.inputSchema=st(d.paramsSchema)),typeof d.outputSchema<"u"&&(l.outputSchema=st(d.outputSchema)),typeof d.callback<"u"&&(l.handler=d.callback),typeof d.annotations<"u"&&(l.annotations=d.annotations),typeof d._meta<"u"&&(l._meta=d._meta),typeof d.enabled<"u"&&(l.enabled=d.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=l,this.setToolRequestHandlers(),this.sendToolListChanged(),l}tool(e,...n){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,s,i,o;if(typeof n[0]=="string"&&(r=n.shift()),n.length>1){const c=n[0];Jn(c)?(s=n.shift(),n.length>1&&typeof n[0]=="object"&&n[0]!==null&&!Jn(n[0])&&(o=n.shift())):typeof c=="object"&&c!==null&&(o=n.shift())}const a=n[0];return this._createRegisteredTool(e,void 0,r,s,i,o,{taskSupport:"forbidden"},void 0,a)}registerTool(e,n,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{title:s,description:i,inputSchema:o,outputSchema:a,annotations:c,_meta:u}=n;return this._createRegisteredTool(e,s,i,o,a,c,{taskSupport:"forbidden"},u,r)}prompt(e,...n){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof n[0]=="string"&&(r=n.shift());let s;n.length>1&&(s=n.shift());const i=n[0],o=this._createRegisteredPrompt(e,void 0,r,s,i);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}registerPrompt(e,n,r){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);const{title:s,description:i,argsSchema:o}=n,a=this._createRegisteredPrompt(e,s,i,o,r);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(e,n){return this.server.sendLoggingMessage(e,n)}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const fm={type:"object",properties:{}};function so(t){return t!==null&&typeof t=="object"&&"parse"in t&&typeof t.parse=="function"&&"safeParse"in t&&typeof t.safeParse=="function"}function hm(t){return"_def"in t||"_zod"in t||so(t)}function Jn(t){return typeof t!="object"||t===null||hm(t)?!1:Object.keys(t).length===0?!0:Object.values(t).some(so)}function ws(t){if(t)return Jn(t)?st(t):t}function mm(t){const e=Ot(t);return e?Object.entries(e).map(([n,r])=>{const s=ah(r),i=ch(r);return{name:n,description:s,required:!i}}):[]}function Le(t){const e=Ot(t),n=e==null?void 0:e.method;if(!n)throw new Error("Schema is missing a method literal");const r=Wi(n);if(typeof r=="string")return r;throw new Error("Schema method literal must be a string")}function ks(t){return{completion:{values:t.slice(0,100),total:t.length,hasMore:t.length>100}}}const _t={completion:{values:[],hasMore:!1}},Ss=lo.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:yn&&yn.tagName.toUpperCase()==="SCRIPT"&&yn.src||new URL("index.cjs",document.baseURI).href);let Bn;try{Bn=Ss("./package.json").version}catch{Bn=Ss("../package.json").version}function pm(){return new dm({name:"wordpress-playground",version:Bn,description:`Use this server when you need a live WordPress environment without any local setup. WordPress Playground runs entirely in the user's browser tab via WebAssembly — no PHP, MySQL, or server required. You are automatically authenticated as an admin user.
|
|
45
|
+
]`;continue}s+=r[u],r[u]==="\\"?i=!0:o&&r[u]==="]"?o=!1:!o&&r[u]==="["&&(o=!0)}try{new RegExp(s)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return s}function to(t,e){var r,s,i,o,a,c;if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&((r=t.keyType)==null?void 0:r._def.typeName)===S.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((u,l)=>({...u,[l]:G(t.valueType._def,{...e,currentPath:[...e.currentPath,"properties",l]})??ke(e)}),{}),additionalProperties:e.rejectedAdditionalProperties};const n={type:"object",additionalProperties:G(t.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return n;if(((s=t.keyType)==null?void 0:s._def.typeName)===S.ZodString&&((i=t.keyType._def.checks)!=null&&i.length)){const{type:u,...l}=eo(t.keyType._def,e);return{...n,propertyNames:l}}else{if(((o=t.keyType)==null?void 0:o._def.typeName)===S.ZodEnum)return{...n,propertyNames:{enum:t.keyType._def.values}};if(((a=t.keyType)==null?void 0:a._def.typeName)===S.ZodBranded&&t.keyType._def.type._def.typeName===S.ZodString&&((c=t.keyType._def.type._def.checks)!=null&&c.length)){const{type:u,...l}=Qi(t.keyType._def,e);return{...n,propertyNames:l}}}return n}function $h(t,e){if(e.mapStrategy==="record")return to(t,e);const n=G(t.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||ke(e),r=G(t.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||ke(e);return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function Rh(t){const e=t.values,r=Object.keys(t.values).filter(i=>typeof e[e[i]]!="number").map(i=>e[i]),s=Array.from(new Set(r.map(i=>typeof i)));return{type:s.length===1?s[0]==="string"?"string":"number":["string","number"],enum:r}}function Ph(t){return t.target==="openAi"?void 0:{not:ke({...t,currentPath:[...t.currentPath,"not"]})}}function Nh(t){return t.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}const sn={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Eh(t,e){if(e.target==="openApi3")return ms(t,e);const n=t.options instanceof Map?Array.from(t.options.values()):t.options;if(n.every(r=>r._def.typeName in sn&&(!r._def.checks||!r._def.checks.length))){const r=n.reduce((s,i)=>{const o=sn[i._def.typeName];return o&&!s.includes(o)?[...s,o]:s},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){const r=n.reduce((s,i)=>{const o=typeof i._def.value;switch(o){case"string":case"number":case"boolean":return[...s,o];case"bigint":return[...s,"integer"];case"object":if(i._def.value===null)return[...s,"null"];case"symbol":case"undefined":case"function":default:return s}},[]);if(r.length===n.length){const s=r.filter((i,o,a)=>a.indexOf(i)===o);return{type:s.length>1?s:s[0],enum:n.reduce((i,o)=>i.includes(o._def.value)?i:[...i,o._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,s)=>[...r,...s._def.values.filter(i=>!r.includes(i))],[])};return ms(t,e)}const ms=(t,e)=>{const n=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((r,s)=>G(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${s}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function Ih(t,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return e.target==="openApi3"?{type:sn[t.innerType._def.typeName],nullable:!0}:{type:[sn[t.innerType._def.typeName],"null"]};if(e.target==="openApi3"){const r=G(t.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const n=G(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function Ch(t,e){const n={type:"number"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"int":n.type="integer",Ki(n,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?Y(n,"minimum",r.value,r.message,e):Y(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),Y(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?Y(n,"maximum",r.value,r.message,e):Y(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),Y(n,"maximum",r.value,r.message,e));break;case"multipleOf":Y(n,"multipleOf",r.value,r.message,e);break}return n}function Oh(t,e){const n=e.target==="openAi",r={type:"object",properties:{}},s=[],i=t.shape();for(const a in i){let c=i[a];if(c===void 0||c._def===void 0)continue;let u=Zh(c);u&&n&&(c._def.typeName==="ZodOptional"&&(c=c._def.innerType),c.isNullable()||(c=c.nullable()),u=!1);const l=G(c._def,{...e,currentPath:[...e.currentPath,"properties",a],propertyPath:[...e.currentPath,"properties",a]});l!==void 0&&(r.properties[a]=l,u||s.push(a))}s.length&&(r.required=s);const o=xh(t,e);return o!==void 0&&(r.additionalProperties=o),r}function xh(t,e){if(t.catchall._def.typeName!=="ZodNever")return G(t.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function Zh(t){try{return t.isOptional()}catch{return!0}}const Ah=(t,e)=>{var r;if(e.currentPath.toString()===((r=e.propertyPath)==null?void 0:r.toString()))return G(t.innerType._def,e);const n=G(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return n?{anyOf:[{not:ke(e)},n]}:ke(e)},jh=(t,e)=>{if(e.pipeStrategy==="input")return G(t.in._def,e);if(e.pipeStrategy==="output")return G(t.out._def,e);const n=G(t.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=G(t.out._def,{...e,currentPath:[...e.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(s=>s!==void 0)}};function Mh(t,e){return G(t.type._def,e)}function Lh(t,e){const r={type:"array",uniqueItems:!0,items:G(t.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return t.minSize&&Y(r,"minItems",t.minSize.value,t.minSize.message,e),t.maxSize&&Y(r,"maxItems",t.maxSize.value,t.maxSize.message,e),r}function Dh(t,e){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((n,r)=>G(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:G(t.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((n,r)=>G(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function qh(t){return{not:ke(t)}}function Fh(t){return ke(t)}const Uh=(t,e)=>G(t.innerType._def,e),Vh=(t,e,n)=>{switch(e){case S.ZodString:return eo(t,n);case S.ZodNumber:return Ch(t,n);case S.ZodObject:return Oh(t,n);case S.ZodBigInt:return mh(t,n);case S.ZodBoolean:return ph();case S.ZodDate:return Xi(t,n);case S.ZodUndefined:return qh(n);case S.ZodNull:return Nh(n);case S.ZodArray:return hh(t,n);case S.ZodUnion:case S.ZodDiscriminatedUnion:return Eh(t,n);case S.ZodIntersection:return kh(t,n);case S.ZodTuple:return Dh(t,n);case S.ZodRecord:return to(t,n);case S.ZodLiteral:return Sh(t,n);case S.ZodEnum:return bh(t);case S.ZodNativeEnum:return Rh(t);case S.ZodNullable:return Ih(t,n);case S.ZodOptional:return Ah(t,n);case S.ZodMap:return $h(t,n);case S.ZodSet:return Lh(t,n);case S.ZodLazy:return()=>t.getter()._def;case S.ZodPromise:return Mh(t,n);case S.ZodNaN:case S.ZodNever:return Ph(n);case S.ZodEffects:return vh(t,n);case S.ZodAny:return ke(n);case S.ZodUnknown:return Fh(n);case S.ZodDefault:return yh(t,n);case S.ZodBranded:return Qi(t,n);case S.ZodReadonly:return Uh(t,n);case S.ZodCatch:return gh(t,n);case S.ZodPipeline:return jh(t,n);case S.ZodFunction:case S.ZodVoid:case S.ZodSymbol:return;default:return(r=>{})()}};function G(t,e,n=!1){var a;const r=e.seen.get(t);if(e.override){const c=(a=e.override)==null?void 0:a.call(e,t,e,r,n);if(c!==lh)return c}if(r&&!n){const c=Hh(r,e);if(c!==void 0)return c}const s={def:t,path:e.currentPath,jsonSchema:void 0};e.seen.set(t,s);const i=Vh(t,t.typeName,e),o=typeof i=="function"?G(i(),e):i;if(o&&Jh(t,e,o),e.postProcess){const c=e.postProcess(o,t,e);return s.jsonSchema=o,c}return s.jsonSchema=o,o}const Hh=(t,e)=>{switch(e.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:Yi(e.currentPath,t.path)};case"none":case"seen":return t.path.length<e.currentPath.length&&t.path.every((n,r)=>e.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),ke(e)):e.$refStrategy==="seen"?ke(e):void 0}},Jh=(t,e,n)=>(t.description&&(n.description=t.description,e.markdownDescription&&(n.markdownDescription=t.description)),n),Bh=(t,e)=>{const n=fh(e);let r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((c,[u,l])=>({...c,[u]:G(l._def,{...n,currentPath:[...n.basePath,n.definitionPath,u]},!0)??ke(n)}),{}):void 0;const s=typeof e=="string"?e:(e==null?void 0:e.nameStrategy)==="title"||e==null?void 0:e.name,i=G(t._def,s===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,s]},!1)??ke(n),o=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;o!==void 0&&(i.title=o),n.flags.hasReferencedOpenAiAnyType&&(r||(r={}),r[n.openAiAnyTypeName]||(r[n.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:n.$refStrategy==="relative"?"1":[...n.basePath,n.definitionPath,n.openAiAnyTypeName].join("/")}}));const a=s===void 0?r?{...i,[n.definitionPath]:r}:i:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,s].join("/"),[n.definitionPath]:{...r,[s]:i}};return n.target==="jsonSchema7"?a.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(a.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in a||"oneOf"in a||"allOf"in a||"type"in a&&Array.isArray(a.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),a};function Wh(t){return!t||t==="jsonSchema7"||t==="draft-7"?"draft-7":t==="jsonSchema2019-09"||t==="draft-2020-12"?"draft-2020-12":"draft-7"}function ps(t,e){return Ze(t)?Iu(t,{target:Wh(e==null?void 0:e.target),io:(e==null?void 0:e.pipeStrategy)??"input"}):Bh(t,{strictUnions:(e==null?void 0:e.strictUnions)??!0,pipeStrategy:(e==null?void 0:e.pipeStrategy)??"input"})}function gs(t){const e=xt(t),n=e==null?void 0:e.method;if(!n)throw new Error("Schema is missing a method literal");const r=Gi(n);if(typeof r!="string")throw new Error("Schema method literal must be a string");return r}function _s(t,e){const n=kt(t,e);if(!n.success)throw n.error;return n.data}const Gh=6e4;class Kh{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this._pendingDebouncedNotifications=new Set,this._taskProgressTokens=new Map,this._requestResolvers=new Map,this.setNotificationHandler(cr,n=>{this._oncancel(n)}),this.setNotificationHandler(lr,n=>{this._onprogress(n)}),this.setRequestHandler(ur,n=>({})),this._taskStore=e==null?void 0:e.taskStore,this._taskMessageQueue=e==null?void 0:e.taskMessageQueue,this._taskStore&&(this.setRequestHandler(dr,async(n,r)=>{const s=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!s)throw new E(O.InvalidParams,"Failed to retrieve task: Task not found");return{...s}}),this.setRequestHandler(hr,async(n,r)=>{const s=async()=>{var a;const i=n.params.taskId;if(this._taskMessageQueue){let c;for(;c=await this._taskMessageQueue.dequeue(i,r.sessionId);){if(c.type==="response"||c.type==="error"){const u=c.message,l=u.id,f=this._requestResolvers.get(l);if(f)if(this._requestResolvers.delete(l),c.type==="response")f(u);else{const p=u,m=new E(p.error.code,p.error.message,p.error.data);f(m)}else{const p=c.type==="response"?"Response":"Error";this._onerror(new Error(`${p} handler missing for request ${l}`))}continue}await((a=this._transport)==null?void 0:a.send(c.message,{relatedRequestId:r.requestId}))}}const o=await this._taskStore.getTask(i,r.sessionId);if(!o)throw new E(O.InvalidParams,`Task not found: ${i}`);if(!Ke(o.status))return await this._waitForTaskUpdate(i,r.signal),await s();if(Ke(o.status)){const c=await this._taskStore.getTaskResult(i,r.sessionId);return this._clearTaskQueue(i),{...c,_meta:{...c._meta,[Ye]:{taskId:i}}}}return await s()};return await s()}),this.setRequestHandler(mr,async(n,r)=>{var s;try{const{tasks:i,nextCursor:o}=await this._taskStore.listTasks((s=n.params)==null?void 0:s.cursor,r.sessionId);return{tasks:i,nextCursor:o,_meta:{}}}catch(i){throw new E(O.InvalidParams,`Failed to list tasks: ${i instanceof Error?i.message:String(i)}`)}}),this.setRequestHandler(gr,async(n,r)=>{try{const s=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!s)throw new E(O.InvalidParams,`Task not found: ${n.params.taskId}`);if(Ke(s.status))throw new E(O.InvalidParams,`Cannot cancel task in terminal status: ${s.status}`);await this._taskStore.updateTaskStatus(n.params.taskId,"cancelled","Client cancelled task execution.",r.sessionId),this._clearTaskQueue(n.params.taskId);const i=await this._taskStore.getTask(n.params.taskId,r.sessionId);if(!i)throw new E(O.InvalidParams,`Task not found after cancellation: ${n.params.taskId}`);return{_meta:{},...i}}catch(s){throw s instanceof E?s:new E(O.InvalidRequest,`Failed to cancel task: ${s instanceof Error?s.message:String(s)}`)}}))}async _oncancel(e){if(!e.params.requestId)return;const n=this._requestHandlerAbortControllers.get(e.params.requestId);n==null||n.abort(e.params.reason)}_setupTimeout(e,n,r,s,i=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(s,n),startTime:Date.now(),timeout:n,maxTotalTimeout:r,resetTimeoutOnProgress:i,onTimeout:s})}_resetTimeout(e){const n=this._timeoutInfo.get(e);if(!n)return!1;const r=Date.now()-n.startTime;if(n.maxTotalTimeout&&r>=n.maxTotalTimeout)throw this._timeoutInfo.delete(e),E.fromError(O.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:n.maxTotalTimeout,totalElapsed:r});return clearTimeout(n.timeoutId),n.timeoutId=setTimeout(n.onTimeout,n.timeout),!0}_cleanupTimeout(e){const n=this._timeoutInfo.get(e);n&&(clearTimeout(n.timeoutId),this._timeoutInfo.delete(e))}async connect(e){var i,o,a;if(this._transport)throw new Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");this._transport=e;const n=(i=this.transport)==null?void 0:i.onclose;this._transport.onclose=()=>{n==null||n(),this._onclose()};const r=(o=this.transport)==null?void 0:o.onerror;this._transport.onerror=c=>{r==null||r(c),this._onerror(c)};const s=(a=this._transport)==null?void 0:a.onmessage;this._transport.onmessage=(c,u)=>{s==null||s(c,u),Dt(c)||Gl(c)?this._onresponse(c):Wr(c)?this._onrequest(c,u):Wl(c)?this._onnotification(c):this._onerror(new Error(`Unknown message type: ${JSON.stringify(c)}`))},await this._transport.start()}_onclose(){var r;const e=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._taskProgressTokens.clear(),this._pendingDebouncedNotifications.clear();for(const s of this._requestHandlerAbortControllers.values())s.abort();this._requestHandlerAbortControllers.clear();const n=E.fromError(O.ConnectionClosed,"Connection closed");this._transport=void 0,(r=this.onclose)==null||r.call(this);for(const s of e.values())s(n)}_onerror(e){var n;(n=this.onerror)==null||n.call(this,e)}_onnotification(e){const n=this._notificationHandlers.get(e.method)??this.fallbackNotificationHandler;n!==void 0&&Promise.resolve().then(()=>n(e)).catch(r=>this._onerror(new Error(`Uncaught error in notification handler: ${r}`)))}_onrequest(e,n){var l,f,p,m;const r=this._requestHandlers.get(e.method)??this.fallbackRequestHandler,s=this._transport,i=(p=(f=(l=e.params)==null?void 0:l._meta)==null?void 0:f[Ye])==null?void 0:p.taskId;if(r===void 0){const v={jsonrpc:"2.0",id:e.id,error:{code:O.MethodNotFound,message:"Method not found"}};i&&this._taskMessageQueue?this._enqueueTaskMessage(i,{type:"error",message:v,timestamp:Date.now()},s==null?void 0:s.sessionId).catch(T=>this._onerror(new Error(`Failed to enqueue error response: ${T}`))):s==null||s.send(v).catch(T=>this._onerror(new Error(`Failed to send an error response: ${T}`)));return}const o=new AbortController;this._requestHandlerAbortControllers.set(e.id,o);const a=Bl(e.params)?e.params.task:void 0,c=this._taskStore?this.requestTaskStore(e,s==null?void 0:s.sessionId):void 0,u={signal:o.signal,sessionId:s==null?void 0:s.sessionId,_meta:(m=e.params)==null?void 0:m._meta,sendNotification:async v=>{if(o.signal.aborted)return;const T={relatedRequestId:e.id};i&&(T.relatedTask={taskId:i}),await this.notification(v,T)},sendRequest:async(v,T,x)=>{var A;if(o.signal.aborted)throw new E(O.ConnectionClosed,"Request was cancelled");const b={...x,relatedRequestId:e.id};i&&!b.relatedTask&&(b.relatedTask={taskId:i});const y=((A=b.relatedTask)==null?void 0:A.taskId)??i;return y&&c&&await c.updateTaskStatus(y,"input_required"),await this.request(v,T,b)},authInfo:n==null?void 0:n.authInfo,requestId:e.id,requestInfo:n==null?void 0:n.requestInfo,taskId:i,taskStore:c,taskRequestedTtl:a==null?void 0:a.ttl,closeSSEStream:n==null?void 0:n.closeSSEStream,closeStandaloneSSEStream:n==null?void 0:n.closeStandaloneSSEStream};Promise.resolve().then(()=>{a&&this.assertTaskHandlerCapability(e.method)}).then(()=>r(e,u)).then(async v=>{if(o.signal.aborted)return;const T={result:v,jsonrpc:"2.0",id:e.id};i&&this._taskMessageQueue?await this._enqueueTaskMessage(i,{type:"response",message:T,timestamp:Date.now()},s==null?void 0:s.sessionId):await(s==null?void 0:s.send(T))},async v=>{if(o.signal.aborted)return;const T={jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(v.code)?v.code:O.InternalError,message:v.message??"Internal error",...v.data!==void 0&&{data:v.data}}};i&&this._taskMessageQueue?await this._enqueueTaskMessage(i,{type:"error",message:T,timestamp:Date.now()},s==null?void 0:s.sessionId):await(s==null?void 0:s.send(T))}).catch(v=>this._onerror(new Error(`Failed to send response: ${v}`))).finally(()=>{this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){const{progressToken:n,...r}=e.params,s=Number(n),i=this._progressHandlers.get(s);if(!i){this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}const o=this._responseHandlers.get(s),a=this._timeoutInfo.get(s);if(a&&o&&a.resetTimeoutOnProgress)try{this._resetTimeout(s)}catch(c){this._responseHandlers.delete(s),this._progressHandlers.delete(s),this._cleanupTimeout(s),o(c);return}i(r)}_onresponse(e){const n=Number(e.id),r=this._requestResolvers.get(n);if(r){if(this._requestResolvers.delete(n),Dt(e))r(e);else{const o=new E(e.error.code,e.error.message,e.error.data);r(o)}return}const s=this._responseHandlers.get(n);if(s===void 0){this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}this._responseHandlers.delete(n),this._cleanupTimeout(n);let i=!1;if(Dt(e)&&e.result&&typeof e.result=="object"){const o=e.result;if(o.task&&typeof o.task=="object"){const a=o.task;typeof a.taskId=="string"&&(i=!0,this._taskProgressTokens.set(a.taskId,n))}}if(i||this._progressHandlers.delete(n),Dt(e))s(e);else{const o=E.fromError(e.error.code,e.error.message,e.error.data);s(o)}}get transport(){return this._transport}async close(){var e;await((e=this._transport)==null?void 0:e.close())}async*requestStream(e,n,r){var o,a;const{task:s}=r??{};if(!s){try{yield{type:"result",result:await this.request(e,n,r)}}catch(c){yield{type:"error",error:c instanceof E?c:new E(O.InternalError,String(c))}}return}let i;try{const c=await this.request(e,gn,r);if(c.task)i=c.task.taskId,yield{type:"taskCreated",task:c.task};else throw new E(O.InternalError,"Task creation did not return a task");for(;;){const u=await this.getTask({taskId:i},r);if(yield{type:"taskStatus",task:u},Ke(u.status)){u.status==="completed"?yield{type:"result",result:await this.getTaskResult({taskId:i},n,r)}:u.status==="failed"?yield{type:"error",error:new E(O.InternalError,`Task ${i} failed`)}:u.status==="cancelled"&&(yield{type:"error",error:new E(O.InternalError,`Task ${i} was cancelled`)});return}if(u.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:i},n,r)};return}const l=u.pollInterval??((o=this._options)==null?void 0:o.defaultTaskPollInterval)??1e3;await new Promise(f=>setTimeout(f,l)),(a=r==null?void 0:r.signal)==null||a.throwIfAborted()}}catch(c){yield{type:"error",error:c instanceof E?c:new E(O.InternalError,String(c))}}}request(e,n,r){const{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o,task:a,relatedTask:c}=r??{};return new Promise((u,l)=>{var y,A,j,L,ue;const f=K=>{l(K)};if(!this._transport){f(new Error("Not connected"));return}if(((y=this._options)==null?void 0:y.enforceStrictCapabilities)===!0)try{this.assertCapabilityForMethod(e.method),a&&this.assertTaskCapability(e.method)}catch(K){f(K);return}(A=r==null?void 0:r.signal)==null||A.throwIfAborted();const p=this._requestMessageId++,m={...e,jsonrpc:"2.0",id:p};r!=null&&r.onprogress&&(this._progressHandlers.set(p,r.onprogress),m.params={...e.params,_meta:{...((j=e.params)==null?void 0:j._meta)||{},progressToken:p}}),a&&(m.params={...m.params,task:a}),c&&(m.params={...m.params,_meta:{...((L=m.params)==null?void 0:L._meta)||{},[Ye]:c}});const v=K=>{var fe;this._responseHandlers.delete(p),this._progressHandlers.delete(p),this._cleanupTimeout(p),(fe=this._transport)==null||fe.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:p,reason:String(K)}},{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o}).catch(Je=>this._onerror(new Error(`Failed to send cancellation: ${Je}`)));const _e=K instanceof E?K:new E(O.RequestTimeout,String(K));l(_e)};this._responseHandlers.set(p,K=>{var _e;if(!((_e=r==null?void 0:r.signal)!=null&&_e.aborted)){if(K instanceof Error)return l(K);try{const fe=kt(n,K.result);fe.success?u(fe.data):l(fe.error)}catch(fe){l(fe)}}}),(ue=r==null?void 0:r.signal)==null||ue.addEventListener("abort",()=>{var K;v((K=r==null?void 0:r.signal)==null?void 0:K.reason)});const T=(r==null?void 0:r.timeout)??Gh,x=()=>v(E.fromError(O.RequestTimeout,"Request timed out",{timeout:T}));this._setupTimeout(p,T,r==null?void 0:r.maxTotalTimeout,x,(r==null?void 0:r.resetTimeoutOnProgress)??!1);const b=c==null?void 0:c.taskId;if(b){const K=_e=>{const fe=this._responseHandlers.get(p);fe?fe(_e):this._onerror(new Error(`Response handler missing for side-channeled request ${p}`))};this._requestResolvers.set(p,K),this._enqueueTaskMessage(b,{type:"request",message:m,timestamp:Date.now()}).catch(_e=>{this._cleanupTimeout(p),l(_e)})}else this._transport.send(m,{relatedRequestId:s,resumptionToken:i,onresumptiontoken:o}).catch(K=>{this._cleanupTimeout(p),l(K)})})}async getTask(e,n){return this.request({method:"tasks/get",params:e},fr,n)}async getTaskResult(e,n,r){return this.request({method:"tasks/result",params:e},n,r)}async listTasks(e,n){return this.request({method:"tasks/list",params:e},pr,n)}async cancelTask(e,n){return this.request({method:"tasks/cancel",params:e},fd,n)}async notification(e,n){var a,c,u,l;if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);const r=(a=n==null?void 0:n.relatedTask)==null?void 0:a.taskId;if(r){const f={...e,jsonrpc:"2.0",params:{...e.params,_meta:{...((c=e.params)==null?void 0:c._meta)||{},[Ye]:n.relatedTask}}};await this._enqueueTaskMessage(r,{type:"notification",message:f,timestamp:Date.now()});return}if((((u=this._options)==null?void 0:u.debouncedNotificationMethods)??[]).includes(e.method)&&!e.params&&!(n!=null&&n.relatedRequestId)&&!(n!=null&&n.relatedTask)){if(this._pendingDebouncedNotifications.has(e.method))return;this._pendingDebouncedNotifications.add(e.method),Promise.resolve().then(()=>{var p,m;if(this._pendingDebouncedNotifications.delete(e.method),!this._transport)return;let f={...e,jsonrpc:"2.0"};n!=null&&n.relatedTask&&(f={...f,params:{...f.params,_meta:{...((p=f.params)==null?void 0:p._meta)||{},[Ye]:n.relatedTask}}}),(m=this._transport)==null||m.send(f,n).catch(v=>this._onerror(v))});return}let o={...e,jsonrpc:"2.0"};n!=null&&n.relatedTask&&(o={...o,params:{...o.params,_meta:{...((l=o.params)==null?void 0:l._meta)||{},[Ye]:n.relatedTask}}}),await this._transport.send(o,n)}setRequestHandler(e,n){const r=gs(e);this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,(s,i)=>{const o=_s(e,s);return Promise.resolve(n(o,i))})}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,n){const r=gs(e);this._notificationHandlers.set(r,s=>{const i=_s(e,s);return Promise.resolve(n(i))})}removeNotificationHandler(e){this._notificationHandlers.delete(e)}_cleanupTaskProgressHandler(e){const n=this._taskProgressTokens.get(e);n!==void 0&&(this._progressHandlers.delete(n),this._taskProgressTokens.delete(e))}async _enqueueTaskMessage(e,n,r){var i;if(!this._taskStore||!this._taskMessageQueue)throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");const s=(i=this._options)==null?void 0:i.maxTaskQueueSize;await this._taskMessageQueue.enqueue(e,n,r,s)}async _clearTaskQueue(e,n){if(this._taskMessageQueue){const r=await this._taskMessageQueue.dequeueAll(e,n);for(const s of r)if(s.type==="request"&&Wr(s.message)){const i=s.message.id,o=this._requestResolvers.get(i);o?(o(new E(O.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(i)):this._onerror(new Error(`Resolver missing for request ${i} during task ${e} cleanup`))}}}async _waitForTaskUpdate(e,n){var s,i;let r=((s=this._options)==null?void 0:s.defaultTaskPollInterval)??1e3;try{const o=await((i=this._taskStore)==null?void 0:i.getTask(e));o!=null&&o.pollInterval&&(r=o.pollInterval)}catch{}return new Promise((o,a)=>{if(n.aborted){a(new E(O.InvalidRequest,"Request cancelled"));return}const c=setTimeout(o,r);n.addEventListener("abort",()=>{clearTimeout(c),a(new E(O.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(e,n){const r=this._taskStore;if(!r)throw new Error("No task store configured");return{createTask:async s=>{if(!e)throw new Error("No request provided");return await r.createTask(s,e.id,{method:e.method,params:e.params},n)},getTask:async s=>{const i=await r.getTask(s,n);if(!i)throw new E(O.InvalidParams,"Failed to retrieve task: Task not found");return i},storeTaskResult:async(s,i,o)=>{await r.storeTaskResult(s,i,o,n);const a=await r.getTask(s,n);if(a){const c=Bt.parse({method:"notifications/tasks/status",params:a});await this.notification(c),Ke(a.status)&&this._cleanupTaskProgressHandler(s)}},getTaskResult:s=>r.getTaskResult(s,n),updateTaskStatus:async(s,i,o)=>{const a=await r.getTask(s,n);if(!a)throw new E(O.InvalidParams,`Task "${s}" not found - it may have been cleaned up`);if(Ke(a.status))throw new E(O.InvalidParams,`Cannot update task "${s}" from terminal status "${a.status}" to "${i}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await r.updateTaskStatus(s,i,o,n);const c=await r.getTask(s,n);if(c){const u=Bt.parse({method:"notifications/tasks/status",params:c});await this.notification(u),Ke(c.status)&&this._cleanupTaskProgressHandler(s)}},listTasks:s=>r.listTasks(s,n)}}}function ys(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Yh(t,e){const n={...t};for(const r in e){const s=r,i=e[s];if(i===void 0)continue;const o=n[s];ys(o)&&ys(i)?n[s]={...o,...i}:n[s]=i}return n}function Qh(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Hn={exports:{}},no={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.formatNames=t.fastFormats=t.fullFormats=void 0;function e(Z,F){return{validate:Z,compare:F}}t.fullFormats={date:e(i,o),time:e(c(!0),u),"date-time":e(p(!0),m),"iso-time":e(c(),l),"iso-date-time":e(p(),v),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:b,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:Je,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:A,int32:{type:"number",validate:ue},int64:{type:"number",validate:K},float:{type:"number",validate:_e},double:{type:"number",validate:_e},password:!0,binary:!0},t.fastFormats={...t.fullFormats,date:e(/^\d\d\d\d-[0-1]\d-[0-3]\d$/,o),time:e(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,u),"date-time":e(/^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,m),"iso-time":e(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,l),"iso-date-time":e(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,v),uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i},t.formatNames=Object.keys(t.fullFormats);function n(Z){return Z%4===0&&(Z%100!==0||Z%400===0)}const r=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,s=[0,31,28,31,30,31,30,31,31,30,31,30,31];function i(Z){const F=r.exec(Z);if(!F)return!1;const ae=+F[1],U=+F[2],Te=+F[3];return U>=1&&U<=12&&Te>=1&&Te<=(U===2&&n(ae)?29:s[U])}function o(Z,F){if(Z&&F)return Z>F?1:Z<F?-1:0}const a=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;function c(Z){return function(ae){const U=a.exec(ae);if(!U)return!1;const Te=+U[1],Be=+U[2],We=+U[3],_n=U[4],Zt=U[5]==="-"?-1:1,At=+(U[6]||0),pt=+(U[7]||0);if(At>23||pt>59||Z&&!_n)return!1;if(Te<=23&&Be<=59&&We<60)return!0;const Ge=Be-pt*Zt,C=Te-At*Zt-(Ge<0?1:0);return(C===23||C===-1)&&(Ge===59||Ge===-1)&&We<61}}function u(Z,F){if(!(Z&&F))return;const ae=new Date("2020-01-01T"+Z).valueOf(),U=new Date("2020-01-01T"+F).valueOf();if(ae&&U)return ae-U}function l(Z,F){if(!(Z&&F))return;const ae=a.exec(Z),U=a.exec(F);if(ae&&U)return Z=ae[1]+ae[2]+ae[3],F=U[1]+U[2]+U[3],Z>F?1:Z<F?-1:0}const f=/t|\s/i;function p(Z){const F=c(Z);return function(U){const Te=U.split(f);return Te.length===2&&i(Te[0])&&F(Te[1])}}function m(Z,F){if(!(Z&&F))return;const ae=new Date(Z).valueOf(),U=new Date(F).valueOf();if(ae&&U)return ae-U}function v(Z,F){if(!(Z&&F))return;const[ae,U]=Z.split(f),[Te,Be]=F.split(f),We=o(ae,Te);if(We!==void 0)return We||u(U,Be)}const T=/\/|:/,x=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function b(Z){return T.test(Z)&&x.test(Z)}const y=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;function A(Z){return y.lastIndex=0,y.test(Z)}const j=-2147483648,L=2**31-1;function ue(Z){return Number.isInteger(Z)&&Z<=L&&Z>=j}function K(Z){return Number.isInteger(Z)}function _e(){return!0}const fe=/[^\\]\\Z/;function Je(Z){if(fe.test(Z))return!1;try{return new RegExp(Z),!0}catch{return!1}}})(no);var ro={},$r={},on={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.regexpCode=t.getEsmExportName=t.getProperty=t.safeStringify=t.stringify=t.strConcat=t.addCodeArg=t.str=t._=t.nil=t._Code=t.Name=t.IDENTIFIER=t._CodeOrName=void 0;class e{}t._CodeOrName=e,t.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class n extends e{constructor(y){if(super(),!t.IDENTIFIER.test(y))throw new Error("CodeGen: name must be a valid identifier");this.str=y}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}t.Name=n;class r extends e{constructor(y){super(),this._items=typeof y=="string"?[y]:y}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;const y=this._items[0];return y===""||y==='""'}get str(){var y;return(y=this._str)!==null&&y!==void 0?y:this._str=this._items.reduce((A,j)=>`${A}${j}`,"")}get names(){var y;return(y=this._names)!==null&&y!==void 0?y:this._names=this._items.reduce((A,j)=>(j instanceof n&&(A[j.str]=(A[j.str]||0)+1),A),{})}}t._Code=r,t.nil=new r("");function s(b,...y){const A=[b[0]];let j=0;for(;j<y.length;)a(A,y[j]),A.push(b[++j]);return new r(A)}t._=s;const i=new r("+");function o(b,...y){const A=[m(b[0])];let j=0;for(;j<y.length;)A.push(i),a(A,y[j]),A.push(i,m(b[++j]));return c(A),new r(A)}t.str=o;function a(b,y){y instanceof r?b.push(...y._items):y instanceof n?b.push(y):b.push(f(y))}t.addCodeArg=a;function c(b){let y=1;for(;y<b.length-1;){if(b[y]===i){const A=u(b[y-1],b[y+1]);if(A!==void 0){b.splice(y-1,3,A);continue}b[y++]="+"}y++}}function u(b,y){if(y==='""')return b;if(b==='""')return y;if(typeof b=="string")return y instanceof n||b[b.length-1]!=='"'?void 0:typeof y!="string"?`${b.slice(0,-1)}${y}"`:y[0]==='"'?b.slice(0,-1)+y.slice(1):void 0;if(typeof y=="string"&&y[0]==='"'&&!(b instanceof n))return`"${b}${y.slice(1)}`}function l(b,y){return y.emptyStr()?b:b.emptyStr()?y:o`${b}${y}`}t.strConcat=l;function f(b){return typeof b=="number"||typeof b=="boolean"||b===null?b:m(Array.isArray(b)?b.join(","):b)}function p(b){return new r(m(b))}t.stringify=p;function m(b){return JSON.stringify(b).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}t.safeStringify=m;function v(b){return typeof b=="string"&&t.IDENTIFIER.test(b)?new r(`.${b}`):s`[${b}]`}t.getProperty=v;function T(b){if(typeof b=="string"&&t.IDENTIFIER.test(b))return new r(`${b}`);throw new Error(`CodeGen: invalid export name: ${b}, use explicit $id name mapping`)}t.getEsmExportName=T;function x(b){return new r(b.toString())}t.regexpCode=x})(on);var Jn={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ValueScope=t.ValueScopeName=t.Scope=t.varKinds=t.UsedValueState=void 0;const e=on;class n extends Error{constructor(u){super(`CodeGen: "code" for ${u} not defined`),this.value=u.value}}var r;(function(c){c[c.Started=0]="Started",c[c.Completed=1]="Completed"})(r||(t.UsedValueState=r={})),t.varKinds={const:new e.Name("const"),let:new e.Name("let"),var:new e.Name("var")};class s{constructor({prefixes:u,parent:l}={}){this._names={},this._prefixes=u,this._parent=l}toName(u){return u instanceof e.Name?u:this.name(u)}name(u){return new e.Name(this._newName(u))}_newName(u){const l=this._names[u]||this._nameGroup(u);return`${u}${l.index++}`}_nameGroup(u){var l,f;if(!((f=(l=this._parent)===null||l===void 0?void 0:l._prefixes)===null||f===void 0)&&f.has(u)||this._prefixes&&!this._prefixes.has(u))throw new Error(`CodeGen: prefix "${u}" is not allowed in this scope`);return this._names[u]={prefix:u,index:0}}}t.Scope=s;class i extends e.Name{constructor(u,l){super(l),this.prefix=u}setValue(u,{property:l,itemIndex:f}){this.value=u,this.scopePath=(0,e._)`.${new e.Name(l)}[${f}]`}}t.ValueScopeName=i;const o=(0,e._)`\n`;class a extends s{constructor(u){super(u),this._values={},this._scope=u.scope,this.opts={...u,_n:u.lines?o:e.nil}}get(){return this._scope}name(u){return new i(u,this._newName(u))}value(u,l){var f;if(l.ref===void 0)throw new Error("CodeGen: ref must be passed in value");const p=this.toName(u),{prefix:m}=p,v=(f=l.key)!==null&&f!==void 0?f:l.ref;let T=this._values[m];if(T){const y=T.get(v);if(y)return y}else T=this._values[m]=new Map;T.set(v,p);const x=this._scope[m]||(this._scope[m]=[]),b=x.length;return x[b]=l.ref,p.setValue(l,{property:m,itemIndex:b}),p}getValue(u,l){const f=this._values[u];if(f)return f.get(l)}scopeRefs(u,l=this._values){return this._reduceValues(l,f=>{if(f.scopePath===void 0)throw new Error(`CodeGen: name "${f}" has no value`);return(0,e._)`${u}${f.scopePath}`})}scopeCode(u=this._values,l,f){return this._reduceValues(u,p=>{if(p.value===void 0)throw new Error(`CodeGen: name "${p}" has no value`);return p.value.code},l,f)}_reduceValues(u,l,f={},p){let m=e.nil;for(const v in u){const T=u[v];if(!T)continue;const x=f[v]=f[v]||new Map;T.forEach(b=>{if(x.has(b))return;x.set(b,r.Started);let y=l(b);if(y){const A=this.opts.es5?t.varKinds.var:t.varKinds.const;m=(0,e._)`${m}${A} ${b} = ${y};${this.opts._n}`}else if(y=p==null?void 0:p(b))m=(0,e._)`${m}${y}${this.opts._n}`;else throw new n(b);x.set(b,r.Completed)})}return m}}t.ValueScope=a})(Jn);(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.or=t.and=t.not=t.CodeGen=t.operators=t.varKinds=t.ValueScopeName=t.ValueScope=t.Scope=t.Name=t.regexpCode=t.stringify=t.getProperty=t.nil=t.strConcat=t.str=t._=void 0;const e=on,n=Jn;var r=on;Object.defineProperty(t,"_",{enumerable:!0,get:function(){return r._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return r.str}}),Object.defineProperty(t,"strConcat",{enumerable:!0,get:function(){return r.strConcat}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return r.nil}}),Object.defineProperty(t,"getProperty",{enumerable:!0,get:function(){return r.getProperty}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return r.stringify}}),Object.defineProperty(t,"regexpCode",{enumerable:!0,get:function(){return r.regexpCode}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return r.Name}});var s=Jn;Object.defineProperty(t,"Scope",{enumerable:!0,get:function(){return s.Scope}}),Object.defineProperty(t,"ValueScope",{enumerable:!0,get:function(){return s.ValueScope}}),Object.defineProperty(t,"ValueScopeName",{enumerable:!0,get:function(){return s.ValueScopeName}}),Object.defineProperty(t,"varKinds",{enumerable:!0,get:function(){return s.varKinds}}),t.operators={GT:new e._Code(">"),GTE:new e._Code(">="),LT:new e._Code("<"),LTE:new e._Code("<="),EQ:new e._Code("==="),NEQ:new e._Code("!=="),NOT:new e._Code("!"),OR:new e._Code("||"),AND:new e._Code("&&"),ADD:new e._Code("+")};class i{optimizeNodes(){return this}optimizeNames(d,h){return this}}class o extends i{constructor(d,h,w){super(),this.varKind=d,this.name=h,this.rhs=w}render({es5:d,_n:h}){const w=d?n.varKinds.var:this.varKind,q=this.rhs===void 0?"":` = ${this.rhs}`;return`${w} ${this.name}${q};`+h}optimizeNames(d,h){if(d[this.name.str])return this.rhs&&(this.rhs=U(this.rhs,d,h)),this}get names(){return this.rhs instanceof e._CodeOrName?this.rhs.names:{}}}class a extends i{constructor(d,h,w){super(),this.lhs=d,this.rhs=h,this.sideEffects=w}render({_n:d}){return`${this.lhs} = ${this.rhs};`+d}optimizeNames(d,h){if(!(this.lhs instanceof e.Name&&!d[this.lhs.str]&&!this.sideEffects))return this.rhs=U(this.rhs,d,h),this}get names(){const d=this.lhs instanceof e.Name?{}:{...this.lhs.names};return ae(d,this.rhs)}}class c extends a{constructor(d,h,w,q){super(d,w,q),this.op=h}render({_n:d}){return`${this.lhs} ${this.op}= ${this.rhs};`+d}}class u extends i{constructor(d){super(),this.label=d,this.names={}}render({_n:d}){return`${this.label}:`+d}}class l extends i{constructor(d){super(),this.label=d,this.names={}}render({_n:d}){return`break${this.label?` ${this.label}`:""};`+d}}class f extends i{constructor(d){super(),this.error=d}render({_n:d}){return`throw ${this.error};`+d}get names(){return this.error.names}}class p extends i{constructor(d){super(),this.code=d}render({_n:d}){return`${this.code};`+d}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(d,h){return this.code=U(this.code,d,h),this}get names(){return this.code instanceof e._CodeOrName?this.code.names:{}}}class m extends i{constructor(d=[]){super(),this.nodes=d}render(d){return this.nodes.reduce((h,w)=>h+w.render(d),"")}optimizeNodes(){const{nodes:d}=this;let h=d.length;for(;h--;){const w=d[h].optimizeNodes();Array.isArray(w)?d.splice(h,1,...w):w?d[h]=w:d.splice(h,1)}return d.length>0?this:void 0}optimizeNames(d,h){const{nodes:w}=this;let q=w.length;for(;q--;){const J=w[q];J.optimizeNames(d,h)||(Te(d,J.names),w.splice(q,1))}return w.length>0?this:void 0}get names(){return this.nodes.reduce((d,h)=>F(d,h.names),{})}}class v extends m{render(d){return"{"+d._n+super.render(d)+"}"+d._n}}class T extends m{}class x extends v{}x.kind="else";class b extends v{constructor(d,h){super(h),this.condition=d}render(d){let h=`if(${this.condition})`+super.render(d);return this.else&&(h+="else "+this.else.render(d)),h}optimizeNodes(){super.optimizeNodes();const d=this.condition;if(d===!0)return this.nodes;let h=this.else;if(h){const w=h.optimizeNodes();h=this.else=Array.isArray(w)?new x(w):w}if(h)return d===!1?h instanceof b?h:h.nodes:this.nodes.length?this:new b(Be(d),h instanceof b?[h]:h.nodes);if(!(d===!1||!this.nodes.length))return this}optimizeNames(d,h){var w;if(this.else=(w=this.else)===null||w===void 0?void 0:w.optimizeNames(d,h),!!(super.optimizeNames(d,h)||this.else))return this.condition=U(this.condition,d,h),this}get names(){const d=super.names;return ae(d,this.condition),this.else&&F(d,this.else.names),d}}b.kind="if";class y extends v{}y.kind="for";class A extends y{constructor(d){super(),this.iteration=d}render(d){return`for(${this.iteration})`+super.render(d)}optimizeNames(d,h){if(super.optimizeNames(d,h))return this.iteration=U(this.iteration,d,h),this}get names(){return F(super.names,this.iteration.names)}}class j extends y{constructor(d,h,w,q){super(),this.varKind=d,this.name=h,this.from=w,this.to=q}render(d){const h=d.es5?n.varKinds.var:this.varKind,{name:w,from:q,to:J}=this;return`for(${h} ${w}=${q}; ${w}<${J}; ${w}++)`+super.render(d)}get names(){const d=ae(super.names,this.from);return ae(d,this.to)}}class L extends y{constructor(d,h,w,q){super(),this.loop=d,this.varKind=h,this.name=w,this.iterable=q}render(d){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(d)}optimizeNames(d,h){if(super.optimizeNames(d,h))return this.iterable=U(this.iterable,d,h),this}get names(){return F(super.names,this.iterable.names)}}class ue extends v{constructor(d,h,w){super(),this.name=d,this.args=h,this.async=w}render(d){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(d)}}ue.kind="func";class K extends m{render(d){return"return "+super.render(d)}}K.kind="return";class _e extends v{render(d){let h="try"+super.render(d);return this.catch&&(h+=this.catch.render(d)),this.finally&&(h+=this.finally.render(d)),h}optimizeNodes(){var d,h;return super.optimizeNodes(),(d=this.catch)===null||d===void 0||d.optimizeNodes(),(h=this.finally)===null||h===void 0||h.optimizeNodes(),this}optimizeNames(d,h){var w,q;return super.optimizeNames(d,h),(w=this.catch)===null||w===void 0||w.optimizeNames(d,h),(q=this.finally)===null||q===void 0||q.optimizeNames(d,h),this}get names(){const d=super.names;return this.catch&&F(d,this.catch.names),this.finally&&F(d,this.finally.names),d}}class fe extends v{constructor(d){super(),this.error=d}render(d){return`catch(${this.error})`+super.render(d)}}fe.kind="catch";class Je extends v{render(d){return"finally"+super.render(d)}}Je.kind="finally";class Z{constructor(d,h={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...h,_n:h.lines?`
|
|
46
|
+
`:""},this._extScope=d,this._scope=new n.Scope({parent:d}),this._nodes=[new T]}toString(){return this._root.render(this.opts)}name(d){return this._scope.name(d)}scopeName(d){return this._extScope.name(d)}scopeValue(d,h){const w=this._extScope.value(d,h);return(this._values[w.prefix]||(this._values[w.prefix]=new Set)).add(w),w}getScopeValue(d,h){return this._extScope.getValue(d,h)}scopeRefs(d){return this._extScope.scopeRefs(d,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(d,h,w,q){const J=this._scope.toName(h);return w!==void 0&&q&&(this._constants[J.str]=w),this._leafNode(new o(d,J,w)),J}const(d,h,w){return this._def(n.varKinds.const,d,h,w)}let(d,h,w){return this._def(n.varKinds.let,d,h,w)}var(d,h,w){return this._def(n.varKinds.var,d,h,w)}assign(d,h,w){return this._leafNode(new a(d,h,w))}add(d,h){return this._leafNode(new c(d,t.operators.ADD,h))}code(d){return typeof d=="function"?d():d!==e.nil&&this._leafNode(new p(d)),this}object(...d){const h=["{"];for(const[w,q]of d)h.length>1&&h.push(","),h.push(w),(w!==q||this.opts.es5)&&(h.push(":"),(0,e.addCodeArg)(h,q));return h.push("}"),new e._Code(h)}if(d,h,w){if(this._blockNode(new b(d)),h&&w)this.code(h).else().code(w).endIf();else if(h)this.code(h).endIf();else if(w)throw new Error('CodeGen: "else" body without "then" body');return this}elseIf(d){return this._elseNode(new b(d))}else(){return this._elseNode(new x)}endIf(){return this._endBlockNode(b,x)}_for(d,h){return this._blockNode(d),h&&this.code(h).endFor(),this}for(d,h){return this._for(new A(d),h)}forRange(d,h,w,q,J=this.opts.es5?n.varKinds.var:n.varKinds.let){const de=this._scope.toName(d);return this._for(new j(J,de,h,w),()=>q(de))}forOf(d,h,w,q=n.varKinds.const){const J=this._scope.toName(d);if(this.opts.es5){const de=h instanceof e.Name?h:this.var("_arr",h);return this.forRange("_i",0,(0,e._)`${de}.length`,oo=>{this.var(J,(0,e._)`${de}[${oo}]`),w(J)})}return this._for(new L("of",q,J,h),()=>w(J))}forIn(d,h,w,q=this.opts.es5?n.varKinds.var:n.varKinds.const){if(this.opts.ownProperties)return this.forOf(d,(0,e._)`Object.keys(${h})`,w);const J=this._scope.toName(d);return this._for(new L("in",q,J,h),()=>w(J))}endFor(){return this._endBlockNode(y)}label(d){return this._leafNode(new u(d))}break(d){return this._leafNode(new l(d))}return(d){const h=new K;if(this._blockNode(h),this.code(d),h.nodes.length!==1)throw new Error('CodeGen: "return" should have one node');return this._endBlockNode(K)}try(d,h,w){if(!h&&!w)throw new Error('CodeGen: "try" without "catch" and "finally"');const q=new _e;if(this._blockNode(q),this.code(d),h){const J=this.name("e");this._currNode=q.catch=new fe(J),h(J)}return w&&(this._currNode=q.finally=new Je,this.code(w)),this._endBlockNode(fe,Je)}throw(d){return this._leafNode(new f(d))}block(d,h){return this._blockStarts.push(this._nodes.length),d&&this.code(d).endBlock(h),this}endBlock(d){const h=this._blockStarts.pop();if(h===void 0)throw new Error("CodeGen: not in self-balancing block");const w=this._nodes.length-h;if(w<0||d!==void 0&&w!==d)throw new Error(`CodeGen: wrong number of nodes: ${w} vs ${d} expected`);return this._nodes.length=h,this}func(d,h=e.nil,w,q){return this._blockNode(new ue(d,h,w)),q&&this.code(q).endFunc(),this}endFunc(){return this._endBlockNode(ue)}optimize(d=1){for(;d-- >0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(d){return this._currNode.nodes.push(d),this}_blockNode(d){this._currNode.nodes.push(d),this._nodes.push(d)}_endBlockNode(d,h){const w=this._currNode;if(w instanceof d||h&&w instanceof h)return this._nodes.pop(),this;throw new Error(`CodeGen: not in block "${h?`${d.kind}/${h.kind}`:d.kind}"`)}_elseNode(d){const h=this._currNode;if(!(h instanceof b))throw new Error('CodeGen: "else" without "if"');return this._currNode=h.else=d,this}get _root(){return this._nodes[0]}get _currNode(){const d=this._nodes;return d[d.length-1]}set _currNode(d){const h=this._nodes;h[h.length-1]=d}}t.CodeGen=Z;function F(C,d){for(const h in d)C[h]=(C[h]||0)+(d[h]||0);return C}function ae(C,d){return d instanceof e._CodeOrName?F(C,d.names):C}function U(C,d,h){if(C instanceof e.Name)return w(C);if(!q(C))return C;return new e._Code(C._items.reduce((J,de)=>(de instanceof e.Name&&(de=w(de)),de instanceof e._Code?J.push(...de._items):J.push(de),J),[]));function w(J){const de=h[J.str];return de===void 0||d[J.str]!==1?J:(delete d[J.str],de)}function q(J){return J instanceof e._Code&&J._items.some(de=>de instanceof e.Name&&d[de.str]===1&&h[de.str]!==void 0)}}function Te(C,d){for(const h in d)C[h]=(C[h]||0)-(d[h]||0)}function Be(C){return typeof C=="boolean"||typeof C=="number"||C===null?!C:(0,e._)`!${Ge(C)}`}t.not=Be;const We=pt(t.operators.AND);function _n(...C){return C.reduce(We)}t.and=_n;const Zt=pt(t.operators.OR);function At(...C){return C.reduce(Zt)}t.or=At;function pt(C){return(d,h)=>d===e.nil?h:h===e.nil?d:(0,e._)`${Ge(d)} ${C} ${Ge(h)}`}function Ge(C){return C instanceof e.Name?C:(0,e._)`(${C})`}})($r);(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.formatLimitDefinition=void 0;const e=$s,n=$r,r=n.operators,s={formatMaximum:{okStr:"<=",ok:r.LTE,fail:r.GT},formatMinimum:{okStr:">=",ok:r.GTE,fail:r.LT},formatExclusiveMaximum:{okStr:"<",ok:r.LT,fail:r.GTE},formatExclusiveMinimum:{okStr:">",ok:r.GT,fail:r.LTE}},i={message:({keyword:a,schemaCode:c})=>(0,n.str)`should be ${s[a].okStr} ${c}`,params:({keyword:a,schemaCode:c})=>(0,n._)`{comparison: ${s[a].okStr}, limit: ${c}}`};t.formatLimitDefinition={keyword:Object.keys(s),type:"string",schemaType:"string",$data:!0,error:i,code(a){const{gen:c,data:u,schemaCode:l,keyword:f,it:p}=a,{opts:m,self:v}=p;if(!m.validateFormats)return;const T=new e.KeywordCxt(p,v.RULES.all.format.definition,"format");T.$data?x():b();function x(){const A=c.scopeValue("formats",{ref:v.formats,code:m.code.formats}),j=c.const("fmt",(0,n._)`${A}[${T.schemaCode}]`);a.fail$data((0,n.or)((0,n._)`typeof ${j} != "object"`,(0,n._)`${j} instanceof RegExp`,(0,n._)`typeof ${j}.compare != "function"`,y(j)))}function b(){const A=T.schema,j=v.formats[A];if(!j||j===!0)return;if(typeof j!="object"||j instanceof RegExp||typeof j.compare!="function")throw new Error(`"${f}": format "${A}" does not define "compare" function`);const L=c.scopeValue("formats",{key:A,ref:j,code:m.code.formats?(0,n._)`${m.code.formats}${(0,n.getProperty)(A)}`:void 0});a.fail$data(y(L))}function y(A){return(0,n._)`${A}.compare(${u}, ${l}) ${s[f].fail} 0`}},dependencies:["format"]};const o=a=>(a.addKeyword(t.formatLimitDefinition),a);t.default=o})(ro);(function(t,e){Object.defineProperty(e,"__esModule",{value:!0});const n=no,r=ro,s=$r,i=new s.Name("fullFormats"),o=new s.Name("fastFormats"),a=(u,l={keywords:!0})=>{if(Array.isArray(l))return c(u,l,n.fullFormats,i),u;const[f,p]=l.mode==="fast"?[n.fastFormats,o]:[n.fullFormats,i],m=l.formats||n.formatNames;return c(u,m,f,p),l.keywords&&(0,r.default)(u),u};a.get=(u,l="full")=>{const p=(l==="fast"?n.fastFormats:n.fullFormats)[u];if(!p)throw new Error(`Unknown format "${u}"`);return p};function c(u,l,f,p){var m,v;(m=(v=u.opts.code).formats)!==null&&m!==void 0||(v.formats=(0,s._)`require("ajv-formats/dist/formats").${p}`);for(const T of l)u.addFormat(T,f[T])}t.exports=e=a,Object.defineProperty(e,"__esModule",{value:!0}),e.default=a})(Hn,Hn.exports);var Xh=Hn.exports;const em=Qh(Xh);function tm(){const t=new $s({strict:!1,validateFormats:!0,validateSchema:!1,allErrors:!0});return em(t),t}class nm{constructor(e){this._ajv=e??tm()}getValidator(e){const n="$id"in e&&typeof e.$id=="string"?this._ajv.getSchema(e.$id)??this._ajv.compile(e):this._ajv.compile(e);return r=>n(r)?{valid:!0,data:r,errorMessage:void 0}:{valid:!1,data:void 0,errorMessage:this._ajv.errorsText(n.errors)}}}class rm{constructor(e){this._server=e}requestStream(e,n,r){return this._server.requestStream(e,n,r)}createMessageStream(e,n){var s;const r=this._server.getClientCapabilities();if((e.tools||e.toolChoice)&&!((s=r==null?void 0:r.sampling)!=null&&s.tools))throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){const i=e.messages[e.messages.length-1],o=Array.isArray(i.content)?i.content:[i.content],a=o.some(f=>f.type==="tool_result"),c=e.messages.length>1?e.messages[e.messages.length-2]:void 0,u=c?Array.isArray(c.content)?c.content:[c.content]:[],l=u.some(f=>f.type==="tool_use");if(a){if(o.some(f=>f.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!l)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(l){const f=new Set(u.filter(m=>m.type==="tool_use").map(m=>m.id)),p=new Set(o.filter(m=>m.type==="tool_result").map(m=>m.toolUseId));if(f.size!==p.size||![...f].every(m=>p.has(m)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return this.requestStream({method:"sampling/createMessage",params:e},Tr,n)}elicitInputStream(e,n){var o,a;const r=this._server.getClientCapabilities(),s=e.mode??"form";switch(s){case"url":{if(!((o=r==null?void 0:r.elicitation)!=null&&o.url))throw new Error("Client does not support url elicitation.");break}case"form":{if(!((a=r==null?void 0:r.elicitation)!=null&&a.form))throw new Error("Client does not support form elicitation.");break}}const i=s==="form"&&e.mode===void 0?{...e,mode:"form"}:e;return this.requestStream({method:"elicitation/create",params:i},Yt,n)}async getTask(e,n){return this._server.getTask({taskId:e},n)}async getTaskResult(e,n,r){return this._server.getTaskResult({taskId:e},n,r)}async listTasks(e,n){return this._server.listTasks(e?{cursor:e}:void 0,n)}async cancelTask(e,n){return this._server.cancelTask({taskId:e},n)}}function sm(t,e,n){var r;if(!t)throw new Error(`${n} does not support task creation (required for ${e})`);switch(e){case"tools/call":if(!((r=t.tools)!=null&&r.call))throw new Error(`${n} does not support task creation for tools/call (required for ${e})`);break}}function im(t,e,n){var r,s;if(!t)throw new Error(`${n} does not support task creation (required for ${e})`);switch(e){case"sampling/createMessage":if(!((r=t.sampling)!=null&&r.createMessage))throw new Error(`${n} does not support task creation for sampling/createMessage (required for ${e})`);break;case"elicitation/create":if(!((s=t.elicitation)!=null&&s.create))throw new Error(`${n} does not support task creation for elicitation/create (required for ${e})`);break}}class om extends Kh{constructor(e,n){super(n),this._serverInfo=e,this._loggingLevels=new Map,this.LOG_LEVEL_SEVERITY=new Map(Gt.options.map((r,s)=>[r,s])),this.isMessageIgnored=(r,s)=>{const i=this._loggingLevels.get(s);return i?this.LOG_LEVEL_SEVERITY.get(r)<this.LOG_LEVEL_SEVERITY.get(i):!1},this._capabilities=(n==null?void 0:n.capabilities)??{},this._instructions=n==null?void 0:n.instructions,this._jsonSchemaValidator=(n==null?void 0:n.jsonSchemaValidator)??new nm,this.setRequestHandler(Ai,r=>this._oninitialize(r)),this.setNotificationHandler(ji,()=>{var r;return(r=this.oninitialized)==null?void 0:r.call(this)}),this._capabilities.logging&&this.setRequestHandler(Ui,async(r,s)=>{var c;const i=s.sessionId||((c=s.requestInfo)==null?void 0:c.headers["mcp-session-id"])||void 0,{level:o}=r.params,a=Gt.safeParse(o);return a.success&&this._loggingLevels.set(i,a.data),{}})}get experimental(){return this._experimental||(this._experimental={tasks:new rm(this)}),this._experimental}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=Yh(this._capabilities,e)}setRequestHandler(e,n){var a;const r=xt(e),s=r==null?void 0:r.method;if(!s)throw new Error("Schema is missing a method literal");let i;if(Ze(s)){const c=s,u=(a=c._zod)==null?void 0:a.def;i=(u==null?void 0:u.value)??c.value}else{const c=s,u=c._def;i=(u==null?void 0:u.value)??c.value}if(typeof i!="string")throw new Error("Schema method literal must be a string");if(i==="tools/call"){const c=async(u,l)=>{const f=kt(Wt,u);if(!f.success){const T=f.error instanceof Error?f.error.message:String(f.error);throw new E(O.InvalidParams,`Invalid tools/call request: ${T}`)}const{params:p}=f.data,m=await Promise.resolve(n(u,l));if(p.task){const T=kt(gn,m);if(!T.success){const x=T.error instanceof Error?T.error.message:String(T.error);throw new E(O.InvalidParams,`Invalid task creation result: ${x}`)}return T.data}const v=kt(Sr,m);if(!v.success){const T=v.error instanceof Error?v.error.message:String(v.error);throw new E(O.InvalidParams,`Invalid tools/call result: ${T}`)}return v.data};return super.setRequestHandler(e,c)}return super.setRequestHandler(e,n)}assertCapabilityForMethod(e){var n,r,s;switch(e){case"sampling/createMessage":if(!((n=this._clientCapabilities)!=null&&n.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"elicitation/create":if(!((r=this._clientCapabilities)!=null&&r.elicitation))throw new Error(`Client does not support elicitation (required for ${e})`);break;case"roots/list":if(!((s=this._clientCapabilities)!=null&&s.roots))throw new Error(`Client does not support listing roots (required for ${e})`);break}}assertNotificationCapability(e){var n,r;switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case"notifications/elicitation/complete":if(!((r=(n=this._clientCapabilities)==null?void 0:n.elicitation)!=null&&r.url))throw new Error(`Client does not support URL elicitation (required for ${e})`);break}}assertRequestHandlerCapability(e){if(this._capabilities)switch(e){case"completion/complete":if(!this._capabilities.completions)throw new Error(`Server does not support completions (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw new Error(`Server does not support tasks capability (required for ${e})`);break}}assertTaskCapability(e){var n,r;im((r=(n=this._clientCapabilities)==null?void 0:n.tasks)==null?void 0:r.requests,e,"Client")}assertTaskHandlerCapability(e){var n;this._capabilities&&sm((n=this._capabilities.tasks)==null?void 0:n.requests,e,"Server")}async _oninitialize(e){const n=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Vl.includes(n)?n:Ei,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},ar)}async createMessage(e,n){var r,s;if((e.tools||e.toolChoice)&&!((s=(r=this._clientCapabilities)==null?void 0:r.sampling)!=null&&s.tools))throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){const i=e.messages[e.messages.length-1],o=Array.isArray(i.content)?i.content:[i.content],a=o.some(f=>f.type==="tool_result"),c=e.messages.length>1?e.messages[e.messages.length-2]:void 0,u=c?Array.isArray(c.content)?c.content:[c.content]:[],l=u.some(f=>f.type==="tool_use");if(a){if(o.some(f=>f.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!l)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(l){const f=new Set(u.filter(m=>m.type==="tool_use").map(m=>m.id)),p=new Set(o.filter(m=>m.type==="tool_result").map(m=>m.toolUseId));if(f.size!==p.size||![...f].every(m=>p.has(m)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return e.tools?this.request({method:"sampling/createMessage",params:e},Vi,n):this.request({method:"sampling/createMessage",params:e},Tr,n)}async elicitInput(e,n){var s,i,o,a;switch(e.mode??"form"){case"url":{if(!((i=(s=this._clientCapabilities)==null?void 0:s.elicitation)!=null&&i.url))throw new Error("Client does not support url elicitation.");const c=e;return this.request({method:"elicitation/create",params:c},Yt,n)}case"form":{if(!((a=(o=this._clientCapabilities)==null?void 0:o.elicitation)!=null&&a.form))throw new Error("Client does not support form elicitation.");const c=e.mode==="form"?e:{...e,mode:"form"},u=await this.request({method:"elicitation/create",params:c},Yt,n);if(u.action==="accept"&&u.content&&c.requestedSchema)try{const f=this._jsonSchemaValidator.getValidator(c.requestedSchema)(u.content);if(!f.valid)throw new E(O.InvalidParams,`Elicitation response content does not match requested schema: ${f.errorMessage}`)}catch(l){throw l instanceof E?l:new E(O.InternalError,`Error validating elicitation response: ${l instanceof Error?l.message:String(l)}`)}return u}}}createElicitationCompletionNotifier(e,n){var r,s;if(!((s=(r=this._clientCapabilities)==null?void 0:r.elicitation)!=null&&s.url))throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");return()=>this.notification({method:"notifications/elicitation/complete",params:{elicitationId:e}},n)}async listRoots(e,n){return this.request({method:"roots/list",params:e},Hi,n)}async sendLoggingMessage(e,n){if(this._capabilities.logging&&!this.isMessageIgnored(e.level,n))return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}const so=Symbol.for("mcp.completable");function vs(t){return!!t&&typeof t=="object"&&so in t}function am(t){const e=t[so];return e==null?void 0:e.complete}var bs;(function(t){t.Completable="McpCompletable"})(bs||(bs={}));const cm=/^[A-Za-z0-9._-]{1,128}$/;function um(t){const e=[];if(t.length===0)return{isValid:!1,warnings:["Tool name cannot be empty"]};if(t.length>128)return{isValid:!1,warnings:[`Tool name exceeds maximum length of 128 characters (current: ${t.length})`]};if(t.includes(" ")&&e.push("Tool name contains spaces, which may cause parsing issues"),t.includes(",")&&e.push("Tool name contains commas, which may cause parsing issues"),(t.startsWith("-")||t.endsWith("-"))&&e.push("Tool name starts or ends with a dash, which may cause parsing issues in some contexts"),(t.startsWith(".")||t.endsWith("."))&&e.push("Tool name starts or ends with a dot, which may cause parsing issues in some contexts"),!cm.test(t)){const n=t.split("").filter(r=>!/[A-Za-z0-9._-]/.test(r)).filter((r,s,i)=>i.indexOf(r)===s);return e.push(`Tool name contains invalid characters: ${n.map(r=>`"${r}"`).join(", ")}`,"Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)"),{isValid:!1,warnings:e}}return{isValid:!0,warnings:e}}function lm(t,e){if(e.length>0){console.warn(`Tool name validation warning for "${t}":`);for(const n of e)console.warn(` - ${n}`);console.warn("Tool registration will proceed, but this may cause compatibility issues."),console.warn("Consider updating the tool name to conform to the MCP tool naming standard."),console.warn("See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.")}}function ws(t){const e=um(t);return lm(t,e.warnings),e.isValid}class dm{constructor(e){this._mcpServer=e}registerToolTask(e,n,r){const s={taskSupport:"required",...n.execution};if(s.taskSupport==="forbidden")throw new Error(`Cannot register task-based tool '${e}' with taskSupport 'forbidden'. Use registerTool() instead.`);return this._mcpServer._createRegisteredTool(e,n.title,n.description,n.inputSchema,n.outputSchema,n.annotations,s,n._meta,r)}}class fm{constructor(e,n){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new om(e,n)}get experimental(){return this._experimental||(this._experimental={tasks:new dm(this)}),this._experimental}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(Zn)),this.server.assertCanSetRequestHandler(Le(Wt)),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(Zn,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,n])=>{const r={name:e,title:n.title,description:n.description,inputSchema:(()=>{const s=gt(n.inputSchema);return s?ps(s,{strictUnions:!0,pipeStrategy:"input"}):hm})(),annotations:n.annotations,execution:n.execution,_meta:n._meta};if(n.outputSchema){const s=gt(n.outputSchema);s&&(r.outputSchema=ps(s,{strictUnions:!0,pipeStrategy:"output"}))}return r})})),this.server.setRequestHandler(Wt,async(e,n)=>{var r;try{const s=this._registeredTools[e.params.name];if(!s)throw new E(O.InvalidParams,`Tool ${e.params.name} not found`);if(!s.enabled)throw new E(O.InvalidParams,`Tool ${e.params.name} disabled`);const i=!!e.params.task,o=(r=s.execution)==null?void 0:r.taskSupport,a="createTask"in s.handler;if((o==="required"||o==="optional")&&!a)throw new E(O.InternalError,`Tool ${e.params.name} has taskSupport '${o}' but was not registered with registerToolTask`);if(o==="required"&&!i)throw new E(O.MethodNotFound,`Tool ${e.params.name} requires task augmentation (taskSupport: 'required')`);if(o==="optional"&&!i&&a)return await this.handleAutomaticTaskPolling(s,e,n);const c=await this.validateToolInput(s,e.params.arguments,e.params.name),u=await this.executeToolHandler(s,c,n);return i||await this.validateToolOutput(s,u,e.params.name),u}catch(s){if(s instanceof E&&s.code===O.UrlElicitationRequired)throw s;return this.createToolError(s instanceof Error?s.message:String(s))}}),this._toolHandlersInitialized=!0)}createToolError(e){return{content:[{type:"text",text:e}],isError:!0}}async validateToolInput(e,n,r){if(!e.inputSchema)return;const i=gt(e.inputSchema)??e.inputSchema,o=await kn(i,n);if(!o.success){const a="error"in o?o.error:"Unknown error",c=Sn(a);throw new E(O.InvalidParams,`Input validation error: Invalid arguments for tool ${r}: ${c}`)}return o.data}async validateToolOutput(e,n,r){if(!e.outputSchema||!("content"in n)||n.isError)return;if(!n.structuredContent)throw new E(O.InvalidParams,`Output validation error: Tool ${r} has an output schema but no structured content was provided`);const s=gt(e.outputSchema),i=await kn(s,n.structuredContent);if(!i.success){const o="error"in i?i.error:"Unknown error",a=Sn(o);throw new E(O.InvalidParams,`Output validation error: Invalid structured content for tool ${r}: ${a}`)}}async executeToolHandler(e,n,r){const s=e.handler;if("createTask"in s){if(!r.taskStore)throw new Error("No task store provided.");const o={...r,taskStore:r.taskStore};if(e.inputSchema){const a=s;return await Promise.resolve(a.createTask(n,o))}else{const a=s;return await Promise.resolve(a.createTask(o))}}if(e.inputSchema){const o=s;return await Promise.resolve(o(n,r))}else{const o=s;return await Promise.resolve(o(r))}}async handleAutomaticTaskPolling(e,n,r){if(!r.taskStore)throw new Error("No task store provided for task-capable tool.");const s=await this.validateToolInput(e,n.params.arguments,n.params.name),i=e.handler,o={...r,taskStore:r.taskStore},a=s?await Promise.resolve(i.createTask(s,o)):await Promise.resolve(i.createTask(o)),c=a.task.taskId;let u=a.task;const l=u.pollInterval??5e3;for(;u.status!=="completed"&&u.status!=="failed"&&u.status!=="cancelled";){await new Promise(p=>setTimeout(p,l));const f=await r.taskStore.getTask(c);if(!f)throw new E(O.InternalError,`Task ${c} not found during polling`);u=f}return await r.taskStore.getTaskResult(c)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(Le(An)),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(An,async e=>{switch(e.params.ref.type){case"ref/prompt":return vf(e),this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return bf(e),this.handleResourceCompletion(e,e.params.ref);default:throw new E(O.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,n){const r=this._registeredPrompts[n.name];if(!r)throw new E(O.InvalidParams,`Prompt ${n.name} not found`);if(!r.enabled)throw new E(O.InvalidParams,`Prompt ${n.name} disabled`);if(!r.argsSchema)return _t;const s=xt(r.argsSchema),i=s==null?void 0:s[e.params.argument.name];if(!vs(i))return _t;const o=am(i);if(!o)return _t;const a=await o(e.params.argument.value,e.params.context);return Ss(a)}async handleResourceCompletion(e,n){const r=Object.values(this._registeredResourceTemplates).find(o=>o.resourceTemplate.uriTemplate.toString()===n.uri);if(!r){if(this._registeredResources[n.uri])return _t;throw new E(O.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const s=r.resourceTemplate.completeCallback(e.params.argument.name);if(!s)return _t;const i=await s(e.params.argument.value,e.params.context);return Ss(i)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(En)),this.server.assertCanSetRequestHandler(Le(In)),this.server.assertCanSetRequestHandler(Le(Cn)),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(En,async(e,n)=>{const r=Object.entries(this._registeredResources).filter(([i,o])=>o.enabled).map(([i,o])=>({uri:i,name:o.name,...o.metadata})),s=[];for(const i of Object.values(this._registeredResourceTemplates)){if(!i.resourceTemplate.listCallback)continue;const o=await i.resourceTemplate.listCallback(n);for(const a of o.resources)s.push({...i.metadata,...a})}return{resources:[...r,...s]}}),this.server.setRequestHandler(In,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([n,r])=>({name:n,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(Cn,async(e,n)=>{const r=new URL(e.params.uri),s=this._registeredResources[r.toString()];if(s){if(!s.enabled)throw new E(O.InvalidParams,`Resource ${r} disabled`);return s.readCallback(r,n)}for(const i of Object.values(this._registeredResourceTemplates)){const o=i.resourceTemplate.uriTemplate.match(r.toString());if(o)return i.readCallback(r,o,n)}throw new E(O.InvalidParams,`Resource ${r} not found`)}),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(Le(On)),this.server.assertCanSetRequestHandler(Le(xn)),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(On,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,n])=>({name:e,title:n.title,description:n.description,arguments:n.argsSchema?pm(n.argsSchema):void 0}))})),this.server.setRequestHandler(xn,async(e,n)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new E(O.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new E(O.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const s=gt(r.argsSchema),i=await kn(s,e.params.arguments);if(!i.success){const c="error"in i?i.error:"Unknown error",u=Sn(c);throw new E(O.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${u}`)}const o=i.data,a=r.callback;return await Promise.resolve(a(o,n))}else{const s=r.callback;return await Promise.resolve(s(n))}}),this._promptHandlersInitialized=!0)}resource(e,n,...r){let s;typeof r[0]=="object"&&(s=r.shift());const i=r[0];if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const o=this._createRegisteredResource(e,void 0,n,s,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const o=this._createRegisteredResourceTemplate(e,void 0,n,s,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}}registerResource(e,n,r,s){if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const i=this._createRegisteredResource(e,r.title,n,r,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const i=this._createRegisteredResourceTemplate(e,r.title,n,r,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}}_createRegisteredResource(e,n,r,s,i){const o={name:e,title:n,metadata:s,readCallback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({uri:null}),update:a=>{typeof a.uri<"u"&&a.uri!==r&&(delete this._registeredResources[r],a.uri&&(this._registeredResources[a.uri]=o)),typeof a.name<"u"&&(o.name=a.name),typeof a.title<"u"&&(o.title=a.title),typeof a.metadata<"u"&&(o.metadata=a.metadata),typeof a.callback<"u"&&(o.readCallback=a.callback),typeof a.enabled<"u"&&(o.enabled=a.enabled),this.sendResourceListChanged()}};return this._registeredResources[r]=o,o}_createRegisteredResourceTemplate(e,n,r,s,i){const o={resourceTemplate:r,title:n,metadata:s,readCallback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:u=>{typeof u.name<"u"&&u.name!==e&&(delete this._registeredResourceTemplates[e],u.name&&(this._registeredResourceTemplates[u.name]=o)),typeof u.title<"u"&&(o.title=u.title),typeof u.template<"u"&&(o.resourceTemplate=u.template),typeof u.metadata<"u"&&(o.metadata=u.metadata),typeof u.callback<"u"&&(o.readCallback=u.callback),typeof u.enabled<"u"&&(o.enabled=u.enabled),this.sendResourceListChanged()}};this._registeredResourceTemplates[e]=o;const a=r.uriTemplate.variableNames;return Array.isArray(a)&&a.some(u=>!!r.completeCallback(u))&&this.setCompletionRequestHandler(),o}_createRegisteredPrompt(e,n,r,s,i){const o={title:n,description:r,argsSchema:s===void 0?void 0:st(s),callback:i,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:a=>{typeof a.name<"u"&&a.name!==e&&(delete this._registeredPrompts[e],a.name&&(this._registeredPrompts[a.name]=o)),typeof a.title<"u"&&(o.title=a.title),typeof a.description<"u"&&(o.description=a.description),typeof a.argsSchema<"u"&&(o.argsSchema=st(a.argsSchema)),typeof a.callback<"u"&&(o.callback=a.callback),typeof a.enabled<"u"&&(o.enabled=a.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=o,s&&Object.values(s).some(c=>{var l;const u=c instanceof lo.ZodOptional?(l=c._def)==null?void 0:l.innerType:c;return vs(u)})&&this.setCompletionRequestHandler(),o}_createRegisteredTool(e,n,r,s,i,o,a,c,u){ws(e);const l={title:n,description:r,inputSchema:ks(s),outputSchema:ks(i),annotations:o,execution:a,_meta:c,handler:u,enabled:!0,disable:()=>l.update({enabled:!1}),enable:()=>l.update({enabled:!0}),remove:()=>l.update({name:null}),update:f=>{typeof f.name<"u"&&f.name!==e&&(typeof f.name=="string"&&ws(f.name),delete this._registeredTools[e],f.name&&(this._registeredTools[f.name]=l)),typeof f.title<"u"&&(l.title=f.title),typeof f.description<"u"&&(l.description=f.description),typeof f.paramsSchema<"u"&&(l.inputSchema=st(f.paramsSchema)),typeof f.outputSchema<"u"&&(l.outputSchema=st(f.outputSchema)),typeof f.callback<"u"&&(l.handler=f.callback),typeof f.annotations<"u"&&(l.annotations=f.annotations),typeof f._meta<"u"&&(l._meta=f._meta),typeof f.enabled<"u"&&(l.enabled=f.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=l,this.setToolRequestHandlers(),this.sendToolListChanged(),l}tool(e,...n){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,s,i,o;if(typeof n[0]=="string"&&(r=n.shift()),n.length>1){const c=n[0];Bn(c)?(s=n.shift(),n.length>1&&typeof n[0]=="object"&&n[0]!==null&&!Bn(n[0])&&(o=n.shift())):typeof c=="object"&&c!==null&&(o=n.shift())}const a=n[0];return this._createRegisteredTool(e,void 0,r,s,i,o,{taskSupport:"forbidden"},void 0,a)}registerTool(e,n,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{title:s,description:i,inputSchema:o,outputSchema:a,annotations:c,_meta:u}=n;return this._createRegisteredTool(e,s,i,o,a,c,{taskSupport:"forbidden"},u,r)}prompt(e,...n){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof n[0]=="string"&&(r=n.shift());let s;n.length>1&&(s=n.shift());const i=n[0],o=this._createRegisteredPrompt(e,void 0,r,s,i);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}registerPrompt(e,n,r){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);const{title:s,description:i,argsSchema:o}=n,a=this._createRegisteredPrompt(e,s,i,o,r);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(e,n){return this.server.sendLoggingMessage(e,n)}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const hm={type:"object",properties:{}};function io(t){return t!==null&&typeof t=="object"&&"parse"in t&&typeof t.parse=="function"&&"safeParse"in t&&typeof t.safeParse=="function"}function mm(t){return"_def"in t||"_zod"in t||io(t)}function Bn(t){return typeof t!="object"||t===null||mm(t)?!1:Object.keys(t).length===0?!0:Object.values(t).some(io)}function ks(t){if(t)return Bn(t)?st(t):t}function pm(t){const e=xt(t);return e?Object.entries(e).map(([n,r])=>{const s=ch(r),i=uh(r);return{name:n,description:s,required:!i}}):[]}function Le(t){const e=xt(t),n=e==null?void 0:e.method;if(!n)throw new Error("Schema is missing a method literal");const r=Gi(n);if(typeof r=="string")return r;throw new Error("Schema method literal must be a string")}function Ss(t){return{completion:{values:t.slice(0,100),total:t.length,hasMore:t.length>100}}}const _t={completion:{values:[],hasMore:!1}},Ts=fo.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:yn&&yn.tagName.toUpperCase()==="SCRIPT"&&yn.src||new URL("index.cjs",document.baseURI).href);let Wn;try{Wn=Ts("./package.json").version}catch{Wn=Ts("../package.json").version}function gm(){return new fm({name:"wordpress-playground",version:Wn,description:`Use this server when you need a live WordPress environment without any local setup. WordPress Playground runs entirely in the user's browser tab via WebAssembly — no PHP, MySQL, or server required. You are automatically authenticated as an admin user.
|
|
47
47
|
|
|
48
48
|
PREREQUISITE: Call playground_list_sites first. If no browser is connected, call playground_get_website_url to get the exact URL and ask the user to open it.
|
|
49
49
|
|
|
@@ -53,5 +53,5 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
53
53
|
|
|
54
54
|
Important: sites are temporary by default and not persisted between sessions. Call playground_save_in_browser early in any multi-step workflow where losing progress would be costly.
|
|
55
55
|
|
|
56
|
-
Error handling: tool failures are returned as thrown exceptions with descriptive messages, not as silent failures.`})}function yt(t,e){return{content:[{type:"text",text:`${t}: ${Qe.stringifyError(e)}`}],isError:!0}}const
|
|
56
|
+
Error handling: tool failures are returned as thrown exceptions with descriptive messages, not as silent failures.`})}function yt(t,e){return{content:[{type:"text",text:`${t}: ${Qe.stringifyError(e)}`}],isError:!0}}const Gn=wt().describe("Target site ID. Call playground_list_sites first to discover available site IDs.");function zs(t){const e={siteId:Gn};for(const n of t){let r;switch(n.type){case"string":r=wt();break;case"boolean":r=sh();break;case"object":r=ls(wt(),us());break;case"string_or_object":r=ih([wt(),ls(wt(),us())]);break;default:throw new Error(`Unknown param type "${n.type}" for "${n.name}"`)}n.required||(r=r.optional(),n.default!==void 0&&(r=r.default(n.default))),r=r.describe(n.description),e[n.name]=r}return e}function _m(t,e,n,r){const s=e.sendCommand.bind(e),i=Qe.getSiteToolDefinitions(),o=Qe.playgroundUrl(n,r),a=i.playground_list_sites;t.registerTool("playground_list_sites",{title:a.title,description:a.description,inputSchema:Vn({}),annotations:a.annotations},async()=>{const p=e.getTabCount(),m=e.listSites();return m.length===0?{content:[{type:"text",text:JSON.stringify({connectedTabs:p,sites:[],message:e.isConnected()?"No sites are loaded.":`No browser connected. Open the Playground website at ${o} to connect.`})}]}:{content:[{type:"text",text:JSON.stringify({connectedTabs:p,sites:m.map(v=>({siteId:v.siteId,name:v.name,storage:v.storage,isActive:v.isActive,url:o}))})}]}});const c=i.playground_open_site_in_new_tab;t.registerTool("playground_open_site_in_new_tab",{title:c.title,description:c.description,inputSchema:{siteId:Gn},annotations:c.annotations},async({siteId:p})=>{try{await e.sendCommand(p,"__open_site_in_new_tab");const m=await e.waitForSiteActive(p,3e4);return{content:[{type:"text",text:JSON.stringify({siteId:p,name:m.siteName,isActive:!0})}]}}catch(m){return yt(c.errorPrefix,m)}});const u=i.playground_rename_site;t.registerTool("playground_rename_site",{title:u.title,description:u.description,inputSchema:zs(u.params),annotations:u.annotations},async({siteId:p,newName:m})=>{try{return await e.sendCommand(p,"__rename_site",[m]),{content:[{type:"text",text:JSON.stringify({success:!0,siteId:p,newName:m})}]}}catch(v){return yt(u.errorPrefix,v)}});const l=i.playground_get_website_url;t.registerTool("playground_get_website_url",{title:l.title,description:l.description,inputSchema:Vn({}),annotations:l.annotations},async()=>({content:[{type:"text",text:JSON.stringify({url:o})}]}));const f=i.playground_save_in_browser;t.registerTool("playground_save_in_browser",{title:f.title,description:f.description,inputSchema:{siteId:Gn},annotations:f.annotations},async({siteId:p})=>{try{const v=e.listSites().find(x=>x.siteId===p);if(!v)return yt("Error saving site",new Error(`Unknown site: ${p}`));if(v.storage!=="temporary")return{content:[{type:"text",text:JSON.stringify({success:!0,alreadySaved:!0,siteId:p,name:v.name,storage:v.storage})}]};const T=await e.sendCommand(p,"__save_site");return{content:[{type:"text",text:JSON.stringify({success:!0,alreadySaved:!1,siteId:p,name:v.name,storage:Qe.formatStorageLabel(T.storage)})}]}}catch(m){return yt(f.errorPrefix,m)}});for(const[p,m]of Object.entries(Qe.toolDefinitions)){const v=Qe.toolExecutors[p];v&&t.registerTool(p,{title:m.title,description:m.description,inputSchema:zs(m.params),annotations:m.annotations},async T=>{const{siteId:x,...b}=T;try{const y=x,j=await v({run:(...L)=>s(y,"run",L),request:(...L)=>s(y,"request",L),goTo:(...L)=>s(y,"goTo",L),getCurrentURL:()=>s(y,"getCurrentURL",[]),readFileAsText:(...L)=>s(y,"readFileAsText",L),writeFile:(...L)=>s(y,"writeFile",L),listFiles:(...L)=>s(y,"listFiles",L),mkdirTree:(...L)=>s(y,"mkdirTree",L),unlink:(...L)=>s(y,"unlink",L),rmdir:(...L)=>s(y,"rmdir",L),fileExists:(...L)=>s(y,"fileExists",L)},b);return{content:[{type:"text",text:JSON.stringify(j)}]}}catch(y){return yt(m.errorPrefix,y)}})}}function ym(){const t=process.argv.find(e=>e.startsWith("--port="));return t?Number(t.split("=")[1]):0}function vm(){const t=process.argv.find(n=>n.startsWith("--url="));if(!t)return;const e=t.split("=").slice(1).join("=");try{return new URL(e)}catch{throw new Error(`Invalid --url: "${e}" must be an absolute URL.`)}}async function bm(){const t=vm(),e=new If(t?[t.href]:[]);await e.startWebSocketServer(ym());const n=e.getPort(),r=gm();_m(r,e,n,t==null?void 0:t.href);const s=new Nf;await r.connect(s),console.error("[MCP] WordPress Playground MCP server running on stdio")}bm().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
|
57
57
|
//# sourceMappingURL=index.cjs.map
|