@mongodb-js/compass-web 0.36.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/157.ab4998e7eb2874601f10.mjs +2 -0
- package/dist/{566.513352a4be9e2a46530b.mjs → 183.652977da27df0eb51f2b.mjs} +3 -3
- package/dist/187.761186d8e743ea68ec17.mjs +2 -0
- package/dist/{20.f2c2353886886939e128.mjs.LICENSE.txt → 187.761186d8e743ea68ec17.mjs.LICENSE.txt} +6 -0
- package/dist/503.edf8a9c8de8551ffb233.mjs +378 -0
- package/dist/811.caf23f67d965d1c56224.mjs +1 -0
- package/dist/819.a2cb944a78e8da07819a.mjs +2 -0
- package/dist/832.e3ec48107659934f74e7.mjs +2 -0
- package/dist/941.489a74e5b1130ccb5673.mjs +2 -0
- package/dist/957.77fd779cd858963de4c6.mjs +1 -0
- package/dist/965.521bb6d90f74d9a364b7.mjs +1 -0
- package/dist/assets-manifest.json +11 -11
- package/dist/compass-web.mjs +9 -9
- package/dist/index-bde52cb3.dcb93bf5aae17031a20c.mjs +1 -0
- package/package.json +39 -38
- package/dist/149.abccc0e903c0f5ea7354.mjs +0 -372
- package/dist/20.f2c2353886886939e128.mjs +0 -2
- package/dist/207.d69541eff41412663f35.mjs +0 -2
- package/dist/563.mjs +0 -1
- package/dist/68.f1ca0ed16b5fa27e2cf1.mjs +0 -1
- package/dist/69.mjs +0 -1
- package/dist/724.8aae14d079e334751961.mjs +0 -8
- package/dist/724.8aae14d079e334751961.mjs.LICENSE.txt +0 -5
- package/dist/737.mjs +0 -1
- package/dist/745.mjs +0 -1
- package/dist/832.a6fb147f7fd965a7f30c.mjs +0 -2
- package/dist/938.e127bbcdd0ce0eab8722.mjs +0 -2
- package/dist/965.3c1bdf715c3551cfe1ba.mjs +0 -1
- package/dist/995.c3bb8ac49cdffa0211da.mjs +0 -2
- package/dist/index-bde52cb3.a964d5743a224d2efb82.mjs +0 -1
- /package/dist/{995.c3bb8ac49cdffa0211da.mjs.LICENSE.txt → 157.ab4998e7eb2874601f10.mjs.LICENSE.txt} +0 -0
- /package/dist/{566.513352a4be9e2a46530b.mjs.LICENSE.txt → 183.652977da27df0eb51f2b.mjs.LICENSE.txt} +0 -0
- /package/dist/{149.abccc0e903c0f5ea7354.mjs.LICENSE.txt → 503.edf8a9c8de8551ffb233.mjs.LICENSE.txt} +0 -0
- /package/dist/{207.d69541eff41412663f35.mjs.LICENSE.txt → 819.a2cb944a78e8da07819a.mjs.LICENSE.txt} +0 -0
- /package/dist/{832.a6fb147f7fd965a7f30c.mjs.LICENSE.txt → 832.e3ec48107659934f74e7.mjs.LICENSE.txt} +0 -0
- /package/dist/{938.e127bbcdd0ce0eab8722.mjs.LICENSE.txt → 941.489a74e5b1130ccb5673.mjs.LICENSE.txt} +0 -0
package/dist/69.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const __webpack_esm_id__=69;export const __webpack_esm_ids__=[69];export const __webpack_esm_modules__={72176:()=>{},83069:(e,t,r)=>{r.d(t,{StreamableHTTPServerTransport:()=>k});var s=r(72176),n=r(93874),o=r(27348),a=r(67787).Buffer,i=r(9606).URL,c=class extends Error{constructor(e,t){super(e,t),this.name="RequestError"}},d=global.Request,l=class extends d{constructor(e,t){"object"==typeof e&&u in e&&(e=e[u]()),void 0!==t?.body?.getReader&&(t.duplex??="half"),super(e,t)}},h=Symbol("wrapBodyStream"),u=Symbol("getRequestCache"),p=Symbol("requestCache"),f=Symbol("incomingKey"),m=Symbol("urlKey"),y=Symbol("headersKey"),S=Symbol("abortControllerKey"),w=Symbol("getAbortController"),g={get method(){return this[f].method||"GET"},get url(){return this[m]},get headers(){return this[y]||=(e=>{const t=[],r=e.rawHeaders;for(let e=0;e<r.length;e+=2){const{[e]:s,[e+1]:n}=r;58!==s.charCodeAt(0)&&t.push([s,n])}return new Headers(t)})(this[f])},[w](){return this[u](),this[S]},[u](){return this[S]||=new AbortController,this[p]||=((e,t,r,s,o)=>{const i={method:e,headers:r,signal:o.signal};if("TRACE"===e){i.method="GET";const e=new l(t,i);return Object.defineProperty(e,"method",{get:()=>"TRACE"}),e}if("GET"!==e&&"HEAD"!==e)if("rawBody"in s&&s.rawBody instanceof a)i.body=new ReadableStream({start(e){e.enqueue(s.rawBody),e.close()}});else if(s[h]){let e;i.body=new ReadableStream({async pull(t){try{e||=n.Readable.toWeb(s).getReader();const{done:r,value:o}=await e.read();r?t.close():t.enqueue(o)}catch(e){t.error(e)}}})}else i.body=n.Readable.toWeb(s);return new l(t,i)})(this.method,this[m],this.headers,this[f],this[S])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach((e=>{Object.defineProperty(g,e,{get(){return this[u]()[e]}})})),["arrayBuffer","blob","clone","formData","json","text"].forEach((e=>{Object.defineProperty(g,e,{value:function(){return this[u]()[e]()}})})),Object.setPrototypeOf(g,l.prototype);var v=Symbol("responseCache"),_=Symbol("getResponseCache"),b=Symbol("cache"),E=global.Response,R=class e{#e;#t;[_](){return delete this[b],this[v]||=new E(this.#e,this.#t)}constructor(t,r){let s;if(this.#e=t,r instanceof e){const e=r[v];if(e)return this.#t=e,void this[_]();this.#t=r.#t,s=new Headers(r.#t.headers)}else this.#t=r;("string"==typeof t||void 0!==t?.getReader||t instanceof Blob||t instanceof Uint8Array)&&(this[b]=[r?.status||200,t,s||r?.headers])}get headers(){const e=this[b];return e?(e[2]instanceof Headers||(e[2]=new Headers(e[2]||{"content-type":"text/plain; charset=UTF-8"})),e[2]):this[_]().headers}get status(){return this[b]?.[0]??this[_]().status}get ok(){const e=this.status;return e>=200&&e<300}};async function I(e){return Promise.race([e,Promise.resolve().then((()=>Promise.resolve(void 0)))])}function T(e,t,r){const s=t=>{e.cancel(t).catch((()=>{}))};return t.on("close",s),t.on("error",s),(r??e.read()).then(a,n),e.closed.finally((()=>{t.off("close",s),t.off("error",s)}));function n(e){e&&t.destroy(e)}function o(){e.read().then(a,n)}function a({done:r,value:s}){try{if(r)t.end();else{if(t.write(s))return e.read().then(a,n);t.once("drain",o)}}catch(e){n(e)}}}["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach((e=>{Object.defineProperty(R.prototype,e,{get(){return this[_]()[e]}})})),["arrayBuffer","blob","clone","formData","json","text"].forEach((e=>{Object.defineProperty(R.prototype,e,{value:function(){return this[_]()[e]()}})})),Object.setPrototypeOf(R,E),Object.setPrototypeOf(R.prototype,E.prototype);var q=e=>{const t={};e instanceof Headers||(e=new Headers(e??void 0));const r=[];for(const[s,n]of e)"set-cookie"===s?r.push(n):t[s]=n;return r.length>0&&(t["set-cookie"]=r),t["content-type"]??="text/plain; charset=UTF-8",t};void 0===global.crypto&&(global.crypto=o);var C=Symbol("outgoingEnded"),M=Symbol("incomingDraining"),O=e=>{const t=e;if(e.destroyed||t[M])return;if(t[M]=!0,e instanceof s.Http2ServerRequest){try{e.stream?.close?.(s.constants.NGHTTP2_NO_ERROR)}catch{}return}let r=0;const n=()=>{clearTimeout(a),e.off("data",i),e.off("end",n),e.off("error",n)},o=()=>{n();const t=e.socket;t&&!t.destroyed&&t.destroySoon()},a=setTimeout(o,500);a.unref?.();const i=e=>{r+=e.length,r>67108864&&o()};e.on("data",i),e.on("end",n),e.on("error",n),e.resume()},P=e=>new Response(null,{status:e instanceof Error&&("TimeoutError"===e.name||"TimeoutError"===e.constructor.name)?504:500}),H=(e,t)=>{const r=e instanceof Error?e:new Error("unknown error",{cause:e});"ERR_STREAM_PREMATURE_CLOSE"===r.code?console.info("The user aborted a request."):(console.error(e),t.headersSent||t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Error: ${r.message}`),t.destroy(r))},J=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},j=async(e,t)=>{let[r,s,n]=e[b],o=!1;if(n){if(n instanceof Headers)o=n.has("content-length"),n=q(n);else if(Array.isArray(n)){const e=new Headers(n);o=e.has("content-length"),n=q(e)}else for(const e in n)if(14===e.length&&"content-length"===e.toLowerCase()){o=!0;break}}else n={"content-type":"text/plain; charset=UTF-8"};o||("string"==typeof s?n["Content-Length"]=a.byteLength(s):s instanceof Uint8Array?n["Content-Length"]=s.byteLength:s instanceof Blob&&(n["Content-Length"]=s.size)),t.writeHead(r,n),"string"==typeof s||s instanceof Uint8Array?t.end(s):s instanceof Blob?t.end(new Uint8Array(await s.arrayBuffer())):(J(t),await(function(e,t){if(e.locked)throw new TypeError("ReadableStream is locked.");if(!t.destroyed)return T(e.getReader(),t)}(s,t)?.catch((e=>H(e,t))))),t[C]?.()},x=(e,t={})=>{const r=t.autoCleanupIncoming??!0;return!1!==t.overrideGlobalObjects&&global.Request!==l&&(Object.defineProperty(global,"Request",{value:l}),Object.defineProperty(global,"Response",{value:R})),async(n,o)=>{let a,d;try{d=((e,t)=>{const r=Object.create(g);r[f]=e;const n=e.url||"";if("/"!==n[0]&&(n.startsWith("http://")||n.startsWith("https://"))){if(e instanceof s.Http2ServerRequest)throw new c("Absolute URL for :path is not allowed in HTTP/2");try{const e=new i(n);r[m]=e.href}catch(e){throw new c("Invalid absolute URL",{cause:e})}return r}const o=(e instanceof s.Http2ServerRequest?e.authority:e.headers.host)||t;if(!o)throw new c("Missing host header");let a;if(e instanceof s.Http2ServerRequest){if(a=e.scheme,"http"!==a&&"https"!==a)throw new c("Unsupported scheme")}else a=e.socket&&e.socket.encrypted?"https":"http";const d=new i(`${a}://${o}${n}`);if(d.hostname.length!==o.length&&d.hostname!==o.replace(/:\d+$/,""))throw new c("Invalid host header");return r[m]=d.href,r})(n,t.hostname);let l=!r||"GET"===n.method||"HEAD"===n.method;if(l||(n[h]=!0,n.on("end",(()=>{l=!0})),n instanceof s.Http2ServerRequest&&(o[C]=()=>{l||setTimeout((()=>{l||setTimeout((()=>{O(n)}))}))}),o.on("finish",(()=>{l||O(n)}))),o.on("close",(()=>{d[S]&&(n.errored?d[S].abort(n.errored.toString()):o.writableFinished||d[S].abort("Client connection prematurely closed.")),l||setTimeout((()=>{l||setTimeout((()=>{O(n)}))}))})),a=e(d,{incoming:n,outgoing:o}),b in a)return j(a,o)}catch(e){if(a)return H(e,o);if(t.errorHandler){if(a=await t.errorHandler(d?e:(e=>e instanceof c?e:new c(e.message,{cause:e}))(e)),!a)return}else a=d?P(e):new Response(null,{status:400})}try{return await(async(e,t,r={})=>{if((e=>"function"==typeof e.then)(e))if(r.errorHandler)try{e=await e}catch(t){const s=await r.errorHandler(t);if(!s)return;e=s}else e=await e.catch(P);if(b in e)return j(e,t);const s=q(e.headers);if(e.body){const r=e.body.getReader(),n=[];let o,a=!1;if("chunked"!==s["transfer-encoding"]){let e=2;for(let t=0;t<e;t++){o||=r.read();const s=await I(o).catch((e=>{console.error(e),a=!0}));if(!s){if(1===t){await new Promise((e=>setTimeout(e))),e=3;continue}break}if(o=void 0,s.value&&n.push(s.value),s.done){a=!0;break}}a&&!("content-length"in s)&&(s["content-length"]=n.reduce(((e,t)=>e+t.length),0))}t.writeHead(e.status,s),n.forEach((e=>{t.write(e)})),a?t.end():(0===n.length&&J(t),await T(r,t,o))}else s["x-hono-already-sent"]||(t.writeHead(e.status,s),t.end());t[C]?.()})(a,o,t)}catch(e){return H(e,o)}}},A=r(63648),U=r(9606).URL;class B{constructor(e={}){this._started=!1,this._hasHandledRequest=!1,this._streamMapping=new Map,this._requestToStreamMapping=new Map,this._requestResponseMap=new Map,this._initialized=!1,this._enableJsonResponse=!1,this._standaloneSseStreamId="_GET_stream",this.sessionIdGenerator=e.sessionIdGenerator,this._enableJsonResponse=e.enableJsonResponse??!1,this._eventStore=e.eventStore,this._onsessioninitialized=e.onsessioninitialized,this._onsessionclosed=e.onsessionclosed,this._allowedHosts=e.allowedHosts,this._allowedOrigins=e.allowedOrigins,this._enableDnsRebindingProtection=e.enableDnsRebindingProtection??!1,this._retryInterval=e.retryInterval}async start(){if(this._started)throw new Error("Transport already started");this._started=!0}createJsonErrorResponse(e,t,r,s){const n={code:t,message:r};return void 0!==s?.data&&(n.data=s.data),new Response(JSON.stringify({jsonrpc:"2.0",error:n,id:null}),{status:e,headers:{"Content-Type":"application/json",...s?.headers}})}validateRequestHeaders(e){if(this._enableDnsRebindingProtection){if(this._allowedHosts&&this._allowedHosts.length>0){const t=e.headers.get("host");if(!t||!this._allowedHosts.includes(t)){const e=`Invalid Host header: ${t}`;return this.onerror?.(new Error(e)),this.createJsonErrorResponse(403,-32e3,e)}}if(this._allowedOrigins&&this._allowedOrigins.length>0){const t=e.headers.get("origin");if(t&&!this._allowedOrigins.includes(t)){const e=`Invalid Origin header: ${t}`;return this.onerror?.(new Error(e)),this.createJsonErrorResponse(403,-32e3,e)}}}}async handleRequest(e,t){if(!this.sessionIdGenerator&&this._hasHandledRequest)throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");this._hasHandledRequest=!0;const r=this.validateRequestHeaders(e);if(r)return r;switch(e.method){case"POST":return this.handlePostRequest(e,t);case"GET":return this.handleGetRequest(e);case"DELETE":return this.handleDeleteRequest(e);default:return this.handleUnsupportedRequest()}}async writePrimingEvent(e,t,r,s){if(!this._eventStore)return;if(s<"2025-11-25")return;const n=await this._eventStore.storeEvent(r,{});let o=`id: ${n}\ndata: \n\n`;void 0!==this._retryInterval&&(o=`id: ${n}\nretry: ${this._retryInterval}\ndata: \n\n`),e.enqueue(t.encode(o))}async handleGetRequest(e){const t=e.headers.get("accept");if(!t?.includes("text/event-stream"))return this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept text/event-stream");const r=this.validateSession(e);if(r)return r;const s=this.validateProtocolVersion(e);if(s)return s;if(this._eventStore){const t=e.headers.get("last-event-id");if(t)return this.replayEvents(t)}if(void 0!==this._streamMapping.get(this._standaloneSseStreamId))return this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session")),this.createJsonErrorResponse(409,-32e3,"Conflict: Only one SSE stream is allowed per session");const n=new TextEncoder;let o;const a=new ReadableStream({start:e=>{o=e},cancel:()=>{this._streamMapping.delete(this._standaloneSseStreamId)}}),i={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive"};return void 0!==this.sessionId&&(i["mcp-session-id"]=this.sessionId),this._streamMapping.set(this._standaloneSseStreamId,{controller:o,encoder:n,cleanup:()=>{this._streamMapping.delete(this._standaloneSseStreamId);try{o.close()}catch{}}}),new Response(a,{headers:i})}async replayEvents(e){if(!this._eventStore)return this.onerror?.(new Error("Event store not configured")),this.createJsonErrorResponse(400,-32e3,"Event store not configured");try{let t;if(this._eventStore.getStreamIdForEventId){if(t=await this._eventStore.getStreamIdForEventId(e),!t)return this.onerror?.(new Error("Invalid event ID format")),this.createJsonErrorResponse(400,-32e3,"Invalid event ID format");if(void 0!==this._streamMapping.get(t))return this.onerror?.(new Error("Conflict: Stream already has an active connection")),this.createJsonErrorResponse(409,-32e3,"Conflict: Stream already has an active connection")}const r={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform",Connection:"keep-alive"};void 0!==this.sessionId&&(r["mcp-session-id"]=this.sessionId);const s=new TextEncoder;let n;const o=new ReadableStream({start:e=>{n=e},cancel:()=>{}}),a=await this._eventStore.replayEventsAfter(e,{send:async(e,t)=>{if(!this.writeSSEEvent(n,s,t,e)){this.onerror?.(new Error("Failed replay events"));try{n.close()}catch{}}}});return this._streamMapping.set(a,{controller:n,encoder:s,cleanup:()=>{this._streamMapping.delete(a);try{n.close()}catch{}}}),new Response(o,{headers:r})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(500,-32e3,"Error replaying events")}}writeSSEEvent(e,t,r,s){try{let n="event: message\n";return s&&(n+=`id: ${s}\n`),n+=`data: ${JSON.stringify(r)}\n\n`,e.enqueue(t.encode(n)),!0}catch(e){return this.onerror?.(e),!1}}handleUnsupportedRequest(){return this.onerror?.(new Error("Method not allowed.")),new Response(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}),{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(e,t){try{const r=e.headers.get("accept");if(!r?.includes("application/json")||!r.includes("text/event-stream"))return this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");const s=e.headers.get("content-type");if(!s||!s.includes("application/json"))return this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");const n={headers:Object.fromEntries(e.headers.entries()),url:new U(e.url)};let o,a;if(void 0!==t?.parsedBody)o=t.parsedBody;else try{o=await e.json()}catch{return this.onerror?.(new Error("Parse error: Invalid JSON")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}try{a=Array.isArray(o)?o.map((e=>A.OR.parse(e))):[A.OR.parse(o)]}catch{return this.onerror?.(new Error("Parse error: Invalid JSON-RPC message")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}const i=a.some(A.eK);if(i){if(this._initialized&&void 0!==this.sessionId)return this.onerror?.(new Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(a.length>1)return this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!i){const t=this.validateSession(e);if(t)return t;const r=this.validateProtocolVersion(e);if(r)return r}if(!a.some(A.vo)){for(const e of a)this.onmessage?.(e,{authInfo:t?.authInfo,requestInfo:n});return new Response(null,{status:202})}const c=crypto.randomUUID(),d=a.find((e=>(0,A.eK)(e))),l=d?d.params.protocolVersion:e.headers.get("mcp-protocol-version")??A.PC;if(this._enableJsonResponse)return new Promise((e=>{this._streamMapping.set(c,{resolveJson:e,cleanup:()=>{this._streamMapping.delete(c)}});for(const e of a)(0,A.vo)(e)&&this._requestToStreamMapping.set(e.id,c);for(const e of a)this.onmessage?.(e,{authInfo:t?.authInfo,requestInfo:n})}));const h=new TextEncoder;let u;const p=new ReadableStream({start:e=>{u=e},cancel:()=>{this._streamMapping.delete(c)}}),f={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};void 0!==this.sessionId&&(f["mcp-session-id"]=this.sessionId);for(const e of a)(0,A.vo)(e)&&(this._streamMapping.set(c,{controller:u,encoder:h,cleanup:()=>{this._streamMapping.delete(c);try{u.close()}catch{}}}),this._requestToStreamMapping.set(e.id,c));await this.writePrimingEvent(u,h,c,l);for(const e of a){let r,s;(0,A.vo)(e)&&this._eventStore&&l>="2025-11-25"&&(r=()=>{this.closeSSEStream(e.id)},s=()=>{this.closeStandaloneSSEStream()}),this.onmessage?.(e,{authInfo:t?.authInfo,requestInfo:n,closeSSEStream:r,closeStandaloneSSEStream:s})}return new Response(p,{status:200,headers:f})}catch(e){return this.onerror?.(e),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(e)})}}async handleDeleteRequest(e){const t=this.validateSession(e);if(t)return t;return this.validateProtocolVersion(e)||(await Promise.resolve(this._onsessionclosed?.(this.sessionId)),await this.close(),new Response(null,{status:200}))}validateSession(e){if(void 0===this.sessionIdGenerator)return;if(!this._initialized)return this.onerror?.(new Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");const t=e.headers.get("mcp-session-id");return t?t!==this.sessionId?(this.onerror?.(new Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")):void 0:(this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required"))}validateProtocolVersion(e){const t=e.headers.get("mcp-protocol-version");if(null!==t&&!A.Iu.includes(t))return this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${t} (supported versions: ${A.Iu.join(", ")})`)),this.createJsonErrorResponse(400,-32e3,`Bad Request: Unsupported protocol version: ${t} (supported versions: ${A.Iu.join(", ")})`)}async close(){this._streamMapping.forEach((({cleanup:e})=>{e()})),this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}closeSSEStream(e){const t=this._requestToStreamMapping.get(e);if(!t)return;const r=this._streamMapping.get(t);r&&r.cleanup()}closeStandaloneSSEStream(){const e=this._streamMapping.get(this._standaloneSseStreamId);e&&e.cleanup()}async send(e,t){let r=t?.relatedRequestId;if(((0,A.ig)(e)||(0,A.LW)(e))&&(r=e.id),void 0===r){if((0,A.ig)(e)||(0,A.LW)(e))throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");let t;this._eventStore&&(t=await this._eventStore.storeEvent(this._standaloneSseStreamId,e));const r=this._streamMapping.get(this._standaloneSseStreamId);if(void 0===r)return;return void(r.controller&&r.encoder&&this.writeSSEEvent(r.controller,r.encoder,e,t))}const s=this._requestToStreamMapping.get(r);if(!s)throw new Error(`No connection established for request ID: ${String(r)}`);const n=this._streamMapping.get(s);if(!this._enableJsonResponse&&n?.controller&&n?.encoder){let t;this._eventStore&&(t=await this._eventStore.storeEvent(s,e)),this.writeSSEEvent(n.controller,n.encoder,e,t)}if((0,A.ig)(e)||(0,A.LW)(e)){this._requestResponseMap.set(r,e);const t=Array.from(this._requestToStreamMapping.entries()).filter((([e,t])=>t===s)).map((([e])=>e));if(t.every((e=>this._requestResponseMap.has(e)))){if(!n)throw new Error(`No connection established for request ID: ${String(r)}`);if(this._enableJsonResponse&&n.resolveJson){const e={"Content-Type":"application/json"};void 0!==this.sessionId&&(e["mcp-session-id"]=this.sessionId);const r=t.map((e=>this._requestResponseMap.get(e)));1===r.length?n.resolveJson(new Response(JSON.stringify(r[0]),{status:200,headers:e})):n.resolveJson(new Response(JSON.stringify(r),{status:200,headers:e}))}else n.cleanup();for(const e of t)this._requestResponseMap.delete(e),this._requestToStreamMapping.delete(e)}}}}class k{constructor(e={}){this._requestContext=new WeakMap,this._webStandardTransport=new B(e),this._requestListener=x((async e=>{const t=this._requestContext.get(e);return this._webStandardTransport.handleRequest(e,{authInfo:t?.authInfo,parsedBody:t?.parsedBody})}),{overrideGlobalObjects:!1})}get sessionId(){return this._webStandardTransport.sessionId}set onclose(e){this._webStandardTransport.onclose=e}get onclose(){return this._webStandardTransport.onclose}set onerror(e){this._webStandardTransport.onerror=e}get onerror(){return this._webStandardTransport.onerror}set onmessage(e){this._webStandardTransport.onmessage=e}get onmessage(){return this._webStandardTransport.onmessage}async start(){return this._webStandardTransport.start()}async close(){return this._webStandardTransport.close()}async send(e,t){return this._webStandardTransport.send(e,t)}async handleRequest(e,t,r){const s=e.auth,n=x((async e=>this._webStandardTransport.handleRequest(e,{authInfo:s,parsedBody:r})),{overrideGlobalObjects:!1});await n(e,t)}closeSSEStream(e){this._webStandardTransport.closeSSEStream(e)}closeStandaloneSSEStream(){this._webStandardTransport.closeStandaloneSSEStream()}}}};
|