@lightsage/mcp 0.4.24 → 0.4.25

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/bin/mcp-server.js CHANGED
@@ -6512,11 +6512,38 @@ var init_console_logger = __esm(() => {
6512
6512
  ];
6513
6513
  });
6514
6514
 
6515
+ // node_modules/@hono/node-server/dist/constants-BLSFu_RU.mjs
6516
+ var X_ALREADY_SENT = "x-hono-already-sent";
6517
+ var init_constants_BLSFu_RU = () => {};
6518
+
6519
+ // node_modules/hono/dist/helper/websocket/index.js
6520
+ var defineWebSocketHelper = (handler) => {
6521
+ return (...args) => {
6522
+ if (typeof args[0] === "function") {
6523
+ const [createEvents, options] = args;
6524
+ return async function upgradeWebSocket(c, next) {
6525
+ const result = await handler(c, await createEvents(c), options);
6526
+ if (result)
6527
+ return result;
6528
+ await next();
6529
+ };
6530
+ } else {
6531
+ const [c, events, options] = args;
6532
+ return (async () => {
6533
+ const upgraded = await handler(c, events, options);
6534
+ if (!upgraded)
6535
+ throw new Error("Failed to upgrade WebSocket");
6536
+ return upgraded;
6537
+ })();
6538
+ }
6539
+ };
6540
+ };
6541
+ var init_websocket = () => {};
6542
+
6515
6543
  // node_modules/@hono/node-server/dist/index.mjs
6516
- import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
6517
- import { Http2ServerRequest } from "http2";
6518
- import { Readable } from "stream";
6519
- import crypto2 from "crypto";
6544
+ import { STATUS_CODES, ServerResponse, createServer } from "node:http";
6545
+ import { Http2ServerRequest, constants } from "node:http2";
6546
+ import { Readable } from "node:stream";
6520
6547
  async function readWithoutBlocking(readPromise) {
6521
6548
  return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
6522
6549
  }
@@ -6524,6 +6551,11 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
6524
6551
  const cancel = (error) => {
6525
6552
  reader.cancel(error).catch(() => {});
6526
6553
  };
6554
+ const stream = writable.stream;
6555
+ if (writable.destroyed || stream?.closed || stream?.destroyed) {
6556
+ cancel();
6557
+ return reader.closed;
6558
+ }
6527
6559
  writable.on("close", cancel);
6528
6560
  writable.on("error", cancel);
6529
6561
  (currentReadPromise ?? reader.read()).then(flow, handleStreamError);
@@ -6532,59 +6564,124 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
6532
6564
  writable.off("error", cancel);
6533
6565
  });
6534
6566
  function handleStreamError(error) {
6535
- if (error) {
6567
+ if (error)
6536
6568
  writable.destroy(error);
6537
- }
6538
6569
  }
6539
6570
  function onDrain() {
6540
6571
  reader.read().then(flow, handleStreamError);
6541
6572
  }
6542
6573
  function flow({ done, value }) {
6543
6574
  try {
6544
- if (done) {
6575
+ if (done)
6545
6576
  writable.end();
6546
- } else if (!writable.write(value)) {
6577
+ else if (!writable.write(value))
6547
6578
  writable.once("drain", onDrain);
6548
- } else {
6549
- return reader.read().then(flow, handleStreamError);
6550
- }
6579
+ else
6580
+ reader.read().then(flow, handleStreamError);
6551
6581
  } catch (e) {
6552
6582
  handleStreamError(e);
6553
6583
  }
6554
6584
  }
6555
6585
  }
6556
6586
  function writeFromReadableStream(stream, writable) {
6557
- if (stream.locked) {
6587
+ if (stream.locked)
6558
6588
  throw new TypeError("ReadableStream is locked.");
6559
- } else if (writable.destroyed) {
6589
+ else if (writable.destroyed) {
6590
+ stream.cancel().catch(() => {});
6560
6591
  return;
6561
6592
  }
6562
6593
  return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
6563
6594
  }
6564
- var RequestError, validateRequestTarget = (target) => {
6595
+ var RequestError, nonJoinedHeaders, validHeaderName, isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32, normalizeHeaderValue = (value) => {
6596
+ if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1)))
6597
+ return value;
6598
+ let start = 0;
6599
+ let end = value.length;
6600
+ while (start < end && isHttpWhitespace(value.charCodeAt(start)))
6601
+ start++;
6602
+ while (end > start && isHttpWhitespace(value.charCodeAt(end - 1)))
6603
+ end--;
6604
+ return value.slice(start, end);
6605
+ }, forbiddenHeaderValue, GlobalHeaders, materializeHeaders = (rawHeaders, HeadersCtor = GlobalHeaders) => {
6606
+ const headers = new HeadersCtor;
6607
+ for (let i = 0;i < rawHeaders.length; i += 2) {
6608
+ const name = rawHeaders[i];
6609
+ if (!name.startsWith(":"))
6610
+ headers.append(name, rawHeaders[i + 1]);
6611
+ }
6612
+ return headers;
6613
+ }, RequestHeaders, newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers), reValidRequestUrl, reDotSegment, reValidHost, validateRequestTarget = (target) => {
6565
6614
  const backslash = target.indexOf("\\");
6566
6615
  if (backslash !== -1) {
6567
6616
  const query = target.indexOf("?");
6568
- if (query === -1 || backslash < query) {
6617
+ if (query === -1 || backslash < query)
6569
6618
  throw new RequestError("Backslash in request path");
6619
+ }
6620
+ }, buildUrl = (scheme, host, incomingUrl) => {
6621
+ const url = `${scheme}://${host}${incomingUrl}`;
6622
+ if (!reValidHost.test(host)) {
6623
+ validateRequestTarget(incomingUrl);
6624
+ const urlObj = new URL(url);
6625
+ if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase())
6626
+ throw new RequestError("Invalid host header");
6627
+ return urlObj.href;
6628
+ } else if (incomingUrl.length === 0)
6629
+ return url + "/";
6630
+ else {
6631
+ if (incomingUrl.charCodeAt(0) !== 47)
6632
+ throw new RequestError("Invalid URL");
6633
+ if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) {
6634
+ validateRequestTarget(incomingUrl);
6635
+ return new URL(url).href;
6570
6636
  }
6637
+ return url;
6571
6638
  }
6572
6639
  }, toRequestError = (e) => {
6573
- if (e instanceof RequestError) {
6640
+ if (e instanceof RequestError)
6574
6641
  return e;
6575
- }
6576
6642
  return new RequestError(e.message, { cause: e });
6577
- }, GlobalRequest, Request2, newHeadersFromIncoming = (incoming) => {
6578
- const headerRecord = [];
6579
- const rawHeaders = incoming.rawHeaders;
6580
- for (let i = 0;i < rawHeaders.length; i += 2) {
6581
- const { [i]: key, [i + 1]: value } = rawHeaders;
6582
- if (key.charCodeAt(0) !== 58) {
6583
- headerRecord.push([key, value]);
6584
- }
6643
+ }, GlobalRequest, Request$1, wrapBodyStream, byteExactEncodings, isByteExactEncoding = (encoding) => encoding === null || byteExactEncodings.has(encoding), bodyBufferedBeforeDisconnectKey, bodyBufferedLengthBeforeDisconnectKey, toBufferChunk = (chunk, encoding) => Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding ?? "utf8"), isRecoverableDisconnectedIncoming = (incoming) => !(incoming instanceof Http2ServerRequest) && !!incoming.complete && !!incoming.readableAborted && typeof incoming.read === "function" && isByteExactEncoding(incoming.readableEncoding), recordBodyBufferedBeforeDisconnect = (incoming) => {
6644
+ if (incoming.readableDidRead || !isRecoverableDisconnectedIncoming(incoming))
6645
+ return;
6646
+ const incomingWithRecovery = incoming;
6647
+ incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] ??= incoming.readableLength;
6648
+ }, readBodyBufferedBeforeDisconnect = (incoming, chunks) => {
6649
+ if (incoming.readableDidRead && !chunks || !isRecoverableDisconnectedIncoming(incoming))
6650
+ return;
6651
+ const incomingWithRecovery = incoming;
6652
+ if (incomingWithRecovery[bodyBufferedBeforeDisconnectKey] !== undefined)
6653
+ return incomingWithRecovery[bodyBufferedBeforeDisconnectKey];
6654
+ let result;
6655
+ const errored = incoming.errored;
6656
+ if (errored && errored.code !== "ECONNRESET")
6657
+ result = errored;
6658
+ else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== undefined && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey])
6659
+ result = newBodyUnusableError();
6660
+ else {
6661
+ const bodyChunks = chunks ?? [];
6662
+ const chunk = incoming.read();
6663
+ if (chunk !== null)
6664
+ bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
6665
+ const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
6666
+ result = buffer;
6667
+ const contentLength = incoming.headers["content-length"];
6668
+ if (typeof contentLength === "string" && /^\d+$/.test(contentLength)) {
6669
+ const expectedLength = Number(contentLength);
6670
+ if (Number.isSafeInteger(expectedLength) && buffer.length !== expectedLength)
6671
+ result = newBodyUnusableError();
6672
+ }
6673
+ }
6674
+ incomingWithRecovery[bodyBufferedBeforeDisconnectKey] = result;
6675
+ return result;
6676
+ }, enqueueBufferedBody = (controller, buffered) => {
6677
+ if (buffered instanceof Error) {
6678
+ controller.error(buffered);
6679
+ return;
6585
6680
  }
6586
- return new Headers(headerRecord);
6587
- }, wrapBodyStream, newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
6681
+ if (buffered.length > 0)
6682
+ controller.enqueue(buffered);
6683
+ controller.close();
6684
+ }, newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
6588
6685
  const init = {
6589
6686
  method,
6590
6687
  headers,
@@ -6592,108 +6689,293 @@ var RequestError, validateRequestTarget = (target) => {
6592
6689
  };
6593
6690
  if (method === "TRACE") {
6594
6691
  init.method = "GET";
6595
- const req = new Request2(url, init);
6596
- Object.defineProperty(req, "method", {
6597
- get() {
6598
- return "TRACE";
6599
- }
6600
- });
6692
+ const req = new Request$1(url, init);
6693
+ Object.defineProperty(req, "method", { get() {
6694
+ return "TRACE";
6695
+ } });
6601
6696
  return req;
6602
6697
  }
6603
- if (!(method === "GET" || method === "HEAD")) {
6604
- if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
6605
- init.body = new ReadableStream({
6606
- start(controller) {
6607
- controller.enqueue(incoming.rawBody);
6608
- controller.close();
6609
- }
6610
- });
6611
- } else if (incoming[wrapBodyStream]) {
6698
+ if (!(method === "GET" || method === "HEAD"))
6699
+ if ("rawBody" in incoming && incoming.rawBody instanceof Buffer)
6700
+ init.body = new ReadableStream({ start(controller) {
6701
+ controller.enqueue(incoming.rawBody);
6702
+ controller.close();
6703
+ } });
6704
+ else if (incoming[wrapBodyStream]) {
6612
6705
  let reader;
6613
- init.body = new ReadableStream({
6614
- async pull(controller) {
6615
- try {
6616
- reader ||= Readable.toWeb(incoming).getReader();
6617
- const { done, value } = await reader.read();
6618
- if (done) {
6619
- controller.close();
6620
- } else {
6621
- controller.enqueue(value);
6706
+ init.body = new ReadableStream({ async pull(controller) {
6707
+ try {
6708
+ if (!reader) {
6709
+ const buffered = readBodyBufferedBeforeDisconnect(incoming);
6710
+ if (buffered !== undefined) {
6711
+ enqueueBufferedBody(controller, buffered);
6712
+ return;
6622
6713
  }
6623
- } catch (error) {
6624
- controller.error(error);
6625
6714
  }
6715
+ reader ||= Readable.toWeb(incoming).getReader();
6716
+ const { done, value } = await reader.read();
6717
+ if (done)
6718
+ controller.close();
6719
+ else
6720
+ controller.enqueue(value);
6721
+ } catch (error) {
6722
+ controller.error(error);
6626
6723
  }
6627
- });
6724
+ } });
6628
6725
  } else {
6629
- init.body = Readable.toWeb(incoming);
6630
- }
6726
+ const buffered = readBodyBufferedBeforeDisconnect(incoming);
6727
+ if (buffered !== undefined)
6728
+ init.body = new ReadableStream({ start(controller) {
6729
+ enqueueBufferedBody(controller, buffered);
6730
+ } });
6731
+ else
6732
+ init.body = Readable.toWeb(incoming);
6733
+ }
6734
+ return new Request$1(url, init);
6735
+ }, getRequestCache, requestCache, incomingKey, urlKey, methodKey, headersKey, abortControllerKey, getAbortController, abortRequest, bodyBufferKey, bodyReadPromiseKey, bodyConsumedDirectlyKey, bodyLockReaderKey, abortReasonKey, newBodyUnusableError = () => {
6736
+ return /* @__PURE__ */ new TypeError("Body is unusable");
6737
+ }, rejectBodyUnusable = () => {
6738
+ return Promise.reject(newBodyUnusableError());
6739
+ }, textDecoder, consumeBodyDirectOnce = (request) => {
6740
+ if (request[bodyConsumedDirectlyKey])
6741
+ return rejectBodyUnusable();
6742
+ request[bodyConsumedDirectlyKey] = true;
6743
+ }, toArrayBuffer = (buf) => {
6744
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
6745
+ }, contentType = (request) => {
6746
+ return (request[headersKey] ||= newHeadersFromIncoming(request[incomingKey])).get("content-type") || "";
6747
+ }, methodTokenRegExp, normalizeIncomingMethod = (method) => {
6748
+ if (typeof method !== "string" || method.length === 0)
6749
+ return "GET";
6750
+ switch (method) {
6751
+ case "DELETE":
6752
+ case "GET":
6753
+ case "HEAD":
6754
+ case "OPTIONS":
6755
+ case "PATCH":
6756
+ case "POST":
6757
+ case "PUT":
6758
+ case "QUERY":
6759
+ return method;
6760
+ }
6761
+ const upper = method.toUpperCase();
6762
+ switch (upper) {
6763
+ case "DELETE":
6764
+ case "GET":
6765
+ case "HEAD":
6766
+ case "OPTIONS":
6767
+ case "POST":
6768
+ case "PUT":
6769
+ return upper;
6770
+ default:
6771
+ return method;
6772
+ }
6773
+ }, validateDirectReadMethod = (method) => {
6774
+ if (!methodTokenRegExp.test(method))
6775
+ return /* @__PURE__ */ new TypeError(`'${method}' is not a valid HTTP method.`);
6776
+ const normalized = method.toUpperCase();
6777
+ if (normalized === "CONNECT" || normalized === "TRACK" || normalized === "TRACE" && method !== "TRACE")
6778
+ return /* @__PURE__ */ new TypeError(`'${method}' HTTP method is unsupported.`);
6779
+ }, readBodyWithFastPath = (request, method, fromBuffer) => {
6780
+ if (request[bodyConsumedDirectlyKey])
6781
+ return rejectBodyUnusable();
6782
+ const methodName = request.method;
6783
+ if (methodName === "GET" || methodName === "HEAD")
6784
+ return request[getRequestCache]()[method]();
6785
+ const methodValidationError = validateDirectReadMethod(methodName);
6786
+ if (methodValidationError)
6787
+ return Promise.reject(methodValidationError);
6788
+ if (request[requestCache]) {
6789
+ if (methodName !== "TRACE")
6790
+ return request[requestCache][method]();
6791
+ }
6792
+ const alreadyUsedError = consumeBodyDirectOnce(request);
6793
+ if (alreadyUsedError)
6794
+ return alreadyUsedError;
6795
+ const raw = readRawBodyIfAvailable(request);
6796
+ if (raw) {
6797
+ const result = Promise.resolve(fromBuffer(raw, request));
6798
+ request[bodyBufferKey] = undefined;
6799
+ return result;
6631
6800
  }
6632
- return new Request2(url, init);
6633
- }, getRequestCache, requestCache, incomingKey, urlKey, headersKey, abortControllerKey, getAbortController, requestPrototype, newRequest = (incoming, defaultHostname) => {
6801
+ return readBodyDirect(request).then((buf) => {
6802
+ const result = fromBuffer(buf, request);
6803
+ request[bodyBufferKey] = undefined;
6804
+ return result;
6805
+ });
6806
+ }, readRawBodyIfAvailable = (request) => {
6807
+ const incoming = request[incomingKey];
6808
+ if ("rawBody" in incoming && incoming.rawBody instanceof Buffer)
6809
+ return incoming.rawBody;
6810
+ }, normalizeAbortError = (request, incoming) => {
6811
+ if (incoming.errored)
6812
+ return incoming.errored;
6813
+ const reason = request[abortReasonKey];
6814
+ if (reason !== undefined)
6815
+ return reason instanceof Error ? reason : new Error(String(reason));
6816
+ return /* @__PURE__ */ new Error("Client connection prematurely closed.");
6817
+ }, readBodyDirect = (request) => {
6818
+ if (request[bodyBufferKey])
6819
+ return Promise.resolve(request[bodyBufferKey]);
6820
+ if (request[bodyReadPromiseKey])
6821
+ return request[bodyReadPromiseKey];
6822
+ const incoming = request[incomingKey];
6823
+ if (incoming.readableDidRead)
6824
+ return rejectBodyUnusable();
6825
+ const buffered = readBodyBufferedBeforeDisconnect(incoming);
6826
+ if (buffered !== undefined) {
6827
+ if (buffered instanceof Error)
6828
+ return Promise.reject(buffered);
6829
+ request[bodyBufferKey] = buffered;
6830
+ return Promise.resolve(buffered);
6831
+ }
6832
+ const promise = new Promise((resolve, reject) => {
6833
+ const chunks = [];
6834
+ let settled = false;
6835
+ const finish = (callback) => {
6836
+ if (settled)
6837
+ return;
6838
+ settled = true;
6839
+ cleanup();
6840
+ callback();
6841
+ };
6842
+ const recoverCompleteBodyAfterDisconnect = (error) => {
6843
+ const streamError = incoming.errored ?? error;
6844
+ if (!isRecoverableDisconnectedIncoming(incoming) || streamError && streamError.code !== "ECONNRESET")
6845
+ return false;
6846
+ finish(() => {
6847
+ const recovered = readBodyBufferedBeforeDisconnect(incoming, chunks);
6848
+ if (recovered instanceof Error)
6849
+ reject(recovered);
6850
+ else if (recovered === undefined)
6851
+ reject(error ?? normalizeAbortError(request, incoming));
6852
+ else {
6853
+ request[bodyBufferKey] = recovered;
6854
+ resolve(recovered);
6855
+ }
6856
+ });
6857
+ return true;
6858
+ };
6859
+ const onData = (chunk) => {
6860
+ chunks.push(toBufferChunk(chunk, incoming.readableEncoding));
6861
+ };
6862
+ const onEnd = () => {
6863
+ finish(() => {
6864
+ const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
6865
+ request[bodyBufferKey] = buffer;
6866
+ resolve(buffer);
6867
+ });
6868
+ };
6869
+ const onError = (error) => {
6870
+ if (recoverCompleteBodyAfterDisconnect(error))
6871
+ return;
6872
+ finish(() => {
6873
+ reject(error);
6874
+ });
6875
+ };
6876
+ const onClose = () => {
6877
+ if (incoming.readableEnded) {
6878
+ onEnd();
6879
+ return;
6880
+ }
6881
+ if (recoverCompleteBodyAfterDisconnect())
6882
+ return;
6883
+ finish(() => {
6884
+ reject(normalizeAbortError(request, incoming));
6885
+ });
6886
+ };
6887
+ const cleanup = () => {
6888
+ incoming.off("data", onData);
6889
+ incoming.off("end", onEnd);
6890
+ incoming.off("error", onError);
6891
+ incoming.off("close", onClose);
6892
+ request[bodyReadPromiseKey] = undefined;
6893
+ };
6894
+ incoming.on("data", onData);
6895
+ incoming.on("end", onEnd);
6896
+ incoming.on("error", onError);
6897
+ incoming.on("close", onClose);
6898
+ queueMicrotask(() => {
6899
+ if (settled)
6900
+ return;
6901
+ if (incoming.readableEnded)
6902
+ onEnd();
6903
+ else if (incoming.errored)
6904
+ onError(incoming.errored);
6905
+ else if (incoming.destroyed)
6906
+ onClose();
6907
+ });
6908
+ });
6909
+ request[bodyReadPromiseKey] = promise;
6910
+ return promise;
6911
+ }, requestPrototype, newRequest = (incoming, defaultHostname) => {
6634
6912
  const req = Object.create(requestPrototype);
6635
6913
  req[incomingKey] = incoming;
6914
+ req[methodKey] = normalizeIncomingMethod(incoming.method);
6636
6915
  const incomingUrl = incoming.url || "";
6637
6916
  if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
6638
- if (incoming instanceof Http2ServerRequest) {
6917
+ if (incoming instanceof Http2ServerRequest)
6639
6918
  throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
6640
- }
6641
6919
  try {
6642
6920
  validateRequestTarget(incomingUrl);
6643
- const url2 = new URL(incomingUrl);
6644
- req[urlKey] = url2.href;
6921
+ req[urlKey] = new URL(incomingUrl).href;
6645
6922
  } catch (e) {
6646
6923
  throw new RequestError("Invalid absolute URL", { cause: e });
6647
6924
  }
6648
6925
  return req;
6649
6926
  }
6650
6927
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
6651
- if (!host) {
6928
+ if (!host)
6652
6929
  throw new RequestError("Missing host header");
6653
- }
6654
6930
  let scheme;
6655
6931
  if (incoming instanceof Http2ServerRequest) {
6656
6932
  scheme = incoming.scheme;
6657
- if (!(scheme === "http" || scheme === "https")) {
6933
+ if (!(scheme === "http" || scheme === "https"))
6658
6934
  throw new RequestError("Unsupported scheme");
6659
- }
6660
- } else {
6935
+ } else
6661
6936
  scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
6937
+ try {
6938
+ req[urlKey] = buildUrl(scheme, host, incomingUrl);
6939
+ } catch (e) {
6940
+ if (e instanceof RequestError)
6941
+ throw e;
6942
+ else
6943
+ throw new RequestError("Invalid URL", { cause: e });
6662
6944
  }
6663
- validateRequestTarget(incomingUrl);
6664
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
6665
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
6666
- throw new RequestError("Invalid host header");
6667
- }
6668
- req[urlKey] = url.href;
6669
6945
  return req;
6670
- }, responseCache, getResponseCache, cacheKey, GlobalResponse, Response2, buildOutgoingHttpHeaders = (headers) => {
6946
+ }, defaultContentType = "text/plain; charset=UTF-8", responseCache, getResponseCache, cacheKey, GlobalResponse, Response$1, validRedirectUrl, parseRedirectUrl = (url) => {
6947
+ if (url instanceof URL)
6948
+ return url.href;
6949
+ if (validRedirectUrl.test(url))
6950
+ return url;
6951
+ return new URL(url).href;
6952
+ }, validRedirectStatuses, buildOutgoingHttpHeaders = (headers, defaultContentType) => {
6671
6953
  const res = {};
6672
- if (!(headers instanceof Headers)) {
6954
+ if (!(headers instanceof Headers))
6673
6955
  headers = new Headers(headers ?? undefined);
6674
- }
6675
- const cookies = [];
6676
- for (const [k, v] of headers) {
6677
- if (k === "set-cookie") {
6678
- cookies.push(v);
6679
- } else {
6956
+ if (headers.has("set-cookie")) {
6957
+ const cookies = [];
6958
+ for (const [k, v] of headers)
6959
+ if (k === "set-cookie")
6960
+ cookies.push(v);
6961
+ else
6962
+ res[k] = v;
6963
+ if (cookies.length > 0)
6964
+ res["set-cookie"] = cookies;
6965
+ } else
6966
+ for (const [k, v] of headers)
6680
6967
  res[k] = v;
6681
- }
6682
- }
6683
- if (cookies.length > 0) {
6684
- res["set-cookie"] = cookies;
6685
- }
6686
- res["content-type"] ??= "text/plain; charset=UTF-8";
6968
+ if (defaultContentType)
6969
+ res["content-type"] ??= defaultContentType;
6687
6970
  return res;
6688
- }, X_ALREADY_SENT = "x-hono-already-sent", outgoingEnded, incomingDraining, DRAIN_TIMEOUT_MS = 500, MAX_DRAIN_BYTES, drainIncoming = (incoming) => {
6971
+ }, outgoingEnded, incomingDraining, DRAIN_TIMEOUT_MS = 500, MAX_DRAIN_BYTES, drainIncoming = (incoming) => {
6689
6972
  const incomingWithDrainState = incoming;
6690
- if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
6973
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining])
6691
6974
  return;
6692
- }
6693
6975
  incomingWithDrainState[incomingDraining] = true;
6694
- if (incoming instanceof Http2ServerRequest2) {
6976
+ if (incoming instanceof Http2ServerRequest) {
6695
6977
  try {
6696
- incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
6978
+ incoming.stream?.close?.(constants.NGHTTP2_NO_ERROR);
6697
6979
  } catch {}
6698
6980
  return;
6699
6981
  }
@@ -6708,100 +6990,161 @@ var RequestError, validateRequestTarget = (target) => {
6708
6990
  cleanup();
6709
6991
  const socket = incoming.socket;
6710
6992
  if (socket && !socket.destroyed) {
6711
- socket.destroySoon();
6993
+ if (typeof socket.destroySoon === "function")
6994
+ socket.destroySoon();
6995
+ else if (typeof socket.destroy === "function")
6996
+ socket.destroy();
6712
6997
  }
6713
6998
  };
6714
6999
  const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
6715
7000
  timer.unref?.();
6716
7001
  const onData = (chunk) => {
6717
7002
  bytesRead += chunk.length;
6718
- if (bytesRead > MAX_DRAIN_BYTES) {
7003
+ if (bytesRead > MAX_DRAIN_BYTES)
6719
7004
  forceClose();
6720
- }
6721
7005
  };
6722
7006
  incoming.on("data", onData);
6723
7007
  incoming.on("end", cleanup);
6724
7008
  incoming.on("error", cleanup);
6725
7009
  incoming.resume();
6726
- }, handleRequestError = () => new Response(null, {
6727
- status: 400
6728
- }), handleFetchError = (e) => new Response(null, {
6729
- status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
6730
- }), handleResponseError = (e, outgoing) => {
7010
+ }, makeCloseHandler = (req, incoming, outgoing, needsBodyCleanup) => () => {
7011
+ if (incoming.errored) {
7012
+ recordBodyBufferedBeforeDisconnect(incoming);
7013
+ req[abortRequest](incoming.errored.toString());
7014
+ } else if (!outgoing.writableFinished || incoming instanceof Http2ServerRequest && incoming.aborted) {
7015
+ recordBodyBufferedBeforeDisconnect(incoming);
7016
+ req[abortRequest]("Client connection prematurely closed.");
7017
+ }
7018
+ if (needsBodyCleanup && !incoming.readableEnded)
7019
+ setTimeout(() => {
7020
+ if (!incoming.readableEnded)
7021
+ setTimeout(() => {
7022
+ drainIncoming(incoming);
7023
+ });
7024
+ });
7025
+ }, isImmediateCacheableResponse = (res) => {
7026
+ if (!(cacheKey in res))
7027
+ return false;
7028
+ const body = res[cacheKey][1];
7029
+ return body === null || typeof body === "string" || body instanceof Uint8Array;
7030
+ }, handleRequestError = () => new Response(null, { status: 400 }), handleFetchError = (e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 }), handleResponseError = (e, outgoing) => {
6731
7031
  const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
6732
- if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
7032
+ if (err.code === "ERR_STREAM_PREMATURE_CLOSE")
6733
7033
  console.info("The user aborted a request.");
6734
- } else {
7034
+ else {
6735
7035
  console.error(e);
6736
7036
  if (!outgoing.headersSent) {
7037
+ if (outgoing instanceof ServerResponse)
7038
+ outgoing._contentLength = null;
6737
7039
  outgoing.writeHead(500, { "Content-Type": "text/plain" });
6738
7040
  }
6739
7041
  outgoing.end(`Error: ${err.message}`);
6740
7042
  outgoing.destroy(err);
6741
7043
  }
6742
7044
  }, flushHeaders = (outgoing) => {
6743
- if ("flushHeaders" in outgoing && outgoing.writable) {
7045
+ if ("flushHeaders" in outgoing && outgoing.writable)
6744
7046
  outgoing.flushHeaders();
7047
+ }, trySetContentLength = (outgoing, status, length) => {
7048
+ const http1 = outgoing;
7049
+ if (http1._contentLength === null && http1._hasBody && http1.useChunkedEncodingByDefault && !http1._removedContLen && status >= 200 && status !== 204 && status !== 304 && !outgoing.hasHeader("content-length") && !outgoing.hasHeader("transfer-encoding") && !outgoing.hasHeader("trailer")) {
7050
+ http1._contentLength = length;
7051
+ return true;
6745
7052
  }
7053
+ return false;
7054
+ }, writeDefaultHeaders = (outgoing, status, length) => {
7055
+ if (trySetContentLength(outgoing, status, length))
7056
+ outgoing.writeHead(status, { "Content-Type": defaultContentType });
7057
+ else
7058
+ outgoing.writeHead(status, {
7059
+ "Content-Type": defaultContentType,
7060
+ "Content-Length": length
7061
+ });
6746
7062
  }, responseViaCache = async (res, outgoing) => {
6747
7063
  let [status, body, header] = res[cacheKey];
6748
- let hasContentLength = false;
6749
7064
  if (!header) {
6750
- header = { "content-type": "text/plain; charset=UTF-8" };
6751
- } else if (header instanceof Headers) {
7065
+ if (body === null) {
7066
+ outgoing.writeHead(status);
7067
+ outgoing.end();
7068
+ } else if (typeof body === "string") {
7069
+ writeDefaultHeaders(outgoing, status, Buffer.byteLength(body));
7070
+ outgoing.end(body);
7071
+ } else if (body instanceof Uint8Array) {
7072
+ writeDefaultHeaders(outgoing, status, body.byteLength);
7073
+ outgoing.end(body);
7074
+ } else if (body instanceof Blob) {
7075
+ writeDefaultHeaders(outgoing, status, body.size);
7076
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
7077
+ } else {
7078
+ outgoing.writeHead(status, { "Content-Type": defaultContentType });
7079
+ flushHeaders(outgoing);
7080
+ await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
7081
+ }
7082
+ outgoing[outgoingEnded]?.();
7083
+ return;
7084
+ }
7085
+ let hasContentLength = false;
7086
+ let plainHeaders = false;
7087
+ let canAutoLength = true;
7088
+ if (header instanceof Headers) {
6752
7089
  hasContentLength = header.has("content-length");
6753
- header = buildOutgoingHttpHeaders(header);
7090
+ header = buildOutgoingHttpHeaders(header, body === null ? undefined : defaultContentType);
6754
7091
  } else if (Array.isArray(header)) {
6755
7092
  const headerObj = new Headers(header);
6756
7093
  hasContentLength = headerObj.has("content-length");
6757
- header = buildOutgoingHttpHeaders(headerObj);
7094
+ header = buildOutgoingHttpHeaders(headerObj, body === null ? undefined : defaultContentType);
6758
7095
  } else {
7096
+ plainHeaders = true;
6759
7097
  for (const key in header) {
6760
7098
  if (key.length === 14 && key.toLowerCase() === "content-length") {
6761
7099
  hasContentLength = true;
6762
7100
  break;
6763
7101
  }
7102
+ if (key.length === 17 && key.toLowerCase() === "transfer-encoding" || key.length === 7 && key.toLowerCase() === "trailer")
7103
+ canAutoLength = false;
6764
7104
  }
6765
7105
  }
6766
7106
  if (!hasContentLength) {
6767
- if (typeof body === "string") {
6768
- header["Content-Length"] = Buffer.byteLength(body);
6769
- } else if (body instanceof Uint8Array) {
6770
- header["Content-Length"] = body.byteLength;
6771
- } else if (body instanceof Blob) {
6772
- header["Content-Length"] = body.size;
7107
+ let length;
7108
+ if (typeof body === "string")
7109
+ length = Buffer.byteLength(body);
7110
+ else if (body instanceof Uint8Array)
7111
+ length = body.byteLength;
7112
+ else if (body instanceof Blob)
7113
+ length = body.size;
7114
+ if (length !== undefined && (!plainHeaders || !canAutoLength || !trySetContentLength(outgoing, status, length))) {
7115
+ if (plainHeaders)
7116
+ header = { ...header };
7117
+ header["Content-Length"] = length;
6773
7118
  }
6774
7119
  }
6775
7120
  outgoing.writeHead(status, header);
6776
- if (typeof body === "string" || body instanceof Uint8Array) {
7121
+ if (body == null)
7122
+ outgoing.end();
7123
+ else if (typeof body === "string" || body instanceof Uint8Array)
6777
7124
  outgoing.end(body);
6778
- } else if (body instanceof Blob) {
7125
+ else if (body instanceof Blob)
6779
7126
  outgoing.end(new Uint8Array(await body.arrayBuffer()));
6780
- } else {
7127
+ else {
6781
7128
  flushHeaders(outgoing);
6782
7129
  await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
6783
7130
  }
6784
7131
  outgoing[outgoingEnded]?.();
6785
7132
  }, isPromise = (res) => typeof res.then === "function", responseViaResponseObject = async (res, outgoing, options = {}) => {
6786
- if (isPromise(res)) {
6787
- if (options.errorHandler) {
7133
+ if (isPromise(res))
7134
+ if (options.errorHandler)
6788
7135
  try {
6789
7136
  res = await res;
6790
7137
  } catch (err) {
6791
7138
  const errRes = await options.errorHandler(err);
6792
- if (!errRes) {
7139
+ if (!errRes)
6793
7140
  return;
6794
- }
6795
7141
  res = errRes;
6796
7142
  }
6797
- } else {
7143
+ else
6798
7144
  res = await res.catch(handleFetchError);
6799
- }
6800
- }
6801
- if (cacheKey in res) {
7145
+ if (cacheKey in res)
6802
7146
  return responseViaCache(res, outgoing);
6803
- }
6804
- const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
7147
+ const resHeaderRecord = buildOutgoingHttpHeaders(res.headers, res.body === null ? undefined : defaultContentType);
6805
7148
  if (res.body) {
6806
7149
  const reader = res.body.getReader();
6807
7150
  const values = [];
@@ -6811,10 +7154,7 @@ var RequestError, validateRequestTarget = (target) => {
6811
7154
  let maxReadCount = 2;
6812
7155
  for (let i = 0;i < maxReadCount; i++) {
6813
7156
  currentReadPromise ||= reader.read();
6814
- const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
6815
- console.error(e);
6816
- done = true;
6817
- });
7157
+ const chunk = await readWithoutBlocking(currentReadPromise);
6818
7158
  if (!chunk) {
6819
7159
  if (i === 1) {
6820
7160
  await new Promise((resolve) => setTimeout(resolve));
@@ -6824,28 +7164,25 @@ var RequestError, validateRequestTarget = (target) => {
6824
7164
  break;
6825
7165
  }
6826
7166
  currentReadPromise = undefined;
6827
- if (chunk.value) {
7167
+ if (chunk.value)
6828
7168
  values.push(chunk.value);
6829
- }
6830
7169
  if (chunk.done) {
6831
7170
  done = true;
6832
7171
  break;
6833
7172
  }
6834
7173
  }
6835
- if (done && !("content-length" in resHeaderRecord)) {
7174
+ if (done && !("content-length" in resHeaderRecord))
6836
7175
  resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
6837
- }
6838
7176
  }
6839
7177
  outgoing.writeHead(res.status, resHeaderRecord);
6840
7178
  values.forEach((value) => {
6841
7179
  outgoing.write(value);
6842
7180
  });
6843
- if (done) {
7181
+ if (done)
6844
7182
  outgoing.end();
6845
- } else {
6846
- if (values.length === 0) {
7183
+ else {
7184
+ if (values.length === 0)
6847
7185
  flushHeaders(outgoing);
6848
- }
6849
7186
  await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
6850
7187
  }
6851
7188
  } else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
@@ -6855,81 +7192,63 @@ var RequestError, validateRequestTarget = (target) => {
6855
7192
  outgoing[outgoingEnded]?.();
6856
7193
  }, getRequestListener = (fetchCallback, options = {}) => {
6857
7194
  const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
6858
- if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
6859
- Object.defineProperty(global, "Request", {
6860
- value: Request2
6861
- });
6862
- Object.defineProperty(global, "Response", {
6863
- value: Response2
6864
- });
7195
+ if (options.overrideGlobalObjects !== false && global.Request !== Request$1) {
7196
+ Object.defineProperty(global, "Request", { value: Request$1 });
7197
+ Object.defineProperty(global, "Response", { value: Response$1 });
6865
7198
  }
6866
7199
  return async (incoming, outgoing) => {
6867
7200
  let res, req;
7201
+ let needsBodyCleanup = false;
7202
+ let closeHandlerAttached = false;
7203
+ const ensureCloseHandler = () => {
7204
+ if (!req || closeHandlerAttached)
7205
+ return;
7206
+ closeHandlerAttached = true;
7207
+ outgoing.on("close", makeCloseHandler(req, incoming, outgoing, needsBodyCleanup));
7208
+ };
6868
7209
  try {
6869
7210
  req = newRequest(incoming, options.hostname);
6870
- let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
6871
- if (!incomingEnded) {
7211
+ needsBodyCleanup = autoCleanupIncoming && !(incoming.method === "GET" || incoming.method === "HEAD");
7212
+ if (needsBodyCleanup) {
6872
7213
  incoming[wrapBodyStream] = true;
6873
- incoming.on("end", () => {
6874
- incomingEnded = true;
6875
- });
6876
- if (incoming instanceof Http2ServerRequest2) {
7214
+ if (incoming instanceof Http2ServerRequest)
6877
7215
  outgoing[outgoingEnded] = () => {
6878
- if (!incomingEnded) {
7216
+ if (!incoming.readableEnded)
6879
7217
  setTimeout(() => {
6880
- if (!incomingEnded) {
7218
+ if (!incoming.readableEnded)
6881
7219
  setTimeout(() => {
6882
- drainIncoming(incoming);
7220
+ incoming.destroy();
7221
+ outgoing.destroy();
6883
7222
  });
6884
- }
6885
7223
  });
6886
- }
6887
7224
  };
6888
- }
6889
- outgoing.on("finish", () => {
6890
- if (!incomingEnded) {
6891
- drainIncoming(incoming);
6892
- }
6893
- });
6894
7225
  }
6895
- outgoing.on("close", () => {
6896
- const abortController = req[abortControllerKey];
6897
- if (abortController) {
6898
- if (incoming.errored) {
6899
- req[abortControllerKey].abort(incoming.errored.toString());
6900
- } else if (!outgoing.writableFinished) {
6901
- req[abortControllerKey].abort("Client connection prematurely closed.");
6902
- }
6903
- }
6904
- if (!incomingEnded) {
6905
- setTimeout(() => {
6906
- if (!incomingEnded) {
6907
- setTimeout(() => {
6908
- drainIncoming(incoming);
6909
- });
6910
- }
6911
- });
6912
- }
7226
+ res = fetchCallback(req, {
7227
+ incoming,
7228
+ outgoing
6913
7229
  });
6914
- res = fetchCallback(req, { incoming, outgoing });
6915
- if (cacheKey in res) {
7230
+ if (!isPromise(res) && isImmediateCacheableResponse(res)) {
7231
+ if (needsBodyCleanup && !incoming.readableEnded)
7232
+ outgoing.once("finish", () => {
7233
+ if (!incoming.readableEnded)
7234
+ drainIncoming(incoming);
7235
+ });
6916
7236
  return responseViaCache(res, outgoing);
6917
7237
  }
7238
+ ensureCloseHandler();
6918
7239
  } catch (e) {
6919
- if (!res) {
7240
+ if (!res)
6920
7241
  if (options.errorHandler) {
7242
+ ensureCloseHandler();
6921
7243
  res = await options.errorHandler(req ? e : toRequestError(e));
6922
- if (!res) {
7244
+ if (!res)
6923
7245
  return;
6924
- }
6925
- } else if (!req) {
7246
+ } else if (!req)
6926
7247
  res = handleRequestError();
6927
- } else {
7248
+ else
6928
7249
  res = handleFetchError(e);
6929
- }
6930
- } else {
7250
+ else
6931
7251
  return handleResponseError(e, outgoing);
6932
- }
6933
7252
  }
6934
7253
  try {
6935
7254
  return await responseViaResponseObject(res, outgoing, options);
@@ -6937,37 +7256,201 @@ var RequestError, validateRequestTarget = (target) => {
6937
7256
  return handleResponseError(e, outgoing);
6938
7257
  }
6939
7258
  };
6940
- };
7259
+ }, CloseEvent, ErrorEvent, generateConnectionSymbol = () => Symbol("connection"), CONNECTION_SYMBOL_KEY, WAIT_FOR_WEBSOCKET_SYMBOL, responseHeadersToSkip, upgradeWebSocket;
6941
7260
  var init_dist = __esm(() => {
7261
+ init_constants_BLSFu_RU();
7262
+ init_websocket();
6942
7263
  RequestError = class extends Error {
6943
7264
  constructor(message, options) {
6944
7265
  super(message, options);
6945
7266
  this.name = "RequestError";
6946
7267
  }
6947
7268
  };
7269
+ nonJoinedHeaders = new Set([
7270
+ "age",
7271
+ "authorization",
7272
+ "content-length",
7273
+ "content-type",
7274
+ "etag",
7275
+ "expires",
7276
+ "from",
7277
+ "host",
7278
+ "if-modified-since",
7279
+ "if-unmodified-since",
7280
+ "last-modified",
7281
+ "location",
7282
+ "max-forwards",
7283
+ "proxy-authorization",
7284
+ "referer",
7285
+ "retry-after",
7286
+ "server",
7287
+ "user-agent"
7288
+ ]);
7289
+ validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
7290
+ forbiddenHeaderValue = /[\0\r\n]/;
7291
+ GlobalHeaders = globalThis.Headers;
7292
+ RequestHeaders = class {
7293
+ #incoming;
7294
+ #rawHeaders;
7295
+ #headers;
7296
+ #invalidValue;
7297
+ constructor(incoming) {
7298
+ this.#incoming = incoming;
7299
+ if (incoming instanceof Http2ServerRequest)
7300
+ this.#rawHeaders = incoming.rawHeaders.slice();
7301
+ }
7302
+ get #lazyRawHeaders() {
7303
+ return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
7304
+ }
7305
+ get #native() {
7306
+ if (!this.#headers) {
7307
+ this.#headers = materializeHeaders(this.#lazyRawHeaders);
7308
+ this.#rawHeaders = undefined;
7309
+ }
7310
+ return this.#headers;
7311
+ }
7312
+ #normalizedName(name) {
7313
+ if (typeof name !== "string")
7314
+ return;
7315
+ if (!validHeaderName.test(name))
7316
+ throw new TypeError(`Invalid header name: ${name}`);
7317
+ return name.toLowerCase();
7318
+ }
7319
+ #lookupHttp1(lowerName) {
7320
+ const headers = this.#incoming instanceof Http2ServerRequest ? undefined : this.#incoming.headers;
7321
+ if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__")
7322
+ return;
7323
+ if (!Object.hasOwn(headers, lowerName))
7324
+ return null;
7325
+ const rawValue = headers[lowerName];
7326
+ if (typeof rawValue === "string") {
7327
+ const value = normalizeHeaderValue(rawValue);
7328
+ return forbiddenHeaderValue.test(value) ? undefined : value;
7329
+ }
7330
+ }
7331
+ #lookup(rawHeaders, lowerName) {
7332
+ const separator = lowerName === "cookie" ? "; " : ", ";
7333
+ let value = null;
7334
+ for (let i = 0;i < rawHeaders.length; i += 2) {
7335
+ const rawName = rawHeaders[i];
7336
+ if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
7337
+ const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
7338
+ if (forbiddenHeaderValue.test(rawValue)) {
7339
+ this.#invalidValue = true;
7340
+ return;
7341
+ }
7342
+ value = value === null ? rawValue : value + separator + rawValue;
7343
+ }
7344
+ }
7345
+ return value;
7346
+ }
7347
+ append(name, value) {
7348
+ this.#native.append(name, value);
7349
+ }
7350
+ delete(name) {
7351
+ this.#native.delete(name);
7352
+ }
7353
+ get(name) {
7354
+ const lowerName = this.#normalizedName(name);
7355
+ if (lowerName && !this.#headers && !this.#invalidValue) {
7356
+ const http1Value = this.#lookupHttp1(lowerName);
7357
+ if (http1Value !== undefined)
7358
+ return http1Value;
7359
+ const value = this.#lookup(this.#lazyRawHeaders, lowerName);
7360
+ if (value !== undefined)
7361
+ return value;
7362
+ }
7363
+ return this.#native.get(name);
7364
+ }
7365
+ has(name) {
7366
+ const lowerName = this.#normalizedName(name);
7367
+ if (lowerName && !this.#headers && !this.#invalidValue) {
7368
+ const http1Value = this.#lookupHttp1(lowerName);
7369
+ if (http1Value !== undefined)
7370
+ return http1Value !== null;
7371
+ const value = this.#lookup(this.#lazyRawHeaders, lowerName);
7372
+ if (value !== undefined)
7373
+ return value !== null;
7374
+ }
7375
+ return this.#native.has(name);
7376
+ }
7377
+ set(name, value) {
7378
+ this.#native.set(name, value);
7379
+ }
7380
+ getSetCookie() {
7381
+ return this.#native.getSetCookie();
7382
+ }
7383
+ keys() {
7384
+ return this.#native.keys();
7385
+ }
7386
+ values() {
7387
+ return this.#native.values();
7388
+ }
7389
+ entries() {
7390
+ return this.#native.entries();
7391
+ }
7392
+ forEach(callback, thisArg) {
7393
+ this.#native.forEach((value, key) => {
7394
+ callback.call(thisArg, value, key, this);
7395
+ });
7396
+ }
7397
+ [Symbol.iterator]() {
7398
+ return this.entries();
7399
+ }
7400
+ };
7401
+ Object.defineProperty(RequestHeaders.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
7402
+ return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
7403
+ ...options,
7404
+ depth: depth == null ? null : depth - 1
7405
+ })}`;
7406
+ } });
7407
+ Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
7408
+ reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
7409
+ reDotSegment = /\/\.\.?(?:[/?#]|$)/;
7410
+ reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
6948
7411
  GlobalRequest = global.Request;
6949
- Request2 = class extends GlobalRequest {
7412
+ Request$1 = class extends GlobalRequest {
6950
7413
  constructor(input, options) {
6951
7414
  if (typeof input === "object" && getRequestCache in input) {
7415
+ const hasReplacementBody = options !== undefined && "body" in options && options.body != null;
7416
+ if (input[bodyConsumedDirectlyKey] && !hasReplacementBody)
7417
+ throw new TypeError("Cannot construct a Request with a Request object that has already been used.");
6952
7418
  input = input[getRequestCache]();
6953
7419
  }
6954
- if (typeof options?.body?.getReader !== "undefined") {
7420
+ if (typeof options?.body?.getReader !== "undefined")
6955
7421
  options.duplex ??= "half";
6956
- }
6957
7422
  super(input, options);
6958
7423
  }
6959
7424
  };
6960
7425
  wrapBodyStream = Symbol("wrapBodyStream");
7426
+ byteExactEncodings = new Set([
7427
+ "latin1",
7428
+ "binary",
7429
+ "hex",
7430
+ "base64",
7431
+ "base64url"
7432
+ ]);
7433
+ bodyBufferedBeforeDisconnectKey = Symbol("bodyBufferedBeforeDisconnect");
7434
+ bodyBufferedLengthBeforeDisconnectKey = Symbol("bodyBufferedLengthBeforeDisconnect");
6961
7435
  getRequestCache = Symbol("getRequestCache");
6962
7436
  requestCache = Symbol("requestCache");
6963
7437
  incomingKey = Symbol("incomingKey");
6964
7438
  urlKey = Symbol("urlKey");
7439
+ methodKey = Symbol("methodKey");
6965
7440
  headersKey = Symbol("headersKey");
6966
7441
  abortControllerKey = Symbol("abortControllerKey");
6967
7442
  getAbortController = Symbol("getAbortController");
7443
+ abortRequest = Symbol("abortRequest");
7444
+ bodyBufferKey = Symbol("bodyBuffer");
7445
+ bodyReadPromiseKey = Symbol("bodyReadPromise");
7446
+ bodyConsumedDirectlyKey = Symbol("bodyConsumedDirectly");
7447
+ bodyLockReaderKey = Symbol("bodyLockReader");
7448
+ abortReasonKey = Symbol("abortReason");
7449
+ textDecoder = new TextDecoder;
7450
+ methodTokenRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
6968
7451
  requestPrototype = {
6969
7452
  get method() {
6970
- return this[incomingKey].method || "GET";
7453
+ return this[methodKey];
6971
7454
  },
6972
7455
  get url() {
6973
7456
  return this[urlKey];
@@ -6975,91 +7458,164 @@ var init_dist = __esm(() => {
6975
7458
  get headers() {
6976
7459
  return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
6977
7460
  },
7461
+ [abortRequest](reason) {
7462
+ if (this[abortReasonKey] === undefined)
7463
+ this[abortReasonKey] = reason;
7464
+ const abortController = this[abortControllerKey];
7465
+ if (abortController && !abortController.signal.aborted)
7466
+ abortController.abort(reason);
7467
+ },
6978
7468
  [getAbortController]() {
6979
- this[getRequestCache]();
7469
+ this[abortControllerKey] ||= new AbortController;
7470
+ if (this[abortReasonKey] !== undefined && !this[abortControllerKey].signal.aborted)
7471
+ this[abortControllerKey].abort(this[abortReasonKey]);
6980
7472
  return this[abortControllerKey];
6981
7473
  },
6982
7474
  [getRequestCache]() {
6983
- this[abortControllerKey] ||= new AbortController;
6984
- return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
7475
+ const abortController = this[getAbortController]();
7476
+ if (this[requestCache])
7477
+ return this[requestCache];
7478
+ const method = this.method;
7479
+ if (this[bodyConsumedDirectlyKey] && !(method === "GET" || method === "HEAD")) {
7480
+ this[bodyBufferKey] = undefined;
7481
+ const init = {
7482
+ method: method === "TRACE" ? "GET" : method,
7483
+ headers: this.headers,
7484
+ signal: abortController.signal
7485
+ };
7486
+ if (method !== "TRACE") {
7487
+ init.body = new ReadableStream({ start(c) {
7488
+ c.close();
7489
+ } });
7490
+ init.duplex = "half";
7491
+ }
7492
+ const req = new Request$1(this[urlKey], init);
7493
+ if (method === "TRACE")
7494
+ Object.defineProperty(req, "method", { get() {
7495
+ return "TRACE";
7496
+ } });
7497
+ return this[requestCache] = req;
7498
+ }
7499
+ return this[requestCache] = newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], abortController);
7500
+ },
7501
+ get body() {
7502
+ if (!this[bodyConsumedDirectlyKey])
7503
+ return this[getRequestCache]().body;
7504
+ const request = this[getRequestCache]();
7505
+ if (!this[bodyLockReaderKey] && request.body)
7506
+ this[bodyLockReaderKey] = request.body.getReader();
7507
+ return request.body;
7508
+ },
7509
+ get bodyUsed() {
7510
+ if (this[bodyConsumedDirectlyKey])
7511
+ return true;
7512
+ if (this[requestCache])
7513
+ return this[requestCache].bodyUsed;
7514
+ return false;
6985
7515
  }
6986
7516
  };
7517
+ Object.defineProperty(requestPrototype, "signal", { get() {
7518
+ return this[getAbortController]().signal;
7519
+ } });
6987
7520
  [
6988
- "body",
6989
- "bodyUsed",
6990
7521
  "cache",
6991
7522
  "credentials",
6992
7523
  "destination",
7524
+ "duplex",
6993
7525
  "integrity",
6994
7526
  "mode",
6995
7527
  "redirect",
6996
7528
  "referrer",
6997
7529
  "referrerPolicy",
6998
- "signal",
6999
7530
  "keepalive"
7000
7531
  ].forEach((k) => {
7001
- Object.defineProperty(requestPrototype, k, {
7002
- get() {
7003
- return this[getRequestCache]()[k];
7004
- }
7005
- });
7006
- });
7007
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
7008
- Object.defineProperty(requestPrototype, k, {
7009
- value: function() {
7010
- return this[getRequestCache]()[k]();
7011
- }
7532
+ Object.defineProperty(requestPrototype, k, { get() {
7533
+ return this[getRequestCache]()[k];
7534
+ } });
7535
+ });
7536
+ ["clone", "formData"].forEach((k) => {
7537
+ Object.defineProperty(requestPrototype, k, { value: function() {
7538
+ if (this[bodyConsumedDirectlyKey]) {
7539
+ if (k === "clone")
7540
+ throw newBodyUnusableError();
7541
+ return rejectBodyUnusable();
7542
+ }
7543
+ return this[getRequestCache]()[k]();
7544
+ } });
7545
+ });
7546
+ Object.defineProperty(requestPrototype, "text", { value: function() {
7547
+ return readBodyWithFastPath(this, "text", (buf) => textDecoder.decode(buf));
7548
+ } });
7549
+ Object.defineProperty(requestPrototype, "arrayBuffer", { value: function() {
7550
+ return readBodyWithFastPath(this, "arrayBuffer", (buf) => toArrayBuffer(buf));
7551
+ } });
7552
+ Object.defineProperty(requestPrototype, "blob", { value: function() {
7553
+ return readBodyWithFastPath(this, "blob", (buf, request) => {
7554
+ const type = contentType(request);
7555
+ const init = type ? { headers: { "content-type": type } } : undefined;
7556
+ return new Response(buf, init).blob();
7012
7557
  });
7013
- });
7014
- Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
7015
- value: function(depth, options, inspectFn) {
7016
- const props = {
7017
- method: this.method,
7018
- url: this.url,
7019
- headers: this.headers,
7020
- nativeRequest: this[requestCache]
7021
- };
7022
- return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
7023
- }
7024
- });
7025
- Object.setPrototypeOf(requestPrototype, Request2.prototype);
7558
+ } });
7559
+ Object.defineProperty(requestPrototype, "json", { value: function() {
7560
+ if (this[bodyConsumedDirectlyKey])
7561
+ return rejectBodyUnusable();
7562
+ return this.text().then(JSON.parse);
7563
+ } });
7564
+ Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
7565
+ return `Request (lightweight) ${inspectFn({
7566
+ method: this.method,
7567
+ url: this.url,
7568
+ headers: this.headers,
7569
+ nativeRequest: this[requestCache]
7570
+ }, {
7571
+ ...options,
7572
+ depth: depth == null ? null : depth - 1
7573
+ })}`;
7574
+ } });
7575
+ Object.setPrototypeOf(requestPrototype, Request$1.prototype);
7026
7576
  responseCache = Symbol("responseCache");
7027
7577
  getResponseCache = Symbol("getResponseCache");
7028
7578
  cacheKey = Symbol("cache");
7029
7579
  GlobalResponse = global.Response;
7030
- Response2 = class _Response {
7580
+ Response$1 = class Response$1 {
7031
7581
  #body;
7032
7582
  #init;
7033
7583
  [getResponseCache]() {
7584
+ const cache = this[cacheKey];
7585
+ const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : undefined;
7034
7586
  delete this[cacheKey];
7035
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
7587
+ return this[responseCache] ||= new GlobalResponse(this.#body, liveHeaders ? {
7588
+ status: this.#init?.status,
7589
+ statusText: this.#init?.statusText,
7590
+ headers: liveHeaders
7591
+ } : this.#init);
7036
7592
  }
7037
7593
  constructor(body, init) {
7038
7594
  let headers;
7039
7595
  this.#body = body;
7040
- if (init instanceof _Response) {
7596
+ if (init instanceof GlobalResponse) {
7041
7597
  const cachedGlobalResponse = init[responseCache];
7042
7598
  if (cachedGlobalResponse) {
7043
7599
  this.#init = cachedGlobalResponse;
7044
7600
  this[getResponseCache]();
7045
7601
  return;
7046
- } else {
7047
- this.#init = init.#init;
7048
- headers = new Headers(init.#init.headers);
7049
7602
  }
7050
- } else {
7603
+ this.#init = init instanceof Response$1 ? init.#init : init;
7604
+ headers = new Headers(init.headers);
7605
+ } else
7051
7606
  this.#init = init;
7052
- }
7053
- if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
7054
- this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
7055
- }
7607
+ if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array)
7608
+ this[cacheKey] = [
7609
+ init?.status || 200,
7610
+ body ?? null,
7611
+ headers || init?.headers
7612
+ ];
7056
7613
  }
7057
7614
  get headers() {
7058
7615
  const cache = this[cacheKey];
7059
7616
  if (cache) {
7060
- if (!(cache[2] instanceof Headers)) {
7061
- cache[2] = new Headers(cache[2] || { "content-type": "text/plain; charset=UTF-8" });
7062
- }
7617
+ if (!(cache[2] instanceof Headers))
7618
+ cache[2] = new Headers(cache[2] || (cache[1] === null ? undefined : { "content-type": defaultContentType }));
7063
7619
  return cache[2];
7064
7620
  }
7065
7621
  return this[getResponseCache]().headers;
@@ -7072,39 +7628,219 @@ var init_dist = __esm(() => {
7072
7628
  return status >= 200 && status < 300;
7073
7629
  }
7074
7630
  };
7075
- ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
7076
- Object.defineProperty(Response2.prototype, k, {
7077
- get() {
7078
- return this[getResponseCache]()[k];
7079
- }
7080
- });
7631
+ [
7632
+ "body",
7633
+ "bodyUsed",
7634
+ "redirected",
7635
+ "statusText",
7636
+ "trailers",
7637
+ "type",
7638
+ "url"
7639
+ ].forEach((k) => {
7640
+ Object.defineProperty(Response$1.prototype, k, { get() {
7641
+ return this[getResponseCache]()[k];
7642
+ } });
7081
7643
  });
7082
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
7083
- Object.defineProperty(Response2.prototype, k, {
7084
- value: function() {
7085
- return this[getResponseCache]()[k]();
7086
- }
7087
- });
7644
+ [
7645
+ "arrayBuffer",
7646
+ "blob",
7647
+ "clone",
7648
+ "formData",
7649
+ "json",
7650
+ "text"
7651
+ ].forEach((k) => {
7652
+ Object.defineProperty(Response$1.prototype, k, { value: function() {
7653
+ return this[getResponseCache]()[k]();
7654
+ } });
7655
+ });
7656
+ Object.defineProperty(Response$1.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
7657
+ return `Response (lightweight) ${inspectFn({
7658
+ status: this.status,
7659
+ headers: this.headers,
7660
+ ok: this.ok,
7661
+ nativeResponse: this[responseCache]
7662
+ }, {
7663
+ ...options,
7664
+ depth: depth == null ? null : depth - 1
7665
+ })}`;
7666
+ } });
7667
+ Object.setPrototypeOf(Response$1, GlobalResponse);
7668
+ Object.setPrototypeOf(Response$1.prototype, GlobalResponse.prototype);
7669
+ validRedirectUrl = /^https?:\/\/[!#-;=?-[\]_a-z~A-Z]+$/;
7670
+ validRedirectStatuses = new Set([
7671
+ 301,
7672
+ 302,
7673
+ 303,
7674
+ 307,
7675
+ 308
7676
+ ]);
7677
+ Object.defineProperty(Response$1, "redirect", {
7678
+ value: function redirect(url, status = 302) {
7679
+ if (!validRedirectStatuses.has(status))
7680
+ throw new RangeError("Invalid status code");
7681
+ return new Response$1(null, {
7682
+ status,
7683
+ headers: { location: parseRedirectUrl(url) }
7684
+ });
7685
+ },
7686
+ writable: true,
7687
+ configurable: true
7088
7688
  });
7089
- Object.defineProperty(Response2.prototype, Symbol.for("nodejs.util.inspect.custom"), {
7090
- value: function(depth, options, inspectFn) {
7091
- const props = {
7092
- status: this.status,
7093
- headers: this.headers,
7094
- ok: this.ok,
7095
- nativeResponse: this[responseCache]
7096
- };
7097
- return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
7098
- }
7689
+ Object.defineProperty(Response$1, "json", {
7690
+ value: function json(data, init) {
7691
+ const body = JSON.stringify(data);
7692
+ if (body === undefined)
7693
+ throw new TypeError("The data is not JSON serializable");
7694
+ const initHeaders = init?.headers;
7695
+ let headers;
7696
+ if (initHeaders) {
7697
+ headers = new Headers(initHeaders);
7698
+ if (!headers.has("content-type"))
7699
+ headers.set("content-type", "application/json");
7700
+ } else
7701
+ headers = { "content-type": "application/json" };
7702
+ return new Response$1(body, {
7703
+ status: init?.status ?? 200,
7704
+ statusText: init?.statusText,
7705
+ headers
7706
+ });
7707
+ },
7708
+ writable: true,
7709
+ configurable: true
7099
7710
  });
7100
- Object.setPrototypeOf(Response2, GlobalResponse);
7101
- Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
7102
- if (typeof global.crypto === "undefined") {
7103
- global.crypto = crypto2;
7104
- }
7105
7711
  outgoingEnded = Symbol("outgoingEnded");
7106
7712
  incomingDraining = Symbol("incomingDraining");
7107
7713
  MAX_DRAIN_BYTES = 64 * 1024 * 1024;
7714
+ CloseEvent = globalThis.CloseEvent ?? class extends Event {
7715
+ #eventInitDict;
7716
+ constructor(type, eventInitDict = {}) {
7717
+ super(type, eventInitDict);
7718
+ this.#eventInitDict = eventInitDict;
7719
+ }
7720
+ get wasClean() {
7721
+ return this.#eventInitDict.wasClean ?? false;
7722
+ }
7723
+ get code() {
7724
+ return this.#eventInitDict.code ?? 0;
7725
+ }
7726
+ get reason() {
7727
+ return this.#eventInitDict.reason ?? "";
7728
+ }
7729
+ };
7730
+ ErrorEvent = globalThis.ErrorEvent ?? class extends Event {
7731
+ #eventInitDict;
7732
+ constructor(type, eventInitDict = {}) {
7733
+ super(type, eventInitDict);
7734
+ this.#eventInitDict = eventInitDict;
7735
+ }
7736
+ get message() {
7737
+ return this.#eventInitDict.message ?? "";
7738
+ }
7739
+ get filename() {
7740
+ return this.#eventInitDict.filename ?? "";
7741
+ }
7742
+ get lineno() {
7743
+ return this.#eventInitDict.lineno ?? 0;
7744
+ }
7745
+ get colno() {
7746
+ return this.#eventInitDict.colno ?? 0;
7747
+ }
7748
+ get error() {
7749
+ return this.#eventInitDict.error ?? null;
7750
+ }
7751
+ };
7752
+ CONNECTION_SYMBOL_KEY = Symbol("CONNECTION_SYMBOL_KEY");
7753
+ WAIT_FOR_WEBSOCKET_SYMBOL = Symbol("WAIT_FOR_WEBSOCKET_SYMBOL");
7754
+ responseHeadersToSkip = new Set([
7755
+ "connection",
7756
+ "content-length",
7757
+ "keep-alive",
7758
+ "proxy-authenticate",
7759
+ "proxy-authorization",
7760
+ "te",
7761
+ "trailer",
7762
+ "transfer-encoding",
7763
+ "upgrade",
7764
+ "sec-websocket-accept",
7765
+ "sec-websocket-extensions",
7766
+ "sec-websocket-protocol"
7767
+ ]);
7768
+ upgradeWebSocket = defineWebSocketHelper(async (c, events, options) => {
7769
+ if (c.req.header("upgrade")?.toLowerCase() !== "websocket")
7770
+ return;
7771
+ const env = c.env;
7772
+ const waitForWebSocket = env[WAIT_FOR_WEBSOCKET_SYMBOL];
7773
+ if (!waitForWebSocket || !env.incoming)
7774
+ return new Response(null, { status: 500 });
7775
+ const connectionSymbol = generateConnectionSymbol();
7776
+ env[CONNECTION_SYMBOL_KEY] = connectionSymbol;
7777
+ (async () => {
7778
+ let ws;
7779
+ try {
7780
+ ws = await waitForWebSocket(env.incoming, connectionSymbol);
7781
+ } catch {
7782
+ return;
7783
+ }
7784
+ const messagesReceivedInStarting = [];
7785
+ const bufferMessage = (data, isBinary) => {
7786
+ messagesReceivedInStarting.push([data, isBinary]);
7787
+ };
7788
+ ws.on("message", bufferMessage);
7789
+ const ctx = {
7790
+ binaryType: "arraybuffer",
7791
+ close(code, reason) {
7792
+ ws.close(code, reason);
7793
+ },
7794
+ protocol: ws.protocol,
7795
+ raw: ws,
7796
+ get readyState() {
7797
+ return ws.readyState;
7798
+ },
7799
+ send(source, opts) {
7800
+ ws.send(source, { compress: opts?.compress });
7801
+ },
7802
+ url: new URL(c.req.url)
7803
+ };
7804
+ try {
7805
+ events?.onOpen?.(new Event("open"), ctx);
7806
+ } catch (e) {
7807
+ (options?.onError ?? console.error)(e);
7808
+ }
7809
+ const handleMessage = (data, isBinary) => {
7810
+ const datas = Array.isArray(data) ? data : [data];
7811
+ for (const data of datas)
7812
+ try {
7813
+ events?.onMessage?.(new MessageEvent("message", { data: isBinary ? data instanceof ArrayBuffer ? data : data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength) : typeof data === "string" ? data : Buffer.from(data).toString("utf-8") }), ctx);
7814
+ } catch (e) {
7815
+ (options?.onError ?? console.error)(e);
7816
+ }
7817
+ };
7818
+ ws.off("message", bufferMessage);
7819
+ for (const message of messagesReceivedInStarting)
7820
+ handleMessage(...message);
7821
+ ws.on("message", (data, isBinary) => {
7822
+ handleMessage(data, isBinary);
7823
+ });
7824
+ ws.on("close", (code, reason) => {
7825
+ try {
7826
+ events?.onClose?.(new CloseEvent("close", {
7827
+ code,
7828
+ reason: reason.toString()
7829
+ }), ctx);
7830
+ } catch (e) {
7831
+ (options?.onError ?? console.error)(e);
7832
+ }
7833
+ });
7834
+ ws.on("error", (error) => {
7835
+ try {
7836
+ events?.onError?.(new ErrorEvent("error", { error }), ctx);
7837
+ } catch (e) {
7838
+ (options?.onError ?? console.error)(e);
7839
+ }
7840
+ });
7841
+ })();
7842
+ return new Response;
7843
+ });
7108
7844
  });
7109
7845
 
7110
7846
  // node_modules/content-type/index.js
@@ -27428,7 +28164,7 @@ var require_encodeurl = __commonJS(function(exports, module) {
27428
28164
  * MIT Licensed
27429
28165
  */
27430
28166
  module.exports = encodeUrl;
27431
- var ENCODE_CHARS_REGEXP = /(?:[^\x21\x23-\x3B\x3D\x3F-\x5F\x61-\x7A\x7C\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g;
28167
+ var ENCODE_CHARS_REGEXP = /(?:[^\x21\x23-\x3B\x3D\x3F-\x5F\x61-\x7A\x7C\x7E]+|%+(?![0-9A-Fa-f]{2})){1,1024}/g;
27432
28168
  var SURROGATE_REGEXP = /([\uD800-\uDBFF][\uDC00-\uDFFF])|[\uD800-\uDFFF]/g;
27433
28169
  function encodeUrl(url) {
27434
28170
  return String(url).replace(SURROGATE_REGEXP, function(_, pair) {
@@ -53757,9 +54493,9 @@ var init_config = __esm(() => {
53757
54493
  SDK_METADATA = {
53758
54494
  language: "typescript",
53759
54495
  openapiDocVersion: "1.0.0",
53760
- sdkVersion: "0.4.24",
54496
+ sdkVersion: "0.4.25",
53761
54497
  genVersion: "2.948.4",
53762
- userAgent: "speakeasy-sdk/mcp-typescript 0.4.24 2.948.4 1.0.0 @lightsage/mcp"
54498
+ userAgent: "speakeasy-sdk/mcp-typescript 0.4.25 2.948.4 1.0.0 @lightsage/mcp"
53763
54499
  };
53764
54500
  });
53765
54501
 
@@ -61571,7 +62307,8 @@ var init_publicpluginevalresultsdownload = __esm(() => {
61571
62307
  init_zod();
61572
62308
  PublicPluginEvalResultsDownload$zodSchema = object({
61573
62309
  created_at: datetime2({ offset: true }).nullable().optional().describe("When the results were prepared."),
61574
- download_url: string2().describe("Downloads the zip of the day's runs and their insights report. Call it with the same API key."),
62310
+ download_url: string2().describe('Downloads the zip of the day\'s runs and their insights report. It works without an API key until `expires_at`, so any HTTP client can fetch it, for example `curl -o results.zip "<download_url>"`. List the results again for a new link.'),
62311
+ expires_at: datetime2({ offset: true }).describe("When `download_url` stops working, 15 minutes after the list was requested."),
61575
62312
  filename: string2().nullable().optional().describe("The zip file's name."),
61576
62313
  plugin: string2().describe("The plugin's slug, such as `firecrawl`."),
61577
62314
  prompts: int().nullable().optional().describe("Distinct prompts included in the download."),
@@ -61694,7 +62431,7 @@ var init_pluginEvalsResultsList2 = __esm(() => {
61694
62431
  name: "plugin-evals-results-list",
61695
62432
  description: `List Plugin Eval Results
61696
62433
 
61697
- Returns a day's plugin eval results, one per plugin with results that day. Each has a \`download_url\` for a zip of every run with and without the plugin installed, plus the insights report written from them. Call \`download_url\` with the same API key. Returns 404 when no results exist for the date.`,
62434
+ Returns a day's plugin eval results, one per plugin with results that day. Each has a \`download_url\` for a zip of every run with and without the plugin installed, plus the insights report written from them. The link works without an API key until \`expires_at\` (15 minutes), so fetch it with any HTTP client, for example \`curl -o results.zip "<download_url>"\`. Returns 404 when no results exist for the date.`,
61698
62435
  annotations: {
61699
62436
  title: "",
61700
62437
  destructiveHint: false,
@@ -67265,7 +68002,7 @@ function createMCPServer(deps) {
67265
68002
  sizes: ["any"]
67266
68003
  }],
67267
68004
  name: "LightsageMcp",
67268
- version: "0.4.24"
68005
+ version: "0.4.25"
67269
68006
  });
67270
68007
  const getClient = deps.getSDK || (() => new LightsageMcpCore({
67271
68008
  security: deps.security,
@@ -67802,7 +68539,7 @@ Returns recorded attempts for an Agent Preference eval, newest first, each with
67802
68539
  },
67803
68540
  {
67804
68541
  name: "plugin-evals-results-list",
67805
- description: "List Plugin Eval Results\n\nReturns a day's plugin eval results, one per plugin with results that day. Each has a `download_url` for a zip of every run with and without the plugin installed, plus the insights report written from them. Call `download_url` with the same API key. Returns 404 when no results exist for the date."
68542
+ description: 'List Plugin Eval Results\n\nReturns a day\'s plugin eval results, one per plugin with results that day. Each has a `download_url` for a zip of every run with and without the plugin installed, plus the insights report written from them. The link works without an API key until `expires_at` (15 minutes), so fetch it with any HTTP client, for example `curl -o results.zip "<download_url>"`. Returns 404 when no results exist for the date.'
67806
68543
  },
67807
68544
  {
67808
68545
  name: "agents-list",
@@ -68766,7 +69503,7 @@ http_headers = { "lightsage-api-key-auth" = "YOUR_LIGHTSAGE_API_KEY_AUTH" }`;
68766
69503
  <h1>Instructions</h1>
68767
69504
  <p>One-click installation for Claude Desktop users</p>
68768
69505
  <div class="instruction-item">
68769
- <a href="https://github.com/lightsagehq/mcp/releases/download/v0.4.24/mcp-server.mcpb" download="mcp-server.mcpb" class="action-button header-action" style="display: inline-flex; margin-bottom: 16px;">
69506
+ <a href="https://github.com/lightsagehq/mcp/releases/download/v0.4.25/mcp-server.mcpb" download="mcp-server.mcpb" class="action-button header-action" style="display: inline-flex; margin-bottom: 16px;">
68770
69507
  \uD83D\uDCE5 Download MCP Bundle
68771
69508
  </a>
68772
69509
  </div>
@@ -71666,7 +72403,7 @@ var routes = buildRouteMap({
71666
72403
  var app = buildApplication(routes, {
71667
72404
  name: "mcp",
71668
72405
  versionInfo: {
71669
- currentVersion: "0.4.24"
72406
+ currentVersion: "0.4.25"
71670
72407
  }
71671
72408
  });
71672
72409
  run(app, process3.argv.slice(2), buildContext(process3));
@@ -71674,5 +72411,5 @@ export {
71674
72411
  app
71675
72412
  };
71676
72413
 
71677
- //# debugId=A9E096CF9926E1C264756E2164756E21
72414
+ //# debugId=98ECBEB84095AB7964756E2164756E21
71678
72415
  //# sourceMappingURL=mcp-server.js.map