tracks/node_modules/playwright/lib/mcpBundleImpl.js

42 lines
287 KiB
JavaScript
Raw Normal View History

"use strict";var md=Object.create;var Aa=Object.defineProperty;var vd=Object.getOwnPropertyDescriptor;var gd=Object.getOwnPropertyNames;var yd=Object.getPrototypeOf,_d=Object.prototype.hasOwnProperty;var z=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),xi=(a,e)=>{for(var t in e)Aa(a,t,{get:e[t],enumerable:!0})},Ei=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of gd(e))!_d.call(a,r)&&r!==t&&Aa(a,r,{get:()=>e[r],enumerable:!(s=vd(e,r))||s.enumerable});return a};var br=(a,e,t)=>(t=a!=null?md(yd(a)):{},Ei(e||!a||!a.__esModule?Aa(t,"default",{value:a,enumerable:!0}):t,a)),bd=a=>Ei(Aa({},"__esModule",{value:!0}),a);var Yi=z((Ba,Ki)=>{(function(a,e){typeof Ba=="object"&&typeof Ki!="undefined"?e(Ba):typeof define=="function"&&define.amd?define(["exports"],e):e(a.URI=a.URI||{})})(Ba,(function(a){"use strict";function e(){for(var _=arguments.length,p=Array(_),b=0;b<_;b++)p[b]=arguments[b];if(p.length>1){p[0]=p[0].slice(0,-1);for(var x=p.length-1,E=1;E<x;++E)p[E]=p[E].slice(1,-1);return p[x]=p[x].slice(1),p.join("")}else return p[0]}function t(_){return"(?:"+_+")"}function s(_){return _===void 0?"undefined":_===null?"null":Object.prototype.toString.call(_).split(" ").pop().split("]").shift().toLowerCase()}function r(_){return _.toUpperCase()}function n(_){return _!=null?_ instanceof Array?_:typeof _.length!="number"||_.split||_.setInterval||_.call?[_]:Array.prototype.slice.call(_):[]}function i(_,p){var b=_;if(p)for(var x in p)b[x]=p[x];return b}function o(_){var p="[A-Za-z]",b="[\\x0D]",x="[0-9]",E="[\\x22]",j=e(x,"[A-Fa-f]"),W="[\\x0A]",se="[\\x20]",le=t(t("%[EFef]"+j+"%"+j+j+"%"+j+j)+"|"+t("%[89A-Fa-f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|"+Pt+")")+t("\\?("+St+")")+"?$",Rv="^"+t("\\#("+Yt+")")+"?$",Ov="^"+t("("+ue+")@")+"?("+Wt+")"+t("\\:("+Gt+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",p,x,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e(
`;break;case"id":o=v.includes("\0")?void 0:v;break;case"retry":/^\d+$/.test(v)?s(parseInt(v,10)):t(new hs(`Invalid \`retry\` value: "${v}"`,{type:"invalid-retry",value:v,line:w}));break;default:t(new hs(`Unknown field "${m.length>20?`${m.slice(0,20)}\u2026`:m}"`,{type:"unknown-field",field:m,value:v,line:w}));break}}function d(){u.length>0&&e({id:o,event:c||void 0,data:u.endsWith(`
`)?u.slice(0,-1):u}),o=void 0,u="",c=""}function y(m={}){n&&m.consume&&f(n),i=!0,o=void 0,u="",c="",n=""}return{feed:h,reset:y}}function Gp(a){let e=[],t="",s=0;for(;s<a.length;){let r=a.indexOf("\r",s),n=a.indexOf(`
`,s),i=-1;if(r!==-1&&n!==-1?i=Math.min(r,n):r!==-1?i=r:n!==-1&&(i=n),i===-1){t=a.slice(s);break}else{let o=a.slice(s,i);e.push(o),s=i+1,a[s-1]==="\r"&&a[s]===`
`&&s++}}return[e,t]}var ms=class extends Event{constructor(e,t){var s,r;super(e),this.code=(s=t==null?void 0:t.code)!=null?s:void 0,this.message=(r=t==null?void 0:t.message)!=null?r:void 0}[Symbol.for("nodejs.util.inspect.custom")](e,t,s){return s(ec(this),t)}[Symbol.for("Deno.customInspect")](e,t){return e(ec(this),t)}};function Kp(a){let e=globalThis.DOMException;return typeof e=="function"?new e(a,"SyntaxError"):new SyntaxError(a)}function In(a){return a instanceof Error?"errors"in a&&Array.isArray(a.errors)?a.errors.map(In).join(", "):"cause"in a&&a.cause instanceof Error?`${a}: ${In(a.cause)}`:a.message:`${a}`}function ec(a){return{type:a.type,message:a.message,code:a.code,defaultPrevented:a.defaultPrevented,cancelable:a.cancelable,timeStamp:a.timeStamp}}var tc=a=>{throw TypeError(a)},Mn=(a,e,t)=>e.has(a)||tc("Cannot "+t),ee=(a,e,t)=>(Mn(a,e,"read from private field"),t?t.call(a):e.get(a)),Se=(a,e,t)=>e.has(a)?tc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(a):e.set(a,t),fe=(a,e,t,s)=>(Mn(a,e,"write to private field"),e.set(a,t),t),Or=(a,e,t)=>(Mn(a,e,"access private method"),t),Ve,pt,Mt,ps,vs,la,Ut,ca,Fr,Ft,zt,qt,ia,nr,An,$n,kn,rc,Dn,Nn,oa,jn,Ln,mt=class extends EventTarget{constructor(e,t){var s,r;super(),Se(this,nr),this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,Se(this,Ve),Se(this,pt),Se(this,Mt),Se(this,ps),Se(this,vs),Se(this,la),Se(this,Ut),Se(this,ca,null),Se(this,Fr),Se(this,Ft),Se(this,zt,null),Se(this,qt,null),Se(this,ia,null),Se(this,$n,async n=>{var i;ee(this,Ft).reset();let{body:o,redirected:u,status:c,headers:h}=n;if(c===204){Or(this,nr,oa).call(this,"Server sent HTTP 204, not reconnecting",204),this.close();return}if(u?fe(this,Mt,new URL(n.url)):fe(this,Mt,void 0),c!==200){Or(this,nr,oa).call(this,`Non-200 status code (${c})`,c);return}if(!(h.get("content-type")||"").startsWith("text/event-stream")){Or(this,nr,oa).call(this,'Invalid content type, expected "text/event-stream"',c);return}if(ee(this,Ve)===this.CLOSED)return;fe(this,Ve,this.OPEN);let f=new Event("open");if((i=ee(this,ia))==null||i.call(this,f),this.dispatchEvent(f),typeof o!="object"||!o||!("getReader"in o)){Or(this,nr,oa).call(this,"Invalid response body, expected a web ReadableStream",c),this.close();return}let g=new TextDecoder,d=o.getReader(),y=!0;do{let{done:m,value:v}=await d.read();v&&ee(this,Ft).feed(g.decode(v,{stream:!m})),m&&(y=!1,ee(this,Ft).reset(),Or(this,nr,jn).call(this))}while(y)}),Se(this,kn,n=>{fe(this,Fr,void 0),!(n.name==="AbortError"||n.type==="aborted")&&Or(this,nr,jn).call(this,In(n))}),Se(this,Dn,n=>{typeof n.id=="string"&&fe(this,ca,n.id);let i=new MessageEvent(n.event||"message",{data:n.data,origin:ee(this,Mt)?ee(this,Mt).origin:ee(this,pt).origin,lastEventId:n.id||""});ee(this,qt)&&(!n.event||n.event==="message")&&ee(this,qt).call(this,i),this.dispatchEvent(i)}),Se(this,Nn,n=>{fe(this,la,n)}),Se(this,Ln,()=>{fe(this,Ut,void 0),ee(this,Ve)===this.CONNECTING&&Or(this,nr,An).call(this)});try{if(e instanceof URL)fe(this,pt,e);else if(typeof e=="string")fe(this,pt,new URL(e,Yp()));else throw new Error("Invalid URL")}catch{throw Kp("An invalid or illegal string was specified")}fe(this,Ft,fs({onEvent:ee(this,Dn),onRetry:ee(this,Nn)})),fe(this,Ve,this.CONNECTING),fe(this,la,3e3),fe(this,vs,(s=t==null?void 0:t.fetch)!=null?s:globalThis.fetch),fe(this,ps,(r=t==null?void 0:t.withCredentials)!=null?r:!1),Or(this,nr,An).call(this)}get readyState(){return ee(this,Ve)}get url(){return ee(this,pt).href}get withCredentials(){return ee(this,ps)}get onerror(){return ee(this,zt)}set onerror(e){fe(this,zt,e)}get onmessage(){return ee(this,qt)}set onmessage(e){fe(this,qt,e)}get onopen(){return ee(this,ia)}set onopen(e){fe(this,ia,e)}addEventListener(e,t,s){let r=t;super.addEventListener(e,r,s)}removeEventListener(e,t,s){let r=t;super.removeEventListener(e,r,s)}close(){ee(this,Ut)&&clearTimeout(ee(this,Ut)),ee(this,Ve)!==this.CLOSED&&(ee(this,Fr)&&ee(this,Fr).abort(),fe(this,Ve,this.CLOSED),fe(this,Fr,void 0))}};Ve=new WeakMap,pt=new WeakMap,Mt=new WeakMap,ps=new WeakMap,vs=new WeakMap,la=new WeakMap
data: ${s}
`),this._sseResponse=this.res,this.res.on("close",()=>{var r;this._sseResponse=void 0,(r=this.onclose)===null||r===void 0||r.call(this)})}async handlePostMessage(e,t,s){var r,n,i,o;if(!this._sseResponse){let g="SSE connection not established";throw t.writeHead(500).end(g),new Error(g)}let u=this.validateRequestHeaders(e);if(u){t.writeHead(403).end(u),(r=this.onerror)===null||r===void 0||r.call(this,new Error(u));return}let c=e.auth,h={headers:e.headers},f;try{let g=Pc.default.parse((n=e.headers["content-type"])!==null&&n!==void 0?n:"");if(g.type!=="application/json")throw new Error(`Unsupported content-type: ${g.type}`);f=s!=null?s:await Ea(e,{limit:$m,encoding:(i=g.parameters.charset)!==null&&i!==void 0?i:"utf-8"})}catch(g){t.writeHead(400).end(String(g)),(o=this.onerror)===null||o===void 0||o.call(this,g);return}try{await this.handleMessage(typeof f=="string"?JSON.parse(f):f,{requestInfo:h,authInfo:c})}catch{t.writeHead(400).end(`Invalid message: ${f}`);return}t.writeHead(202).end("Accepted")}async handleMessage(e,t){var s,r;let n;try{n=Qe.parse(e)}catch(i){throw(s=this.onerror)===null||s===void 0||s.call(this,i),i}(r=this.onmessage)===null||r===void 0||r.call(this,n,t)}async close(){var e,t;(e=this._sseResponse)===null||e===void 0||e.end(),this._sseResponse=void 0,(t=this.onclose)===null||t===void 0||t.call(this)}async send(e){if(!this._sseResponse)throw new Error("Not connected");this._sseResponse.write(`event: message
data: ${JSON.stringify(e)}
`)}get sessionId(){return this._sessionId}};var pu=br(fu(),1),Pa=br(require("node:process"),1),mu=require("node:stream");var Zt=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
`);if(e===-1)return null;let t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),nv(t)}clear(){this._buffer=void 0}};function nv(a){return Qe.parse(JSON.parse(a))}function ws(a){return JSON.stringify(a)+`
`}var iv=Pa.default.platform==="win32"?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE","PROGRAMFILES"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"];function ov(){let a={};for(let e of iv){let t=Pa.default.env[e];t!==void 0&&(t.startsWith("()")||(a[e]=t))}return a}var xs=class{constructor(e){this._abortController=new AbortController,this._readBuffer=new Zt,this._stderrStream=null,this._serverParams=e,(e.stderr==="pipe"||e.stderr==="overlapped")&&(this._stderrStream=new mu.PassThrough)}async start(){if(this._process)throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((e,t)=>{var s,r,n,i,o;this._process=(0,pu.default)(this._serverParams.command,(s=this._serverParams.args)!==null&&s!==void 0?s:[],{env:{...ov(),...this._serverParams.env},stdio:["pipe","pipe",(r=this._serverParams.stderr)!==null&&r!==void 0?r:"inherit"],shell:!1,signal:this._abortController.signal,windowsHide:Pa.default.platform==="win32"&&lv(),cwd:this._serverParams.cwd}),this._process.on("error",u=>{var c,h;if(u.name==="AbortError"){(c=this.onclose)===null||c===void 0||c.call(this);return}t(u),(h=this.onerror)===null||h===void 0||h.call(this,u)}),this._process.on("spawn",()=>{e()}),this._process.on("close",u=>{var c;this._process=void 0,(c=this.onclose)===null||c===void 0||c.call(this)}),(n=this._process.stdin)===null||n===void 0||n.on("error",u=>{var c;(c=this.onerror)===null||c===void 0||c.call(this,u)}),(i=this._process.stdout)===null||i===void 0||i.on("data",u=>{this._readBuffer.append(u),this.processReadBuffer()}),(o=this._process.stdout)===null||o===void 0||o.on("error",u=>{var c;(c=this.onerror)===null||c===void 0||c.call(this,u)}),this._stderrStream&&this._process.stderr&&this._process.stderr.pipe(this._stderrStream)})}get stderr(){var e,t;return this._stderrStream?this._stderrStream:(t=(e=this._process)===null||e===void 0?void 0:e.stderr)!==null&&t!==void 0?t:null}get pid(){var e,t;return(t=(e=this._process)===null||e===void 0?void 0:e.pid)!==null&&t!==void 0?t:null}processReadBuffer(){for(var e,t;;)try{let s=this._readBuffer.readMessage();if(s===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,s)}catch(s){(t=this.onerror)===null||t===void 0||t.call(this,s)}}async close(){this._abortController.abort(),this._process=void 0,this._readBuffer.clear()}send(e){return new Promise(t=>{var s;if(!(!((s=this._process)===null||s===void 0)&&s.stdin))throw new Error("Not connected");let r=ws(e);this._process.stdin.write(r)?t():this._process.stdin.once("drain",t)})}};function lv(){return"type"in Pa.default}var si=br(require("node:process"),1);var Es=class{constructor(e=si.default.stdin,t=si.default.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new Zt,this._started=!1,this._ondata=s=>{this._readBuffer.append(s),this.processReadBuffer()},this._onerror=s=>{var r;(r=this.onerror)===null||r===void 0||r.call(this,s)}}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(){for(var e,t;;)try{let s=this._readBuffer.readMessage();if(s===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,s)}catch(s){(t=this.onerror)===null||t===void 0||t.call(this,s)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(e=this.onclose)===null||e===void 0||e.call(this)}send(e){return new Promise(t=>{let s=ws(e);this._stdout.write(s)?t():this._stdout.once("drain",t)})}};var vu=br(Qn(),1),gu=require("node:crypto"),cv="4mb",Ps=class{constructor(e){var t,s;this._started=!1,this._streamMapping=new Map,this._requestToStreamMapping=new Map,this._requestResponseMap=new Map,this._initialized=!1,this._enableJsonResponse=!1,this._standaloneSseStre
`;return s&&(r+=`id: ${s}
`),r+=`data: ${JSON.stringify(t)}
`,e.write(r)}async handleUnsupportedRequest(e){e.writeHead(405,{Allow:"GET, POST, DELETE"}).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))}async handlePostRequest(e,t,s){var r,n,i,o,u;try{let c=e.headers.accept;if(!(c!=null&&c.includes("application/json"))||!c.includes("text/event-stream")){t.writeHead(406).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Not Acceptable: Client must accept both application/json and text/event-stream"},id:null}));return}let h=e.headers["content-type"];if(!h||!h.includes("application/json")){t.writeHead(415).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Unsupported Media Type: Content-Type must be application/json"},id:null}));return}let f=e.auth,g={headers:e.headers},d;if(s!==void 0)d=s;else{let w=vu.default.parse(h),S=await Ea(e,{limit:cv,encoding:(r=w.parameters.charset)!==null&&r!==void 0?r:"utf-8"});d=JSON.parse(S.toString())}let y;Array.isArray(d)?y=d.map(w=>Qe.parse(w)):y=[Qe.parse(d)];let m=y.some(Hi);if(m){if(this._initialized&&this.sessionId!==void 0){t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request: Server already initialized"},id:null}));return}if(y.length>1){t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request: Only one initialization request is allowed"},id:null}));return}this.sessionId=(n=this.sessionIdGenerator)===null||n===void 0?void 0:n.call(this),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!m&&(!this.validateSession(e,t)||!this.validateProtocolVersion(e,t)))return;let v=y.some(dt);if(v){if(v){let w=(0,gu.randomUUID)();if(!this._enableJsonResponse){let S={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};this.sessionId!==void 0&&(S["mcp-session-id"]=this.sessionId),t.writeHead(200,S)}for(let S of y)dt(S)&&(this._streamMapping.set(w,t),this._requestToStreamMapping.set(S.id,w));t.on("close",()=>{this._streamMapping.delete(w)});for(let S of y)(o=this.onmessage)===null||o===void 0||o.call(this,S,{authInfo:f,requestInfo:g})}}else{t.writeHead(202).end();for(let w of y)(i=this.onmessage)===null||i===void 0||i.call(this,w,{authInfo:f,requestInfo:g})}}catch(c){t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32700,message:"Parse error",data:String(c)},id:null})),(u=this.onerror)===null||u===void 0||u.call(this,c)}}async handleDeleteRequest(e,t){var s;this.validateSession(e,t)&&this.validateProtocolVersion(e,t)&&(await Promise.resolve((s=this._onsessionclosed)===null||s===void 0?void 0:s.call(this,this.sessionId)),await this.close(),t.writeHead(200).end())}validateSession(e,t){if(this.sessionIdGenerator===void 0)return!0;if(!this._initialized)return t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: Server not initialized"},id:null})),!1;let s=e.headers["mcp-session-id"];if(s){if(Array.isArray(s))return t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: Mcp-Session-Id header must be a single value"},id:null})),!1;if(s!==this.sessionId)return t.writeHead(404).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32001,message:"Session not found"},id:null})),!1}else return t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: Mcp-Session-Id header is required"},id:null})),!1;return!0}validateProtocolVersion(e,t){var s;let r=(s=e.headers["mcp-protocol-version"])!==null&&s!==void 0?s:Ni;return Array.isArray(r)&&(r=r[r.length-1]),ut.includes(r)?!0:(t.writeHead(400).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:`Bad Request: Unsupported protocol version (supported versions: ${ut.join(", ")})`},id:null})),!1)}async close(){var e;this._streamMapping.forEach(t=>{t.end()}),this._streamMapping.clear(),this._requestResponseMap.clear(),(e=this.onclose)===null||e===void 0||e.call(this)}async send(e,t){let s=t==null?void 0:t.relatedRequestId;if((Sr(e)||Dt(e))&&(s=e.id),s===v
]))`;continue}else if(s[c]==="$"){r+=`($|(?=[\r
]))`;continue}}if(t.s&&s[c]==="."){r+=i?`${s[c]}\r
`:`[${s[c]}\r
]`;continue}r+=s[c],s[c]==="\\"?n=!0:i&&s[c]==="]"?i=!1:!i&&s[c]==="["&&(i=!0)}try{new RegExp(r)}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`),a.source}return r}function Is(a,e){var s,r,n,i,o,u,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"&&((s=a.keyType)==null?void 0:s._def.typeName)===T.ZodEnum)return{type:"object",required:a.keyType._def.values,properties:a.keyType._def.values.reduce((h,f)=>{var g;return{...h,[f]:(g=J(a.valueType._def,{...e,currentPath:[...e.currentPath,"properties",f]}))!=null?g:pe(e)}},{}),additionalProperties:e.rejectedAdditionalProperties};let t={type:"object",additionalProperties:(r=J(a.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]}))!=null?r:e.allowedAdditionalProperties};if(e.target==="openApi3")return t;if(((n=a.keyType)==null?void 0:n._def.typeName)===T.ZodString&&((i=a.keyType._def.checks)!=null&&i.length)){let{type:h,...f}=Cs(a.keyType._def,e);return{...t,propertyNames:f}}else{if(((o=a.keyType)==null?void 0:o._def.typeName)===T.ZodEnum)return{...t,propertyNames:{enum:a.keyType._def.values}};if(((u=a.keyType)==null?void 0:u._def.typeName)===T.ZodBranded&&a.keyType._def.type._def.typeName===T.ZodString&&((c=a.keyType._def.type._def.checks)!=null&&c.length)){let{type:h,...f}=Ts(a.keyType._def,e);return{...t,propertyNames:f}}}return t}function $u(a,e){if(e.mapStrategy==="record")return Is(a,e);let t=J(a.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||pe(e),s=J(a.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||pe(e);return{type:"array",maxItems:125,items:{type:"array",items:[t,s],minItems:2,maxItems:2}}}function ku(a){let e=a.values,s=Object.keys(a.values).filter(n=>typeof e[e[n]]!="number").map(n=>e[n]),r=Array.from(new Set(s.map(n=>typeof n)));return{type:r.length===1?r[0]==="string"?"string":"number":["string","number"],enum:s}}function Du(a){return a.target==="openAi"?void 0:{not:pe({...a,currentPath:[...a.currentPath,"not"]})}}function Nu(a){return a.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var Ra={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Lu(a,e){if(e.target==="openApi3")return ju(a,e);let t=a.options instanceof Map?Array.from(a.options.values()):a.options;if(t.every(s=>s._def.typeName in Ra&&(!s._def.checks||!s._def.checks.length))){let s=t.reduce((r,n)=>{let i=Ra[n._def.typeName];return i&&!r.includes(i)?[...r,i]:r},[]);return{type:s.length>1?s:s[0]}}else if(t.every(s=>s._def.typeName==="ZodLiteral"&&!s.description)){let s=t.reduce((r,n)=>{let i=typeof n._def.value;switch(i){case"string":case"number":case"boolean":return[...r,i];case"bigint":return[...r,"integer"];case"object":if(n._def.value===null)return[...r,"null"];case"symbol":case"undefined":case"function":default:return r}},[]);if(s.length===t.length){let r=s.filter((n,i,o)=>o.indexOf(n)===i);return{type:r.length>1?r:r[0],enum:t.reduce((n,i)=>n.includes(i._def.value)?n:[...n,i._def.value],[])}}}else if(t.every(s=>s._def.typeName==="ZodEnum"))return{type:"string",enum:t.reduce((s,r)=>[...s,...r._def.values.filter(n=>!s.includes(n))],[])};return ju(a,e)}var ju=(a,e)=>{let t=(a.options instanceof Map?Array.from(a.options.values()):a.options).map((s,r)=>J(s._def,{...e,currentPath:[...e.currentPath,"anyOf",`${r}`]})).filter(s=>!!s&&(!e.strictUnions||typeof s=="object"&&Object.keys(s).length>0));return t.length?{anyOf:t}:void 0};function Mu(a,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(a.innerType._def.typeName)&&(!a.innerType._def.checks||!a.innerType._def.checks.length))return e.target==="openApi3"?{type:Ra[a.innerType._def.typeName],nullable:!0}:{type:[Ra[a.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let s=J(a.innerType._def,{...e,currentPath:[...e.currentPath]});return s&&"$ref"in s?{allOf:[s],nullable:
/*! Bundled license information:
uri-js/dist/es5/uri.all.js:
(** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js *)
bytes/index.js:
(*!
* bytes
* Copyright(c) 2012-2014 TJ Holowaychuk
* Copyright(c) 2015 Jed Watson
* MIT Licensed
*)
content-type/index.js:
(*!
* content-type
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*)
*/