caplets 0.17.0 → 0.17.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/index.js +549 -129
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -6,15 +6,12 @@ import { execFileSync, spawn } from "node:child_process";
|
|
|
6
6
|
import process$1, { stdin, stdout } from "node:process";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
|
-
import { PassThrough } from "node:stream";
|
|
10
|
-
import { createServer } from "node:http";
|
|
9
|
+
import { PassThrough, Readable } from "node:stream";
|
|
10
|
+
import { STATUS_CODES, createServer } from "node:http";
|
|
11
11
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
12
12
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
13
13
|
import { createInterface } from "node:readline/promises";
|
|
14
|
-
import {
|
|
15
|
-
import { Http2ServerRequest, constants as constants$1 } from "http2";
|
|
16
|
-
import { Readable } from "stream";
|
|
17
|
-
import crypto$1 from "crypto";
|
|
14
|
+
import { Http2ServerRequest, constants as constants$1 } from "node:http2";
|
|
18
15
|
//#region \0rolldown/runtime.js
|
|
19
16
|
var __defProp$1 = Object.defineProperty;
|
|
20
17
|
var __exportAll$1 = (all, no_symbols) => {
|
|
@@ -27,7 +24,7 @@ var __exportAll$1 = (all, no_symbols) => {
|
|
|
27
24
|
return target;
|
|
28
25
|
};
|
|
29
26
|
//#endregion
|
|
30
|
-
//#region ../core/dist/generated-tool-input-schema-
|
|
27
|
+
//#region ../core/dist/generated-tool-input-schema-BYoyY-l-.js
|
|
31
28
|
var _a$1;
|
|
32
29
|
/** A special constant with type `never` */
|
|
33
30
|
const NEVER = /* @__PURE__ */ Object.freeze({ status: "aborted" });
|
|
@@ -4712,7 +4709,7 @@ function generatedToolInputJsonSchema() {
|
|
|
4712
4709
|
return generatedToolInputJsonSchemaForCaplet({ backend: "tool" });
|
|
4713
4710
|
}
|
|
4714
4711
|
//#endregion
|
|
4715
|
-
//#region ../core/dist/options-
|
|
4712
|
+
//#region ../core/dist/options-BqibJVxq.js
|
|
4716
4713
|
var __create = Object.create;
|
|
4717
4714
|
var __defProp = Object.defineProperty;
|
|
4718
4715
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -28835,15 +28832,15 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
|
28835
28832
|
});
|
|
28836
28833
|
};
|
|
28837
28834
|
}
|
|
28838
|
-
let crypto$
|
|
28839
|
-
crypto$
|
|
28835
|
+
let crypto$1;
|
|
28836
|
+
crypto$1 = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m) => m.webcrypto);
|
|
28840
28837
|
/**
|
|
28841
28838
|
* Creates an array of length `size` of random bytes
|
|
28842
28839
|
* @param size
|
|
28843
28840
|
* @returns Array of random ints (0 to 255)
|
|
28844
28841
|
*/
|
|
28845
28842
|
async function getRandomValues(size) {
|
|
28846
|
-
return (await crypto$
|
|
28843
|
+
return (await crypto$1).getRandomValues(new Uint8Array(size));
|
|
28847
28844
|
}
|
|
28848
28845
|
/** Generate cryptographically strong random string
|
|
28849
28846
|
* @param size The desired length of the string
|
|
@@ -28871,7 +28868,7 @@ async function generateVerifier(length) {
|
|
|
28871
28868
|
* @returns The base64 url encoded code challenge
|
|
28872
28869
|
*/
|
|
28873
28870
|
async function generateChallenge(code_verifier) {
|
|
28874
|
-
const buffer = await (await crypto$
|
|
28871
|
+
const buffer = await (await crypto$1).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
28875
28872
|
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
28876
28873
|
}
|
|
28877
28874
|
/** Generate a PKCE challenge pair
|
|
@@ -57628,7 +57625,7 @@ var CapletsEngine = class {
|
|
|
57628
57625
|
}
|
|
57629
57626
|
}
|
|
57630
57627
|
async completeCliWords(words) {
|
|
57631
|
-
const { completeCliWords } = await Promise.resolve().then(() =>
|
|
57628
|
+
const { completeCliWords } = await Promise.resolve().then(() => completion_dbB1hc97_exports).then((n) => n.r);
|
|
57632
57629
|
return await completeCliWords(words, {
|
|
57633
57630
|
config: this.registry.config,
|
|
57634
57631
|
managers: {
|
|
@@ -57966,8 +57963,8 @@ function hasEnv$1(value) {
|
|
|
57966
57963
|
return value !== void 0 && value.trim() !== "";
|
|
57967
57964
|
}
|
|
57968
57965
|
//#endregion
|
|
57969
|
-
//#region ../core/dist/completion-
|
|
57970
|
-
var
|
|
57966
|
+
//#region ../core/dist/completion-dbB1hc97.js
|
|
57967
|
+
var completion_dbB1hc97_exports = /* @__PURE__ */ __exportAll$1({
|
|
57971
57968
|
a: () => formatCapletList,
|
|
57972
57969
|
c: () => resolveCliConfigPaths,
|
|
57973
57970
|
i: () => trailingSpaceCompletionToken,
|
|
@@ -59822,7 +59819,7 @@ const EMPTY_COMPLETION_RESULT = { completion: {
|
|
|
59822
59819
|
values: [],
|
|
59823
59820
|
hasMore: false
|
|
59824
59821
|
} };
|
|
59825
|
-
var version$1 = "0.18.
|
|
59822
|
+
var version$1 = "0.18.1";
|
|
59826
59823
|
var CapletsMcpSession = class {
|
|
59827
59824
|
engine;
|
|
59828
59825
|
server;
|
|
@@ -64827,7 +64824,7 @@ var Hono$1 = class _Hono {
|
|
|
64827
64824
|
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
64828
64825
|
handler[COMPOSED_HANDLER] = r.handler;
|
|
64829
64826
|
}
|
|
64830
|
-
subApp.#addRoute(r.method, r.path, handler);
|
|
64827
|
+
subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
64831
64828
|
});
|
|
64832
64829
|
return this;
|
|
64833
64830
|
}
|
|
@@ -64944,7 +64941,7 @@ var Hono$1 = class _Hono {
|
|
|
64944
64941
|
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
64945
64942
|
return (request) => {
|
|
64946
64943
|
const url = new URL(request.url);
|
|
64947
|
-
url.pathname =
|
|
64944
|
+
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
|
|
64948
64945
|
return new Request(url, request);
|
|
64949
64946
|
};
|
|
64950
64947
|
})();
|
|
@@ -64956,11 +64953,11 @@ var Hono$1 = class _Hono {
|
|
|
64956
64953
|
this.#addRoute("ALL", mergePath(path, "*"), handler);
|
|
64957
64954
|
return this;
|
|
64958
64955
|
}
|
|
64959
|
-
#addRoute(method, path, handler) {
|
|
64956
|
+
#addRoute(method, path, handler, baseRoutePath) {
|
|
64960
64957
|
method = method.toUpperCase();
|
|
64961
64958
|
path = mergePath(this._basePath, path);
|
|
64962
64959
|
const r = {
|
|
64963
|
-
basePath: this._basePath,
|
|
64960
|
+
basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
|
|
64964
64961
|
path,
|
|
64965
64962
|
method,
|
|
64966
64963
|
handler
|
|
@@ -66127,29 +66124,49 @@ var RequestError = class extends Error {
|
|
|
66127
66124
|
this.name = "RequestError";
|
|
66128
66125
|
}
|
|
66129
66126
|
};
|
|
66130
|
-
|
|
66127
|
+
const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
|
|
66128
|
+
const reDotSegment = /\/\.\.?(?:[/?#]|$)/;
|
|
66129
|
+
const reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
|
|
66130
|
+
const buildUrl = (scheme, host, incomingUrl) => {
|
|
66131
|
+
const url = `${scheme}://${host}${incomingUrl}`;
|
|
66132
|
+
if (!reValidHost.test(host)) {
|
|
66133
|
+
const urlObj = new URL(url);
|
|
66134
|
+
if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
|
|
66135
|
+
return urlObj.href;
|
|
66136
|
+
} else if (incomingUrl.length === 0) return url + "/";
|
|
66137
|
+
else {
|
|
66138
|
+
if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
|
|
66139
|
+
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) return new URL(url).href;
|
|
66140
|
+
return url;
|
|
66141
|
+
}
|
|
66142
|
+
};
|
|
66143
|
+
const toRequestError = (e) => {
|
|
66131
66144
|
if (e instanceof RequestError) return e;
|
|
66132
66145
|
return new RequestError(e.message, { cause: e });
|
|
66133
66146
|
};
|
|
66134
|
-
|
|
66147
|
+
const GlobalRequest = global.Request;
|
|
66135
66148
|
var Request$1 = class extends GlobalRequest {
|
|
66136
66149
|
constructor(input, options) {
|
|
66137
|
-
if (typeof input === "object" && getRequestCache in input)
|
|
66138
|
-
|
|
66150
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
66151
|
+
const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
|
|
66152
|
+
if (input[bodyConsumedDirectlyKey] && !hasReplacementBody) throw new TypeError("Cannot construct a Request with a Request object that has already been used.");
|
|
66153
|
+
input = input[getRequestCache]();
|
|
66154
|
+
}
|
|
66155
|
+
if (typeof (options?.body)?.getReader !== "undefined") options.duplex ??= "half";
|
|
66139
66156
|
super(input, options);
|
|
66140
66157
|
}
|
|
66141
66158
|
};
|
|
66142
|
-
|
|
66159
|
+
const newHeadersFromIncoming = (incoming) => {
|
|
66143
66160
|
const headerRecord = [];
|
|
66144
66161
|
const rawHeaders = incoming.rawHeaders;
|
|
66145
|
-
for (let i = 0
|
|
66146
|
-
const
|
|
66147
|
-
if (key.charCodeAt(0) !== 58) headerRecord.push([key,
|
|
66162
|
+
for (let i = 0, len = rawHeaders.length; i < len; i += 2) {
|
|
66163
|
+
const key = rawHeaders[i];
|
|
66164
|
+
if (key.charCodeAt(0) !== 58) headerRecord.push([key, rawHeaders[i + 1]]);
|
|
66148
66165
|
}
|
|
66149
66166
|
return new Headers(headerRecord);
|
|
66150
66167
|
};
|
|
66151
|
-
|
|
66152
|
-
|
|
66168
|
+
const wrapBodyStream = Symbol("wrapBodyStream");
|
|
66169
|
+
const newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
66153
66170
|
const init = {
|
|
66154
66171
|
method,
|
|
66155
66172
|
headers,
|
|
@@ -66182,15 +66199,162 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
66182
66199
|
} else init.body = Readable.toWeb(incoming);
|
|
66183
66200
|
return new Request$1(url, init);
|
|
66184
66201
|
};
|
|
66185
|
-
|
|
66186
|
-
|
|
66187
|
-
|
|
66188
|
-
|
|
66189
|
-
|
|
66190
|
-
|
|
66191
|
-
|
|
66202
|
+
const getRequestCache = Symbol("getRequestCache");
|
|
66203
|
+
const requestCache = Symbol("requestCache");
|
|
66204
|
+
const incomingKey = Symbol("incomingKey");
|
|
66205
|
+
const urlKey = Symbol("urlKey");
|
|
66206
|
+
const methodKey = Symbol("methodKey");
|
|
66207
|
+
const headersKey = Symbol("headersKey");
|
|
66208
|
+
const abortControllerKey = Symbol("abortControllerKey");
|
|
66209
|
+
const getAbortController = Symbol("getAbortController");
|
|
66210
|
+
const abortRequest = Symbol("abortRequest");
|
|
66211
|
+
const bodyBufferKey = Symbol("bodyBuffer");
|
|
66212
|
+
const bodyReadPromiseKey = Symbol("bodyReadPromise");
|
|
66213
|
+
const bodyConsumedDirectlyKey = Symbol("bodyConsumedDirectly");
|
|
66214
|
+
const bodyLockReaderKey = Symbol("bodyLockReader");
|
|
66215
|
+
const abortReasonKey = Symbol("abortReason");
|
|
66216
|
+
const newBodyUnusableError = () => {
|
|
66217
|
+
return /* @__PURE__ */ new TypeError("Body is unusable");
|
|
66218
|
+
};
|
|
66219
|
+
const rejectBodyUnusable = () => {
|
|
66220
|
+
return Promise.reject(newBodyUnusableError());
|
|
66221
|
+
};
|
|
66222
|
+
const textDecoder = new TextDecoder();
|
|
66223
|
+
const consumeBodyDirectOnce = (request) => {
|
|
66224
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
66225
|
+
request[bodyConsumedDirectlyKey] = true;
|
|
66226
|
+
};
|
|
66227
|
+
const toArrayBuffer = (buf) => {
|
|
66228
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
66229
|
+
};
|
|
66230
|
+
const contentType = (request) => {
|
|
66231
|
+
return (request[headersKey] ||= newHeadersFromIncoming(request[incomingKey])).get("content-type") || "";
|
|
66232
|
+
};
|
|
66233
|
+
const methodTokenRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
66234
|
+
const normalizeIncomingMethod = (method) => {
|
|
66235
|
+
if (typeof method !== "string" || method.length === 0) return "GET";
|
|
66236
|
+
switch (method) {
|
|
66237
|
+
case "DELETE":
|
|
66238
|
+
case "GET":
|
|
66239
|
+
case "HEAD":
|
|
66240
|
+
case "OPTIONS":
|
|
66241
|
+
case "POST":
|
|
66242
|
+
case "PUT": return method;
|
|
66243
|
+
}
|
|
66244
|
+
const upper = method.toUpperCase();
|
|
66245
|
+
switch (upper) {
|
|
66246
|
+
case "DELETE":
|
|
66247
|
+
case "GET":
|
|
66248
|
+
case "HEAD":
|
|
66249
|
+
case "OPTIONS":
|
|
66250
|
+
case "POST":
|
|
66251
|
+
case "PUT": return upper;
|
|
66252
|
+
default: return method;
|
|
66253
|
+
}
|
|
66254
|
+
};
|
|
66255
|
+
const validateDirectReadMethod = (method) => {
|
|
66256
|
+
if (!methodTokenRegExp.test(method)) return /* @__PURE__ */ new TypeError(`'${method}' is not a valid HTTP method.`);
|
|
66257
|
+
const normalized = method.toUpperCase();
|
|
66258
|
+
if (normalized === "CONNECT" || normalized === "TRACK" || normalized === "TRACE" && method !== "TRACE") return /* @__PURE__ */ new TypeError(`'${method}' HTTP method is unsupported.`);
|
|
66259
|
+
};
|
|
66260
|
+
const readBodyWithFastPath = (request, method, fromBuffer) => {
|
|
66261
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
66262
|
+
const methodName = request.method;
|
|
66263
|
+
if (methodName === "GET" || methodName === "HEAD") return request[getRequestCache]()[method]();
|
|
66264
|
+
const methodValidationError = validateDirectReadMethod(methodName);
|
|
66265
|
+
if (methodValidationError) return Promise.reject(methodValidationError);
|
|
66266
|
+
if (request[requestCache]) {
|
|
66267
|
+
if (methodName !== "TRACE") return request[requestCache][method]();
|
|
66268
|
+
}
|
|
66269
|
+
const alreadyUsedError = consumeBodyDirectOnce(request);
|
|
66270
|
+
if (alreadyUsedError) return alreadyUsedError;
|
|
66271
|
+
const raw = readRawBodyIfAvailable(request);
|
|
66272
|
+
if (raw) {
|
|
66273
|
+
const result = Promise.resolve(fromBuffer(raw, request));
|
|
66274
|
+
request[bodyBufferKey] = void 0;
|
|
66275
|
+
return result;
|
|
66276
|
+
}
|
|
66277
|
+
return readBodyDirect(request).then((buf) => {
|
|
66278
|
+
const result = fromBuffer(buf, request);
|
|
66279
|
+
request[bodyBufferKey] = void 0;
|
|
66280
|
+
return result;
|
|
66281
|
+
});
|
|
66282
|
+
};
|
|
66283
|
+
const readRawBodyIfAvailable = (request) => {
|
|
66284
|
+
const incoming = request[incomingKey];
|
|
66285
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) return incoming.rawBody;
|
|
66286
|
+
};
|
|
66287
|
+
const readBodyDirect = (request) => {
|
|
66288
|
+
if (request[bodyBufferKey]) return Promise.resolve(request[bodyBufferKey]);
|
|
66289
|
+
if (request[bodyReadPromiseKey]) return request[bodyReadPromiseKey];
|
|
66290
|
+
const incoming = request[incomingKey];
|
|
66291
|
+
if (Readable.isDisturbed(incoming)) return rejectBodyUnusable();
|
|
66292
|
+
const promise = new Promise((resolve, reject) => {
|
|
66293
|
+
const chunks = [];
|
|
66294
|
+
let settled = false;
|
|
66295
|
+
const finish = (callback) => {
|
|
66296
|
+
if (settled) return;
|
|
66297
|
+
settled = true;
|
|
66298
|
+
cleanup();
|
|
66299
|
+
callback();
|
|
66300
|
+
};
|
|
66301
|
+
const onData = (chunk) => {
|
|
66302
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
66303
|
+
};
|
|
66304
|
+
const onEnd = () => {
|
|
66305
|
+
finish(() => {
|
|
66306
|
+
const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
|
|
66307
|
+
request[bodyBufferKey] = buffer;
|
|
66308
|
+
resolve(buffer);
|
|
66309
|
+
});
|
|
66310
|
+
};
|
|
66311
|
+
const onError = (error) => {
|
|
66312
|
+
finish(() => {
|
|
66313
|
+
reject(error);
|
|
66314
|
+
});
|
|
66315
|
+
};
|
|
66316
|
+
const onClose = () => {
|
|
66317
|
+
if (incoming.readableEnded) {
|
|
66318
|
+
onEnd();
|
|
66319
|
+
return;
|
|
66320
|
+
}
|
|
66321
|
+
finish(() => {
|
|
66322
|
+
if (incoming.errored) {
|
|
66323
|
+
reject(incoming.errored);
|
|
66324
|
+
return;
|
|
66325
|
+
}
|
|
66326
|
+
const reason = request[abortReasonKey];
|
|
66327
|
+
if (reason !== void 0) {
|
|
66328
|
+
reject(reason instanceof Error ? reason : new Error(String(reason)));
|
|
66329
|
+
return;
|
|
66330
|
+
}
|
|
66331
|
+
reject(/* @__PURE__ */ new Error("Client connection prematurely closed."));
|
|
66332
|
+
});
|
|
66333
|
+
};
|
|
66334
|
+
const cleanup = () => {
|
|
66335
|
+
incoming.off("data", onData);
|
|
66336
|
+
incoming.off("end", onEnd);
|
|
66337
|
+
incoming.off("error", onError);
|
|
66338
|
+
incoming.off("close", onClose);
|
|
66339
|
+
request[bodyReadPromiseKey] = void 0;
|
|
66340
|
+
};
|
|
66341
|
+
incoming.on("data", onData);
|
|
66342
|
+
incoming.on("end", onEnd);
|
|
66343
|
+
incoming.on("error", onError);
|
|
66344
|
+
incoming.on("close", onClose);
|
|
66345
|
+
queueMicrotask(() => {
|
|
66346
|
+
if (settled) return;
|
|
66347
|
+
if (incoming.readableEnded) onEnd();
|
|
66348
|
+
else if (incoming.errored) onError(incoming.errored);
|
|
66349
|
+
else if (incoming.destroyed) onClose();
|
|
66350
|
+
});
|
|
66351
|
+
});
|
|
66352
|
+
request[bodyReadPromiseKey] = promise;
|
|
66353
|
+
return promise;
|
|
66354
|
+
};
|
|
66355
|
+
const requestPrototype = {
|
|
66192
66356
|
get method() {
|
|
66193
|
-
return this[
|
|
66357
|
+
return this[methodKey];
|
|
66194
66358
|
},
|
|
66195
66359
|
get url() {
|
|
66196
66360
|
return this[urlKey];
|
|
@@ -66198,18 +66362,57 @@ var requestPrototype = {
|
|
|
66198
66362
|
get headers() {
|
|
66199
66363
|
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
66200
66364
|
},
|
|
66201
|
-
[
|
|
66202
|
-
this[
|
|
66365
|
+
[abortRequest](reason) {
|
|
66366
|
+
if (this[abortReasonKey] === void 0) this[abortReasonKey] = reason;
|
|
66367
|
+
const abortController = this[abortControllerKey];
|
|
66368
|
+
if (abortController && !abortController.signal.aborted) abortController.abort(reason);
|
|
66369
|
+
},
|
|
66370
|
+
[getAbortController]() {
|
|
66371
|
+
this[abortControllerKey] ||= new AbortController();
|
|
66372
|
+
if (this[abortReasonKey] !== void 0 && !this[abortControllerKey].signal.aborted) this[abortControllerKey].abort(this[abortReasonKey]);
|
|
66203
66373
|
return this[abortControllerKey];
|
|
66204
66374
|
},
|
|
66205
66375
|
[getRequestCache]() {
|
|
66206
|
-
this[
|
|
66207
|
-
|
|
66376
|
+
const abortController = this[getAbortController]();
|
|
66377
|
+
if (this[requestCache]) return this[requestCache];
|
|
66378
|
+
const method = this.method;
|
|
66379
|
+
if (this[bodyConsumedDirectlyKey] && !(method === "GET" || method === "HEAD")) {
|
|
66380
|
+
this[bodyBufferKey] = void 0;
|
|
66381
|
+
const init = {
|
|
66382
|
+
method: method === "TRACE" ? "GET" : method,
|
|
66383
|
+
headers: this.headers,
|
|
66384
|
+
signal: abortController.signal
|
|
66385
|
+
};
|
|
66386
|
+
if (method !== "TRACE") {
|
|
66387
|
+
init.body = new ReadableStream({ start(c) {
|
|
66388
|
+
c.close();
|
|
66389
|
+
} });
|
|
66390
|
+
init.duplex = "half";
|
|
66391
|
+
}
|
|
66392
|
+
const req = new Request$1(this[urlKey], init);
|
|
66393
|
+
if (method === "TRACE") Object.defineProperty(req, "method", { get() {
|
|
66394
|
+
return "TRACE";
|
|
66395
|
+
} });
|
|
66396
|
+
return this[requestCache] = req;
|
|
66397
|
+
}
|
|
66398
|
+
return this[requestCache] = newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], abortController);
|
|
66399
|
+
},
|
|
66400
|
+
get body() {
|
|
66401
|
+
if (!this[bodyConsumedDirectlyKey]) return this[getRequestCache]().body;
|
|
66402
|
+
const request = this[getRequestCache]();
|
|
66403
|
+
if (!this[bodyLockReaderKey] && request.body) this[bodyLockReaderKey] = request.body.getReader();
|
|
66404
|
+
return request.body;
|
|
66405
|
+
},
|
|
66406
|
+
get bodyUsed() {
|
|
66407
|
+
if (this[bodyConsumedDirectlyKey]) return true;
|
|
66408
|
+
if (this[requestCache]) return this[requestCache].bodyUsed;
|
|
66409
|
+
return false;
|
|
66208
66410
|
}
|
|
66209
66411
|
};
|
|
66412
|
+
Object.defineProperty(requestPrototype, "signal", { get() {
|
|
66413
|
+
return this[getAbortController]().signal;
|
|
66414
|
+
} });
|
|
66210
66415
|
[
|
|
66211
|
-
"body",
|
|
66212
|
-
"bodyUsed",
|
|
66213
66416
|
"cache",
|
|
66214
66417
|
"credentials",
|
|
66215
66418
|
"destination",
|
|
@@ -66218,25 +66421,37 @@ var requestPrototype = {
|
|
|
66218
66421
|
"redirect",
|
|
66219
66422
|
"referrer",
|
|
66220
66423
|
"referrerPolicy",
|
|
66221
|
-
"signal",
|
|
66222
66424
|
"keepalive"
|
|
66223
66425
|
].forEach((k) => {
|
|
66224
66426
|
Object.defineProperty(requestPrototype, k, { get() {
|
|
66225
66427
|
return this[getRequestCache]()[k];
|
|
66226
66428
|
} });
|
|
66227
66429
|
});
|
|
66228
|
-
[
|
|
66229
|
-
"arrayBuffer",
|
|
66230
|
-
"blob",
|
|
66231
|
-
"clone",
|
|
66232
|
-
"formData",
|
|
66233
|
-
"json",
|
|
66234
|
-
"text"
|
|
66235
|
-
].forEach((k) => {
|
|
66430
|
+
["clone", "formData"].forEach((k) => {
|
|
66236
66431
|
Object.defineProperty(requestPrototype, k, { value: function() {
|
|
66432
|
+
if (this[bodyConsumedDirectlyKey]) {
|
|
66433
|
+
if (k === "clone") throw newBodyUnusableError();
|
|
66434
|
+
return rejectBodyUnusable();
|
|
66435
|
+
}
|
|
66237
66436
|
return this[getRequestCache]()[k]();
|
|
66238
66437
|
} });
|
|
66239
66438
|
});
|
|
66439
|
+
Object.defineProperty(requestPrototype, "text", { value: function() {
|
|
66440
|
+
return readBodyWithFastPath(this, "text", (buf) => textDecoder.decode(buf));
|
|
66441
|
+
} });
|
|
66442
|
+
Object.defineProperty(requestPrototype, "arrayBuffer", { value: function() {
|
|
66443
|
+
return readBodyWithFastPath(this, "arrayBuffer", (buf) => toArrayBuffer(buf));
|
|
66444
|
+
} });
|
|
66445
|
+
Object.defineProperty(requestPrototype, "blob", { value: function() {
|
|
66446
|
+
return readBodyWithFastPath(this, "blob", (buf, request) => {
|
|
66447
|
+
const type = contentType(request);
|
|
66448
|
+
return new Response(buf, type ? { headers: { "content-type": type } } : void 0).blob();
|
|
66449
|
+
});
|
|
66450
|
+
} });
|
|
66451
|
+
Object.defineProperty(requestPrototype, "json", { value: function() {
|
|
66452
|
+
if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
66453
|
+
return this.text().then(JSON.parse);
|
|
66454
|
+
} });
|
|
66240
66455
|
Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
|
|
66241
66456
|
return `Request (lightweight) ${inspectFn({
|
|
66242
66457
|
method: this.method,
|
|
@@ -66249,9 +66464,10 @@ Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom")
|
|
|
66249
66464
|
})}`;
|
|
66250
66465
|
} });
|
|
66251
66466
|
Object.setPrototypeOf(requestPrototype, Request$1.prototype);
|
|
66252
|
-
|
|
66467
|
+
const newRequest = (incoming, defaultHostname) => {
|
|
66253
66468
|
const req = Object.create(requestPrototype);
|
|
66254
66469
|
req[incomingKey] = incoming;
|
|
66470
|
+
req[methodKey] = normalizeIncomingMethod(incoming.method);
|
|
66255
66471
|
const incomingUrl = incoming.url || "";
|
|
66256
66472
|
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
66257
66473
|
if (incoming instanceof Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
@@ -66269,26 +66485,35 @@ var newRequest = (incoming, defaultHostname) => {
|
|
|
66269
66485
|
scheme = incoming.scheme;
|
|
66270
66486
|
if (!(scheme === "http" || scheme === "https")) throw new RequestError("Unsupported scheme");
|
|
66271
66487
|
} else scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
66272
|
-
|
|
66273
|
-
|
|
66274
|
-
|
|
66488
|
+
try {
|
|
66489
|
+
req[urlKey] = buildUrl(scheme, host, incomingUrl);
|
|
66490
|
+
} catch (e) {
|
|
66491
|
+
if (e instanceof RequestError) throw e;
|
|
66492
|
+
else throw new RequestError("Invalid URL", { cause: e });
|
|
66493
|
+
}
|
|
66275
66494
|
return req;
|
|
66276
66495
|
};
|
|
66277
|
-
|
|
66278
|
-
|
|
66279
|
-
|
|
66280
|
-
|
|
66281
|
-
|
|
66496
|
+
const defaultContentType = "text/plain; charset=UTF-8";
|
|
66497
|
+
const responseCache = Symbol("responseCache");
|
|
66498
|
+
const getResponseCache = Symbol("getResponseCache");
|
|
66499
|
+
const cacheKey = Symbol("cache");
|
|
66500
|
+
const GlobalResponse = global.Response;
|
|
66501
|
+
var Response$1 = class Response$1 {
|
|
66282
66502
|
#body;
|
|
66283
66503
|
#init;
|
|
66284
66504
|
[getResponseCache]() {
|
|
66505
|
+
const cache = this[cacheKey];
|
|
66506
|
+
const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
|
|
66285
66507
|
delete this[cacheKey];
|
|
66286
|
-
return this[responseCache] ||= new GlobalResponse(this.#body,
|
|
66508
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, liveHeaders ? {
|
|
66509
|
+
...this.#init,
|
|
66510
|
+
headers: liveHeaders
|
|
66511
|
+
} : this.#init);
|
|
66287
66512
|
}
|
|
66288
66513
|
constructor(body, init) {
|
|
66289
66514
|
let headers;
|
|
66290
66515
|
this.#body = body;
|
|
66291
|
-
if (init instanceof
|
|
66516
|
+
if (init instanceof Response$1) {
|
|
66292
66517
|
const cachedGlobalResponse = init[responseCache];
|
|
66293
66518
|
if (cachedGlobalResponse) {
|
|
66294
66519
|
this.#init = cachedGlobalResponse;
|
|
@@ -66296,19 +66521,19 @@ var Response2 = class _Response {
|
|
|
66296
66521
|
return;
|
|
66297
66522
|
} else {
|
|
66298
66523
|
this.#init = init.#init;
|
|
66299
|
-
headers = new Headers(init
|
|
66524
|
+
headers = new Headers(init.headers);
|
|
66300
66525
|
}
|
|
66301
66526
|
} else this.#init = init;
|
|
66302
|
-
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
66527
|
+
if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
66303
66528
|
init?.status || 200,
|
|
66304
|
-
body,
|
|
66529
|
+
body ?? null,
|
|
66305
66530
|
headers || init?.headers
|
|
66306
66531
|
];
|
|
66307
66532
|
}
|
|
66308
66533
|
get headers() {
|
|
66309
66534
|
const cache = this[cacheKey];
|
|
66310
66535
|
if (cache) {
|
|
66311
|
-
if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2] || { "content-type":
|
|
66536
|
+
if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2] || (cache[1] === null ? void 0 : { "content-type": defaultContentType }));
|
|
66312
66537
|
return cache[2];
|
|
66313
66538
|
}
|
|
66314
66539
|
return this[getResponseCache]().headers;
|
|
@@ -66330,7 +66555,7 @@ var Response2 = class _Response {
|
|
|
66330
66555
|
"type",
|
|
66331
66556
|
"url"
|
|
66332
66557
|
].forEach((k) => {
|
|
66333
|
-
Object.defineProperty(
|
|
66558
|
+
Object.defineProperty(Response$1.prototype, k, { get() {
|
|
66334
66559
|
return this[getResponseCache]()[k];
|
|
66335
66560
|
} });
|
|
66336
66561
|
});
|
|
@@ -66342,11 +66567,11 @@ var Response2 = class _Response {
|
|
|
66342
66567
|
"json",
|
|
66343
66568
|
"text"
|
|
66344
66569
|
].forEach((k) => {
|
|
66345
|
-
Object.defineProperty(
|
|
66570
|
+
Object.defineProperty(Response$1.prototype, k, { value: function() {
|
|
66346
66571
|
return this[getResponseCache]()[k]();
|
|
66347
66572
|
} });
|
|
66348
66573
|
});
|
|
66349
|
-
Object.defineProperty(
|
|
66574
|
+
Object.defineProperty(Response$1.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
|
|
66350
66575
|
return `Response (lightweight) ${inspectFn({
|
|
66351
66576
|
status: this.status,
|
|
66352
66577
|
headers: this.headers,
|
|
@@ -66357,8 +66582,51 @@ Object.defineProperty(Response2.prototype, Symbol.for("nodejs.util.inspect.custo
|
|
|
66357
66582
|
depth: depth == null ? null : depth - 1
|
|
66358
66583
|
})}`;
|
|
66359
66584
|
} });
|
|
66360
|
-
Object.setPrototypeOf(
|
|
66361
|
-
Object.setPrototypeOf(
|
|
66585
|
+
Object.setPrototypeOf(Response$1, GlobalResponse);
|
|
66586
|
+
Object.setPrototypeOf(Response$1.prototype, GlobalResponse.prototype);
|
|
66587
|
+
const validRedirectUrl = /^https?:\/\/[!#-;=?-[\]_a-z~A-Z]+$/;
|
|
66588
|
+
const parseRedirectUrl = (url) => {
|
|
66589
|
+
if (url instanceof URL) return url.href;
|
|
66590
|
+
if (validRedirectUrl.test(url)) return url;
|
|
66591
|
+
return new URL(url).href;
|
|
66592
|
+
};
|
|
66593
|
+
const validRedirectStatuses = new Set([
|
|
66594
|
+
301,
|
|
66595
|
+
302,
|
|
66596
|
+
303,
|
|
66597
|
+
307,
|
|
66598
|
+
308
|
|
66599
|
+
]);
|
|
66600
|
+
Object.defineProperty(Response$1, "redirect", {
|
|
66601
|
+
value: function redirect(url, status = 302) {
|
|
66602
|
+
if (!validRedirectStatuses.has(status)) throw new RangeError("Invalid status code");
|
|
66603
|
+
return new Response$1(null, {
|
|
66604
|
+
status,
|
|
66605
|
+
headers: { location: parseRedirectUrl(url) }
|
|
66606
|
+
});
|
|
66607
|
+
},
|
|
66608
|
+
writable: true,
|
|
66609
|
+
configurable: true
|
|
66610
|
+
});
|
|
66611
|
+
Object.defineProperty(Response$1, "json", {
|
|
66612
|
+
value: function json(data, init) {
|
|
66613
|
+
const body = JSON.stringify(data);
|
|
66614
|
+
if (body === void 0) throw new TypeError("The data is not JSON serializable");
|
|
66615
|
+
const initHeaders = init?.headers;
|
|
66616
|
+
let headers;
|
|
66617
|
+
if (initHeaders) {
|
|
66618
|
+
headers = new Headers(initHeaders);
|
|
66619
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
66620
|
+
} else headers = { "content-type": "application/json" };
|
|
66621
|
+
return new Response$1(body, {
|
|
66622
|
+
status: init?.status ?? 200,
|
|
66623
|
+
statusText: init?.statusText,
|
|
66624
|
+
headers
|
|
66625
|
+
});
|
|
66626
|
+
},
|
|
66627
|
+
writable: true,
|
|
66628
|
+
configurable: true
|
|
66629
|
+
});
|
|
66362
66630
|
async function readWithoutBlocking(readPromise) {
|
|
66363
66631
|
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
66364
66632
|
}
|
|
@@ -66394,23 +66662,23 @@ function writeFromReadableStream(stream, writable) {
|
|
|
66394
66662
|
else if (writable.destroyed) return;
|
|
66395
66663
|
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
66396
66664
|
}
|
|
66397
|
-
|
|
66665
|
+
const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
66398
66666
|
const res = {};
|
|
66399
66667
|
if (!(headers instanceof Headers)) headers = new Headers(headers ?? void 0);
|
|
66400
|
-
|
|
66401
|
-
|
|
66402
|
-
|
|
66403
|
-
|
|
66404
|
-
|
|
66668
|
+
if (headers.has("set-cookie")) {
|
|
66669
|
+
const cookies = [];
|
|
66670
|
+
for (const [k, v] of headers) if (k === "set-cookie") cookies.push(v);
|
|
66671
|
+
else res[k] = v;
|
|
66672
|
+
if (cookies.length > 0) res["set-cookie"] = cookies;
|
|
66673
|
+
} else for (const [k, v] of headers) res[k] = v;
|
|
66674
|
+
if (defaultContentType) res["content-type"] ??= defaultContentType;
|
|
66405
66675
|
return res;
|
|
66406
66676
|
};
|
|
66407
|
-
|
|
66408
|
-
|
|
66409
|
-
|
|
66410
|
-
|
|
66411
|
-
|
|
66412
|
-
var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
|
|
66413
|
-
var drainIncoming = (incoming) => {
|
|
66677
|
+
const outgoingEnded = Symbol("outgoingEnded");
|
|
66678
|
+
const incomingDraining = Symbol("incomingDraining");
|
|
66679
|
+
const DRAIN_TIMEOUT_MS = 500;
|
|
66680
|
+
const MAX_DRAIN_BYTES = 64 * 1024 * 1024;
|
|
66681
|
+
const drainIncoming = (incoming) => {
|
|
66414
66682
|
const incomingWithDrainState = incoming;
|
|
66415
66683
|
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
66416
66684
|
incomingWithDrainState[incomingDraining] = true;
|
|
@@ -66443,9 +66711,23 @@ var drainIncoming = (incoming) => {
|
|
|
66443
66711
|
incoming.on("error", cleanup);
|
|
66444
66712
|
incoming.resume();
|
|
66445
66713
|
};
|
|
66446
|
-
|
|
66447
|
-
|
|
66448
|
-
|
|
66714
|
+
const makeCloseHandler = (req, incoming, outgoing, needsBodyCleanup) => () => {
|
|
66715
|
+
if (incoming.errored) req[abortRequest](incoming.errored.toString());
|
|
66716
|
+
else if (!outgoing.writableFinished) req[abortRequest]("Client connection prematurely closed.");
|
|
66717
|
+
if (needsBodyCleanup && !incoming.readableEnded) setTimeout(() => {
|
|
66718
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
66719
|
+
drainIncoming(incoming);
|
|
66720
|
+
});
|
|
66721
|
+
});
|
|
66722
|
+
};
|
|
66723
|
+
const isImmediateCacheableResponse = (res) => {
|
|
66724
|
+
if (!(cacheKey in res)) return false;
|
|
66725
|
+
const body = res[cacheKey][1];
|
|
66726
|
+
return body === null || typeof body === "string" || body instanceof Uint8Array;
|
|
66727
|
+
};
|
|
66728
|
+
const handleRequestError = () => new Response(null, { status: 400 });
|
|
66729
|
+
const handleFetchError = (e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 });
|
|
66730
|
+
const handleResponseError = (e, outgoing) => {
|
|
66449
66731
|
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
66450
66732
|
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
|
|
66451
66733
|
else {
|
|
@@ -66455,20 +66737,49 @@ var handleResponseError = (e, outgoing) => {
|
|
|
66455
66737
|
outgoing.destroy(err);
|
|
66456
66738
|
}
|
|
66457
66739
|
};
|
|
66458
|
-
|
|
66740
|
+
const flushHeaders = (outgoing) => {
|
|
66459
66741
|
if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
|
|
66460
66742
|
};
|
|
66461
|
-
|
|
66743
|
+
const responseViaCache = async (res, outgoing) => {
|
|
66462
66744
|
let [status, body, header] = res[cacheKey];
|
|
66745
|
+
if (!header) {
|
|
66746
|
+
if (body === null) {
|
|
66747
|
+
outgoing.writeHead(status);
|
|
66748
|
+
outgoing.end();
|
|
66749
|
+
} else if (typeof body === "string") {
|
|
66750
|
+
outgoing.writeHead(status, {
|
|
66751
|
+
"Content-Type": defaultContentType,
|
|
66752
|
+
"Content-Length": Buffer.byteLength(body)
|
|
66753
|
+
});
|
|
66754
|
+
outgoing.end(body);
|
|
66755
|
+
} else if (body instanceof Uint8Array) {
|
|
66756
|
+
outgoing.writeHead(status, {
|
|
66757
|
+
"Content-Type": defaultContentType,
|
|
66758
|
+
"Content-Length": body.byteLength
|
|
66759
|
+
});
|
|
66760
|
+
outgoing.end(body);
|
|
66761
|
+
} else if (body instanceof Blob) {
|
|
66762
|
+
outgoing.writeHead(status, {
|
|
66763
|
+
"Content-Type": defaultContentType,
|
|
66764
|
+
"Content-Length": body.size
|
|
66765
|
+
});
|
|
66766
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
66767
|
+
} else {
|
|
66768
|
+
outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
66769
|
+
flushHeaders(outgoing);
|
|
66770
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
66771
|
+
}
|
|
66772
|
+
outgoing[outgoingEnded]?.();
|
|
66773
|
+
return;
|
|
66774
|
+
}
|
|
66463
66775
|
let hasContentLength = false;
|
|
66464
|
-
if (
|
|
66465
|
-
else if (header instanceof Headers) {
|
|
66776
|
+
if (header instanceof Headers) {
|
|
66466
66777
|
hasContentLength = header.has("content-length");
|
|
66467
|
-
header = buildOutgoingHttpHeaders(header);
|
|
66778
|
+
header = buildOutgoingHttpHeaders(header, body === null ? void 0 : defaultContentType);
|
|
66468
66779
|
} else if (Array.isArray(header)) {
|
|
66469
66780
|
const headerObj = new Headers(header);
|
|
66470
66781
|
hasContentLength = headerObj.has("content-length");
|
|
66471
|
-
header = buildOutgoingHttpHeaders(headerObj);
|
|
66782
|
+
header = buildOutgoingHttpHeaders(headerObj, body === null ? void 0 : defaultContentType);
|
|
66472
66783
|
} else for (const key in header) if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
66473
66784
|
hasContentLength = true;
|
|
66474
66785
|
break;
|
|
@@ -66479,7 +66790,8 @@ var responseViaCache = async (res, outgoing) => {
|
|
|
66479
66790
|
else if (body instanceof Blob) header["Content-Length"] = body.size;
|
|
66480
66791
|
}
|
|
66481
66792
|
outgoing.writeHead(status, header);
|
|
66482
|
-
if (
|
|
66793
|
+
if (body == null) outgoing.end();
|
|
66794
|
+
else if (typeof body === "string" || body instanceof Uint8Array) outgoing.end(body);
|
|
66483
66795
|
else if (body instanceof Blob) outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
66484
66796
|
else {
|
|
66485
66797
|
flushHeaders(outgoing);
|
|
@@ -66487,8 +66799,8 @@ var responseViaCache = async (res, outgoing) => {
|
|
|
66487
66799
|
}
|
|
66488
66800
|
outgoing[outgoingEnded]?.();
|
|
66489
66801
|
};
|
|
66490
|
-
|
|
66491
|
-
|
|
66802
|
+
const isPromise = (res) => typeof res.then === "function";
|
|
66803
|
+
const responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
66492
66804
|
if (isPromise(res)) if (options.errorHandler) try {
|
|
66493
66805
|
res = await res;
|
|
66494
66806
|
} catch (err) {
|
|
@@ -66498,7 +66810,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
66498
66810
|
}
|
|
66499
66811
|
else res = await res.catch(handleFetchError);
|
|
66500
66812
|
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
66501
|
-
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
66813
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers, res.body === null ? void 0 : defaultContentType);
|
|
66502
66814
|
if (res.body) {
|
|
66503
66815
|
const reader = res.body.getReader();
|
|
66504
66816
|
const values = [];
|
|
@@ -66538,57 +66850,55 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
66538
66850
|
if (values.length === 0) flushHeaders(outgoing);
|
|
66539
66851
|
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
66540
66852
|
}
|
|
66541
|
-
} else if (resHeaderRecord[
|
|
66853
|
+
} else if (resHeaderRecord["x-hono-already-sent"]) {} else {
|
|
66542
66854
|
outgoing.writeHead(res.status, resHeaderRecord);
|
|
66543
66855
|
outgoing.end();
|
|
66544
66856
|
}
|
|
66545
66857
|
outgoing[outgoingEnded]?.();
|
|
66546
66858
|
};
|
|
66547
|
-
|
|
66859
|
+
const getRequestListener = (fetchCallback, options = {}) => {
|
|
66548
66860
|
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
66549
66861
|
if (options.overrideGlobalObjects !== false && global.Request !== Request$1) {
|
|
66550
66862
|
Object.defineProperty(global, "Request", { value: Request$1 });
|
|
66551
|
-
Object.defineProperty(global, "Response", { value:
|
|
66863
|
+
Object.defineProperty(global, "Response", { value: Response$1 });
|
|
66552
66864
|
}
|
|
66553
66865
|
return async (incoming, outgoing) => {
|
|
66554
66866
|
let res, req;
|
|
66867
|
+
let needsBodyCleanup = false;
|
|
66868
|
+
let closeHandlerAttached = false;
|
|
66869
|
+
const ensureCloseHandler = () => {
|
|
66870
|
+
if (!req || closeHandlerAttached) return;
|
|
66871
|
+
closeHandlerAttached = true;
|
|
66872
|
+
outgoing.on("close", makeCloseHandler(req, incoming, outgoing, needsBodyCleanup));
|
|
66873
|
+
};
|
|
66555
66874
|
try {
|
|
66556
66875
|
req = newRequest(incoming, options.hostname);
|
|
66557
|
-
|
|
66558
|
-
if (
|
|
66876
|
+
needsBodyCleanup = autoCleanupIncoming && !(incoming.method === "GET" || incoming.method === "HEAD");
|
|
66877
|
+
if (needsBodyCleanup) {
|
|
66559
66878
|
incoming[wrapBodyStream] = true;
|
|
66560
|
-
incoming.on("end", () => {
|
|
66561
|
-
incomingEnded = true;
|
|
66562
|
-
});
|
|
66563
66879
|
if (incoming instanceof Http2ServerRequest) outgoing[outgoingEnded] = () => {
|
|
66564
|
-
if (!
|
|
66565
|
-
if (!
|
|
66566
|
-
|
|
66880
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
66881
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
66882
|
+
incoming.destroy();
|
|
66883
|
+
outgoing.destroy();
|
|
66567
66884
|
});
|
|
66568
66885
|
});
|
|
66569
66886
|
};
|
|
66570
|
-
outgoing.on("finish", () => {
|
|
66571
|
-
if (!incomingEnded) drainIncoming(incoming);
|
|
66572
|
-
});
|
|
66573
66887
|
}
|
|
66574
|
-
outgoing.on("close", () => {
|
|
66575
|
-
if (req[abortControllerKey]) {
|
|
66576
|
-
if (incoming.errored) req[abortControllerKey].abort(incoming.errored.toString());
|
|
66577
|
-
else if (!outgoing.writableFinished) req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
66578
|
-
}
|
|
66579
|
-
if (!incomingEnded) setTimeout(() => {
|
|
66580
|
-
if (!incomingEnded) setTimeout(() => {
|
|
66581
|
-
drainIncoming(incoming);
|
|
66582
|
-
});
|
|
66583
|
-
});
|
|
66584
|
-
});
|
|
66585
66888
|
res = fetchCallback(req, {
|
|
66586
66889
|
incoming,
|
|
66587
66890
|
outgoing
|
|
66588
66891
|
});
|
|
66589
|
-
if (
|
|
66892
|
+
if (!isPromise(res) && isImmediateCacheableResponse(res)) {
|
|
66893
|
+
if (needsBodyCleanup && !incoming.readableEnded) outgoing.once("finish", () => {
|
|
66894
|
+
if (!incoming.readableEnded) drainIncoming(incoming);
|
|
66895
|
+
});
|
|
66896
|
+
return responseViaCache(res, outgoing);
|
|
66897
|
+
}
|
|
66898
|
+
ensureCloseHandler();
|
|
66590
66899
|
} catch (e) {
|
|
66591
66900
|
if (!res) if (options.errorHandler) {
|
|
66901
|
+
ensureCloseHandler();
|
|
66592
66902
|
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
66593
66903
|
if (!res) return;
|
|
66594
66904
|
} else if (!req) res = handleRequestError();
|
|
@@ -66602,16 +66912,126 @@ var getRequestListener = (fetchCallback, options = {}) => {
|
|
|
66602
66912
|
}
|
|
66603
66913
|
};
|
|
66604
66914
|
};
|
|
66605
|
-
|
|
66915
|
+
globalThis.CloseEvent;
|
|
66916
|
+
const CONNECTION_SYMBOL_KEY = Symbol("CONNECTION_SYMBOL_KEY");
|
|
66917
|
+
const WAIT_FOR_WEBSOCKET_SYMBOL = Symbol("WAIT_FOR_WEBSOCKET_SYMBOL");
|
|
66918
|
+
const responseHeadersToSkip = new Set([
|
|
66919
|
+
"connection",
|
|
66920
|
+
"content-length",
|
|
66921
|
+
"keep-alive",
|
|
66922
|
+
"proxy-authenticate",
|
|
66923
|
+
"proxy-authorization",
|
|
66924
|
+
"te",
|
|
66925
|
+
"trailer",
|
|
66926
|
+
"transfer-encoding",
|
|
66927
|
+
"upgrade",
|
|
66928
|
+
"sec-websocket-accept",
|
|
66929
|
+
"sec-websocket-extensions",
|
|
66930
|
+
"sec-websocket-protocol"
|
|
66931
|
+
]);
|
|
66932
|
+
const appendResponseHeaders = (headers, responseHeaders) => {
|
|
66933
|
+
if (!responseHeaders) return;
|
|
66934
|
+
responseHeaders.forEach((value, key) => {
|
|
66935
|
+
if (responseHeadersToSkip.has(key.toLowerCase())) return;
|
|
66936
|
+
headers.push(`${key}: ${value}`);
|
|
66937
|
+
});
|
|
66938
|
+
};
|
|
66939
|
+
const rejectUpgradeRequest = (socket, status, responseHeaders) => {
|
|
66940
|
+
const responseLines = ["Connection: close", "Content-Length: 0"];
|
|
66941
|
+
appendResponseHeaders(responseLines, responseHeaders);
|
|
66942
|
+
socket.end(`HTTP/1.1 ${status.toString()} ${STATUS_CODES[status] ?? ""}\r\n${responseLines.join("\r\n")}\r\n\r
|
|
66943
|
+
`);
|
|
66944
|
+
};
|
|
66945
|
+
const createUpgradeRequest = (request) => {
|
|
66946
|
+
const protocol = request.socket.encrypted ? "https" : "http";
|
|
66947
|
+
const url = new URL(request.url ?? "/", `${protocol}://${request.headers.host ?? "localhost"}`);
|
|
66948
|
+
const headers = new Headers();
|
|
66949
|
+
for (const key in request.headers) {
|
|
66950
|
+
const value = request.headers[key];
|
|
66951
|
+
if (!value) continue;
|
|
66952
|
+
headers.append(key, Array.isArray(value) ? value[0] : value);
|
|
66953
|
+
}
|
|
66954
|
+
return new Request(url, { headers });
|
|
66955
|
+
};
|
|
66956
|
+
const setupWebSocket = (options) => {
|
|
66957
|
+
const { server, fetchCallback, wss } = options;
|
|
66958
|
+
const waiterMap = /* @__PURE__ */ new Map();
|
|
66959
|
+
wss.on("connection", (ws, request) => {
|
|
66960
|
+
const waiter = waiterMap.get(request);
|
|
66961
|
+
if (waiter) {
|
|
66962
|
+
waiter.resolve(ws);
|
|
66963
|
+
waiterMap.delete(request);
|
|
66964
|
+
}
|
|
66965
|
+
});
|
|
66966
|
+
const waitForWebSocket = (request, connectionSymbol) => {
|
|
66967
|
+
return new Promise((resolve) => {
|
|
66968
|
+
waiterMap.set(request, {
|
|
66969
|
+
resolve,
|
|
66970
|
+
connectionSymbol
|
|
66971
|
+
});
|
|
66972
|
+
});
|
|
66973
|
+
};
|
|
66974
|
+
server.on("upgrade", async (request, socket, head) => {
|
|
66975
|
+
if (request.headers.upgrade?.toLowerCase() !== "websocket") return;
|
|
66976
|
+
const env = {
|
|
66977
|
+
incoming: request,
|
|
66978
|
+
outgoing: void 0,
|
|
66979
|
+
wss,
|
|
66980
|
+
[WAIT_FOR_WEBSOCKET_SYMBOL]: waitForWebSocket
|
|
66981
|
+
};
|
|
66982
|
+
let status = 400;
|
|
66983
|
+
let responseHeaders;
|
|
66984
|
+
try {
|
|
66985
|
+
const response = await fetchCallback(createUpgradeRequest(request), env);
|
|
66986
|
+
if (response instanceof Response) {
|
|
66987
|
+
status = response.status;
|
|
66988
|
+
responseHeaders = response.headers;
|
|
66989
|
+
}
|
|
66990
|
+
} catch {
|
|
66991
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 500);
|
|
66992
|
+
return;
|
|
66993
|
+
}
|
|
66994
|
+
const waiter = waiterMap.get(request);
|
|
66995
|
+
if (!waiter || waiter.connectionSymbol !== env[CONNECTION_SYMBOL_KEY]) {
|
|
66996
|
+
waiterMap.delete(request);
|
|
66997
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, status, responseHeaders);
|
|
66998
|
+
return;
|
|
66999
|
+
}
|
|
67000
|
+
const addResponseHeaders = (headers) => {
|
|
67001
|
+
appendResponseHeaders(headers, responseHeaders);
|
|
67002
|
+
};
|
|
67003
|
+
wss.on("headers", addResponseHeaders);
|
|
67004
|
+
try {
|
|
67005
|
+
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
67006
|
+
wss.emit("connection", ws, request);
|
|
67007
|
+
});
|
|
67008
|
+
} finally {
|
|
67009
|
+
wss.off("headers", addResponseHeaders);
|
|
67010
|
+
}
|
|
67011
|
+
});
|
|
67012
|
+
server.on("close", () => {
|
|
67013
|
+
wss.close();
|
|
67014
|
+
});
|
|
67015
|
+
};
|
|
67016
|
+
const createAdaptorServer = (options) => {
|
|
66606
67017
|
const fetchCallback = options.fetch;
|
|
66607
67018
|
const requestListener = getRequestListener(fetchCallback, {
|
|
66608
67019
|
hostname: options.hostname,
|
|
66609
67020
|
overrideGlobalObjects: options.overrideGlobalObjects,
|
|
66610
67021
|
autoCleanupIncoming: options.autoCleanupIncoming
|
|
66611
67022
|
});
|
|
66612
|
-
|
|
67023
|
+
const server = (options.createServer || createServer)(options.serverOptions || {}, requestListener);
|
|
67024
|
+
if (options.websocket && options.websocket.server) {
|
|
67025
|
+
if (options.websocket.server.options.noServer !== true) throw new Error("WebSocket server must be created with { noServer: true } option");
|
|
67026
|
+
setupWebSocket({
|
|
67027
|
+
server,
|
|
67028
|
+
fetchCallback,
|
|
67029
|
+
wss: options.websocket.server
|
|
67030
|
+
});
|
|
67031
|
+
}
|
|
67032
|
+
return server;
|
|
66613
67033
|
};
|
|
66614
|
-
|
|
67034
|
+
const serve = (options, listeningListener) => {
|
|
66615
67035
|
const server = createAdaptorServer(options);
|
|
66616
67036
|
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
66617
67037
|
const serverInfo = server.address();
|
|
@@ -68360,7 +68780,7 @@ function writeAddResult(writeOut, label, result) {
|
|
|
68360
68780
|
}
|
|
68361
68781
|
//#endregion
|
|
68362
68782
|
//#region package.json
|
|
68363
|
-
var version = "0.17.
|
|
68783
|
+
var version = "0.17.1";
|
|
68364
68784
|
//#endregion
|
|
68365
68785
|
//#region src/index.ts
|
|
68366
68786
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caplets",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Progressive disclosure gateway CLI for MCP servers and native Caplets adapters.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"caplets",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
|
-
"@caplets/core": "0.18.
|
|
37
|
+
"@caplets/core": "0.18.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^25.9.
|
|
41
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
42
|
-
"rolldown": "^1.0.
|
|
40
|
+
"@types/node": "^25.9.1",
|
|
41
|
+
"@typescript/native-preview": "7.0.0-dev.20260519.1",
|
|
42
|
+
"rolldown": "^1.0.2",
|
|
43
43
|
"typescript": "^6.0.3",
|
|
44
|
-
"vitest": "^4.1.
|
|
44
|
+
"vitest": "^4.1.7"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=22"
|