wildcrane-runner 0.6.79 → 0.6.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/akb/dist/kanban.mjs +92 -142
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/codex-proxy.mjs +1082 -680
- package/dist/{codex-service-main.mjs → codex-retained.mjs} +402 -2515
- package/dist/flow-worker-main.mjs +403 -428
- package/dist/launcher.mjs +849 -813
- package/dist/plugin.mjs +1115 -1079
- package/dist/runner.mjs +1091 -921
- package/dist/settings.mjs +1042 -1006
- package/package.json +1 -1
package/dist/codex-proxy.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.80 — built by runner/scripts/build.mjs. Do not edit.
|
|
2
2
|
import { createRequire as __ai4kanbanRequire } from 'node:module'
|
|
3
3
|
const require = __ai4kanbanRequire(import.meta.url)
|
|
4
4
|
var __create = Object.create;
|
|
@@ -958,9 +958,9 @@ var require_timers = __commonJS({
|
|
|
958
958
|
* before the specified function or code is executed.
|
|
959
959
|
* @param {*} arg
|
|
960
960
|
*/
|
|
961
|
-
constructor(callback,
|
|
961
|
+
constructor(callback, delay2, arg) {
|
|
962
962
|
this._onTimeout = callback;
|
|
963
|
-
this._idleTimeout =
|
|
963
|
+
this._idleTimeout = delay2;
|
|
964
964
|
this._timerArg = arg;
|
|
965
965
|
this.refresh();
|
|
966
966
|
}
|
|
@@ -1005,8 +1005,8 @@ var require_timers = __commonJS({
|
|
|
1005
1005
|
* when the timer expires.
|
|
1006
1006
|
* @returns {NodeJS.Timeout|FastTimer}
|
|
1007
1007
|
*/
|
|
1008
|
-
setTimeout(callback,
|
|
1009
|
-
return
|
|
1008
|
+
setTimeout(callback, delay2, arg) {
|
|
1009
|
+
return delay2 <= RESOLUTION_MS ? setTimeout(callback, delay2, arg) : new FastTimer(callback, delay2, arg);
|
|
1010
1010
|
},
|
|
1011
1011
|
/**
|
|
1012
1012
|
* The clearTimeout method cancels an instantiated Timer previously created
|
|
@@ -1032,8 +1032,8 @@ var require_timers = __commonJS({
|
|
|
1032
1032
|
* when the timer expires.
|
|
1033
1033
|
* @returns {FastTimer}
|
|
1034
1034
|
*/
|
|
1035
|
-
setFastTimeout(callback,
|
|
1036
|
-
return new FastTimer(callback,
|
|
1035
|
+
setFastTimeout(callback, delay2, arg) {
|
|
1036
|
+
return new FastTimer(callback, delay2, arg);
|
|
1037
1037
|
},
|
|
1038
1038
|
/**
|
|
1039
1039
|
* The clearTimeout method cancels an instantiated FastTimer previously
|
|
@@ -1059,8 +1059,8 @@ var require_timers = __commonJS({
|
|
|
1059
1059
|
* @deprecated
|
|
1060
1060
|
* @param {number} [delay=0] The delay in milliseconds to add to the now value.
|
|
1061
1061
|
*/
|
|
1062
|
-
tick(
|
|
1063
|
-
fastNow +=
|
|
1062
|
+
tick(delay2 = 0) {
|
|
1063
|
+
fastNow += delay2 - RESOLUTION_MS + 1;
|
|
1064
1064
|
onTick();
|
|
1065
1065
|
onTick();
|
|
1066
1066
|
},
|
|
@@ -1301,12 +1301,12 @@ var require_errors = __commonJS({
|
|
|
1301
1301
|
};
|
|
1302
1302
|
var kSocketError = /* @__PURE__ */ Symbol.for("undici.error.UND_ERR_SOCKET");
|
|
1303
1303
|
var SocketError = class extends UndiciError {
|
|
1304
|
-
constructor(message,
|
|
1304
|
+
constructor(message, socket) {
|
|
1305
1305
|
super(message);
|
|
1306
1306
|
this.name = "SocketError";
|
|
1307
1307
|
this.message = message || "Socket error";
|
|
1308
1308
|
this.code = "UND_ERR_SOCKET";
|
|
1309
|
-
this.socket =
|
|
1309
|
+
this.socket = socket;
|
|
1310
1310
|
}
|
|
1311
1311
|
static [Symbol.hasInstance](instance) {
|
|
1312
1312
|
return instance && instance[kSocketError] === true;
|
|
@@ -1773,7 +1773,7 @@ var require_util = __commonJS({
|
|
|
1773
1773
|
var { kDestroyed, kBodyUsed, kListeners, kBody } = require_symbols();
|
|
1774
1774
|
var { IncomingMessage } = __require("node:http");
|
|
1775
1775
|
var stream = __require("node:stream");
|
|
1776
|
-
var
|
|
1776
|
+
var net2 = __require("node:net");
|
|
1777
1777
|
var { stringify } = __require("node:querystring");
|
|
1778
1778
|
var { EventEmitter: EE } = __require("node:events");
|
|
1779
1779
|
var timers = require_timers();
|
|
@@ -1922,7 +1922,7 @@ var require_util = __commonJS({
|
|
|
1922
1922
|
}
|
|
1923
1923
|
assert(typeof host === "string");
|
|
1924
1924
|
const servername = getHostname(host);
|
|
1925
|
-
if (
|
|
1925
|
+
if (net2.isIP(servername)) {
|
|
1926
1926
|
return "";
|
|
1927
1927
|
}
|
|
1928
1928
|
return servername;
|
|
@@ -2090,16 +2090,16 @@ var require_util = __commonJS({
|
|
|
2090
2090
|
function isDisturbed(body) {
|
|
2091
2091
|
return !!(body && (stream.isDisturbed(body) || body[kBodyUsed]));
|
|
2092
2092
|
}
|
|
2093
|
-
function getSocketInfo(
|
|
2093
|
+
function getSocketInfo(socket) {
|
|
2094
2094
|
return {
|
|
2095
|
-
localAddress:
|
|
2096
|
-
localPort:
|
|
2097
|
-
remoteAddress:
|
|
2098
|
-
remotePort:
|
|
2099
|
-
remoteFamily:
|
|
2100
|
-
timeout:
|
|
2101
|
-
bytesWritten:
|
|
2102
|
-
bytesRead:
|
|
2095
|
+
localAddress: socket.localAddress,
|
|
2096
|
+
localPort: socket.localPort,
|
|
2097
|
+
remoteAddress: socket.remoteAddress,
|
|
2098
|
+
remotePort: socket.remotePort,
|
|
2099
|
+
remoteFamily: socket.remoteFamily,
|
|
2100
|
+
timeout: socket.timeout,
|
|
2101
|
+
bytesWritten: socket.bytesWritten,
|
|
2102
|
+
bytesRead: socket.bytesRead
|
|
2103
2103
|
};
|
|
2104
2104
|
}
|
|
2105
2105
|
function ReadableStreamFrom(iterable) {
|
|
@@ -2500,18 +2500,18 @@ var require_util = __commonJS({
|
|
|
2500
2500
|
clearImmediate(s1);
|
|
2501
2501
|
};
|
|
2502
2502
|
};
|
|
2503
|
-
function onConnectTimeout(
|
|
2504
|
-
if (
|
|
2503
|
+
function onConnectTimeout(socket, opts) {
|
|
2504
|
+
if (socket == null) {
|
|
2505
2505
|
return;
|
|
2506
2506
|
}
|
|
2507
2507
|
let message = "Connect Timeout Error";
|
|
2508
|
-
if (Array.isArray(
|
|
2509
|
-
message += ` (attempted addresses: ${
|
|
2508
|
+
if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) {
|
|
2509
|
+
message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(", ")},`;
|
|
2510
2510
|
} else {
|
|
2511
2511
|
message += ` (attempted address: ${opts.hostname}:${opts.port},`;
|
|
2512
2512
|
}
|
|
2513
2513
|
message += ` timeout: ${opts.timeout}ms)`;
|
|
2514
|
-
destroy(
|
|
2514
|
+
destroy(socket, new ConnectTimeoutError(message));
|
|
2515
2515
|
}
|
|
2516
2516
|
function getProtocolFromUrlString(urlString) {
|
|
2517
2517
|
if (urlString[0] === "h" && urlString[1] === "t" && urlString[2] === "t" && urlString[3] === "p") {
|
|
@@ -3100,14 +3100,14 @@ var require_request = __commonJS({
|
|
|
3100
3100
|
* @param {import('node:stream').Duplex} socket
|
|
3101
3101
|
* @param {string} [statusText]
|
|
3102
3102
|
*/
|
|
3103
|
-
onUpgrade(statusCode, headers,
|
|
3103
|
+
onUpgrade(statusCode, headers, socket, statusText = "") {
|
|
3104
3104
|
this.onFinally();
|
|
3105
3105
|
assert(!this.aborted);
|
|
3106
3106
|
assert(!this.completed);
|
|
3107
3107
|
if (channels.headers.hasSubscribers) {
|
|
3108
3108
|
channels.headers.publish({ request: this, response: { statusCode, headers, statusText } });
|
|
3109
3109
|
}
|
|
3110
|
-
const result = this[kHandler].onUpgrade(statusCode, headers,
|
|
3110
|
+
const result = this[kHandler].onUpgrade(statusCode, headers, socket);
|
|
3111
3111
|
if (!this.aborted) {
|
|
3112
3112
|
this.completed = true;
|
|
3113
3113
|
if (channels.trailers.hasSubscribers) {
|
|
@@ -3270,8 +3270,8 @@ var require_wrap_handler = __commonJS({
|
|
|
3270
3270
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
3271
3271
|
return this.#handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage);
|
|
3272
3272
|
}
|
|
3273
|
-
onUpgrade(statusCode, rawHeaders,
|
|
3274
|
-
return this.#handler.onUpgrade?.(statusCode, rawHeaders,
|
|
3273
|
+
onUpgrade(statusCode, rawHeaders, socket) {
|
|
3274
|
+
return this.#handler.onUpgrade?.(statusCode, rawHeaders, socket);
|
|
3275
3275
|
}
|
|
3276
3276
|
onData(data) {
|
|
3277
3277
|
return this.#handler.onData?.(data);
|
|
@@ -3289,12 +3289,12 @@ var require_wrap_handler = __commonJS({
|
|
|
3289
3289
|
onRequestStart(controller, context) {
|
|
3290
3290
|
this.#handler.onConnect?.((reason) => controller.abort(reason), context);
|
|
3291
3291
|
}
|
|
3292
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
3292
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
3293
3293
|
const rawHeaders = [];
|
|
3294
3294
|
for (const [key, val] of Object.entries(headers)) {
|
|
3295
3295
|
rawHeaders.push(Buffer.from(key, "latin1"), toRawHeaderValue(val));
|
|
3296
3296
|
}
|
|
3297
|
-
this.#handler.onUpgrade?.(statusCode, rawHeaders,
|
|
3297
|
+
this.#handler.onUpgrade?.(statusCode, rawHeaders, socket);
|
|
3298
3298
|
}
|
|
3299
3299
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
3300
3300
|
const rawHeaders = [];
|
|
@@ -3432,9 +3432,9 @@ var require_unwrap_handler = __commonJS({
|
|
|
3432
3432
|
onResponseStarted() {
|
|
3433
3433
|
return this.#handler.onResponseStarted?.();
|
|
3434
3434
|
}
|
|
3435
|
-
onUpgrade(statusCode, rawHeaders,
|
|
3435
|
+
onUpgrade(statusCode, rawHeaders, socket) {
|
|
3436
3436
|
this.#controller.rawHeaders = rawHeaders;
|
|
3437
|
-
this.#handler.onRequestUpgrade?.(this.#controller, statusCode, parseHeaders(rawHeaders),
|
|
3437
|
+
this.#handler.onRequestUpgrade?.(this.#controller, statusCode, parseHeaders(rawHeaders), socket);
|
|
3438
3438
|
}
|
|
3439
3439
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
3440
3440
|
this.#controller[kResume] = resume;
|
|
@@ -3627,7 +3627,7 @@ var require_dispatcher_base = __commonJS({
|
|
|
3627
3627
|
var require_connect = __commonJS({
|
|
3628
3628
|
"node_modules/undici/lib/core/connect.js"(exports, module) {
|
|
3629
3629
|
"use strict";
|
|
3630
|
-
var
|
|
3630
|
+
var net2 = __require("node:net");
|
|
3631
3631
|
var assert = __require("node:assert");
|
|
3632
3632
|
var util = require_util();
|
|
3633
3633
|
var { InvalidArgumentError } = require_errors();
|
|
@@ -3685,7 +3685,7 @@ var require_connect = __commonJS({
|
|
|
3685
3685
|
timeout = timeout == null ? 1e4 : timeout;
|
|
3686
3686
|
allowH2 = allowH2 != null ? allowH2 : false;
|
|
3687
3687
|
return function connect2({ hostname, host, protocol, port, servername, localAddress, httpSocket }, callback) {
|
|
3688
|
-
let
|
|
3688
|
+
let socket;
|
|
3689
3689
|
if (protocol === "https:") {
|
|
3690
3690
|
if (!tls) {
|
|
3691
3691
|
tls = __require("node:tls");
|
|
@@ -3695,7 +3695,7 @@ var require_connect = __commonJS({
|
|
|
3695
3695
|
assert(sessionKey);
|
|
3696
3696
|
const session = customSession || sessionCache.get(sessionKey) || null;
|
|
3697
3697
|
port = port || 443;
|
|
3698
|
-
|
|
3698
|
+
socket = tls.connect({
|
|
3699
3699
|
highWaterMark: 16384,
|
|
3700
3700
|
// TLS in node can't have bigger HWM anyway...
|
|
3701
3701
|
...options,
|
|
@@ -3708,13 +3708,13 @@ var require_connect = __commonJS({
|
|
|
3708
3708
|
port,
|
|
3709
3709
|
host: hostname
|
|
3710
3710
|
});
|
|
3711
|
-
|
|
3711
|
+
socket.on("session", function(session2) {
|
|
3712
3712
|
sessionCache.set(sessionKey, session2);
|
|
3713
3713
|
});
|
|
3714
3714
|
} else {
|
|
3715
3715
|
assert(!httpSocket, "httpSocket can only be sent on TLS update");
|
|
3716
3716
|
port = port || 80;
|
|
3717
|
-
|
|
3717
|
+
socket = net2.connect({
|
|
3718
3718
|
highWaterMark: 64 * 1024,
|
|
3719
3719
|
// Same as nodejs fs streams.
|
|
3720
3720
|
...options,
|
|
@@ -3723,15 +3723,15 @@ var require_connect = __commonJS({
|
|
|
3723
3723
|
host: hostname
|
|
3724
3724
|
});
|
|
3725
3725
|
if (useH2c === true) {
|
|
3726
|
-
|
|
3726
|
+
socket.alpnProtocol = "h2";
|
|
3727
3727
|
}
|
|
3728
3728
|
}
|
|
3729
3729
|
if (options.keepAlive == null || options.keepAlive) {
|
|
3730
3730
|
const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay;
|
|
3731
|
-
|
|
3731
|
+
socket.setKeepAlive(true, keepAliveInitialDelay);
|
|
3732
3732
|
}
|
|
3733
|
-
const clearConnectTimeout = util.setupConnectTimeout(new WeakRef(
|
|
3734
|
-
|
|
3733
|
+
const clearConnectTimeout = util.setupConnectTimeout(new WeakRef(socket), { timeout, hostname, port });
|
|
3734
|
+
socket.setNoDelay(true).once(protocol === "https:" ? "secureConnect" : "connect", function() {
|
|
3735
3735
|
queueMicrotask(clearConnectTimeout);
|
|
3736
3736
|
if (callback) {
|
|
3737
3737
|
const cb = callback;
|
|
@@ -3746,7 +3746,7 @@ var require_connect = __commonJS({
|
|
|
3746
3746
|
cb(err);
|
|
3747
3747
|
}
|
|
3748
3748
|
});
|
|
3749
|
-
return
|
|
3749
|
+
return socket;
|
|
3750
3750
|
};
|
|
3751
3751
|
}
|
|
3752
3752
|
module.exports = buildConnector;
|
|
@@ -4709,23 +4709,23 @@ var require_infra = __commonJS({
|
|
|
4709
4709
|
"use strict";
|
|
4710
4710
|
var assert = __require("node:assert");
|
|
4711
4711
|
var { utf8DecodeBytes } = require_encoding();
|
|
4712
|
-
function collectASequenceOfCodePoints(condition,
|
|
4712
|
+
function collectASequenceOfCodePoints(condition, input, position) {
|
|
4713
4713
|
let result = "";
|
|
4714
|
-
while (position.position <
|
|
4715
|
-
result +=
|
|
4714
|
+
while (position.position < input.length && condition(input[position.position])) {
|
|
4715
|
+
result += input[position.position];
|
|
4716
4716
|
position.position++;
|
|
4717
4717
|
}
|
|
4718
4718
|
return result;
|
|
4719
4719
|
}
|
|
4720
|
-
function collectASequenceOfCodePointsFast(char,
|
|
4721
|
-
const idx =
|
|
4720
|
+
function collectASequenceOfCodePointsFast(char, input, position) {
|
|
4721
|
+
const idx = input.indexOf(char, position.position);
|
|
4722
4722
|
const start = position.position;
|
|
4723
4723
|
if (idx === -1) {
|
|
4724
|
-
position.position =
|
|
4725
|
-
return
|
|
4724
|
+
position.position = input.length;
|
|
4725
|
+
return input.slice(start);
|
|
4726
4726
|
}
|
|
4727
4727
|
position.position = idx;
|
|
4728
|
-
return
|
|
4728
|
+
return input.slice(start, position.position);
|
|
4729
4729
|
}
|
|
4730
4730
|
var ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g;
|
|
4731
4731
|
var nonASCIIRegex = /[^\x00-\x7F]/;
|
|
@@ -4759,10 +4759,10 @@ var require_infra = __commonJS({
|
|
|
4759
4759
|
char === 13 || // \r
|
|
4760
4760
|
char === 32;
|
|
4761
4761
|
}
|
|
4762
|
-
function isomorphicDecode(
|
|
4763
|
-
const length =
|
|
4762
|
+
function isomorphicDecode(input) {
|
|
4763
|
+
const length = input.length;
|
|
4764
4764
|
if ((2 << 15) - 1 > length) {
|
|
4765
|
-
return String.fromCharCode.apply(null,
|
|
4765
|
+
return String.fromCharCode.apply(null, input);
|
|
4766
4766
|
}
|
|
4767
4767
|
let result = "";
|
|
4768
4768
|
let i = 0;
|
|
@@ -4771,14 +4771,14 @@ var require_infra = __commonJS({
|
|
|
4771
4771
|
if (i + addition > length) {
|
|
4772
4772
|
addition = length - i;
|
|
4773
4773
|
}
|
|
4774
|
-
result += String.fromCharCode.apply(null,
|
|
4774
|
+
result += String.fromCharCode.apply(null, input.subarray(i, i += addition));
|
|
4775
4775
|
}
|
|
4776
4776
|
return result;
|
|
4777
4777
|
}
|
|
4778
4778
|
var invalidIsomorphicEncodeValueRegex = /[^\x00-\xFF]/;
|
|
4779
|
-
function isomorphicEncode(
|
|
4780
|
-
assert(!invalidIsomorphicEncodeValueRegex.test(
|
|
4781
|
-
return
|
|
4779
|
+
function isomorphicEncode(input) {
|
|
4780
|
+
assert(!invalidIsomorphicEncodeValueRegex.test(input));
|
|
4781
|
+
return input;
|
|
4782
4782
|
}
|
|
4783
4783
|
function parseJSONFromBytes(bytes) {
|
|
4784
4784
|
return JSON.parse(utf8DecodeBytes(bytes));
|
|
@@ -4833,21 +4833,21 @@ var require_data_url = __commonJS({
|
|
|
4833
4833
|
var HTTP_QUOTED_STRING_TOKENS = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/u;
|
|
4834
4834
|
function dataURLProcessor(dataURL) {
|
|
4835
4835
|
assert(dataURL.protocol === "data:");
|
|
4836
|
-
let
|
|
4837
|
-
|
|
4836
|
+
let input = URLSerializer(dataURL, true);
|
|
4837
|
+
input = input.slice(5);
|
|
4838
4838
|
const position = { position: 0 };
|
|
4839
4839
|
let mimeType = collectASequenceOfCodePointsFast(
|
|
4840
4840
|
",",
|
|
4841
|
-
|
|
4841
|
+
input,
|
|
4842
4842
|
position
|
|
4843
4843
|
);
|
|
4844
4844
|
const mimeTypeLength = mimeType.length;
|
|
4845
4845
|
mimeType = removeASCIIWhitespace(mimeType, true, true);
|
|
4846
|
-
if (position.position >=
|
|
4846
|
+
if (position.position >= input.length) {
|
|
4847
4847
|
return "failure";
|
|
4848
4848
|
}
|
|
4849
4849
|
position.position++;
|
|
4850
|
-
const encodedBody =
|
|
4850
|
+
const encodedBody = input.slice(mimeTypeLength + 1);
|
|
4851
4851
|
let body = stringPercentDecode(encodedBody);
|
|
4852
4852
|
if (/;(?:\u0020*)base64$/ui.test(mimeType)) {
|
|
4853
4853
|
const stringBody = isomorphicDecode(body);
|
|
@@ -4880,8 +4880,8 @@ var require_data_url = __commonJS({
|
|
|
4880
4880
|
}
|
|
4881
4881
|
return serialized;
|
|
4882
4882
|
}
|
|
4883
|
-
function stringPercentDecode(
|
|
4884
|
-
const bytes = encoder.encode(
|
|
4883
|
+
function stringPercentDecode(input) {
|
|
4884
|
+
const bytes = encoder.encode(input);
|
|
4885
4885
|
return percentDecode(bytes);
|
|
4886
4886
|
}
|
|
4887
4887
|
function isHexCharByte(byte) {
|
|
@@ -4893,43 +4893,43 @@ var require_data_url = __commonJS({
|
|
|
4893
4893
|
byte >= 48 && byte <= 57 ? byte - 48 : (byte & 223) - 55
|
|
4894
4894
|
);
|
|
4895
4895
|
}
|
|
4896
|
-
function percentDecode(
|
|
4897
|
-
const length =
|
|
4896
|
+
function percentDecode(input) {
|
|
4897
|
+
const length = input.length;
|
|
4898
4898
|
const output = new Uint8Array(length);
|
|
4899
4899
|
let j = 0;
|
|
4900
4900
|
let i = 0;
|
|
4901
4901
|
while (i < length) {
|
|
4902
|
-
const byte =
|
|
4902
|
+
const byte = input[i];
|
|
4903
4903
|
if (byte !== 37) {
|
|
4904
4904
|
output[j++] = byte;
|
|
4905
|
-
} else if (byte === 37 && !(isHexCharByte(
|
|
4905
|
+
} else if (byte === 37 && !(isHexCharByte(input[i + 1]) && isHexCharByte(input[i + 2]))) {
|
|
4906
4906
|
output[j++] = 37;
|
|
4907
4907
|
} else {
|
|
4908
|
-
output[j++] = hexByteToNumber(
|
|
4908
|
+
output[j++] = hexByteToNumber(input[i + 1]) << 4 | hexByteToNumber(input[i + 2]);
|
|
4909
4909
|
i += 2;
|
|
4910
4910
|
}
|
|
4911
4911
|
++i;
|
|
4912
4912
|
}
|
|
4913
4913
|
return length === j ? output : output.subarray(0, j);
|
|
4914
4914
|
}
|
|
4915
|
-
function parseMIMEType(
|
|
4916
|
-
|
|
4915
|
+
function parseMIMEType(input) {
|
|
4916
|
+
input = removeHTTPWhitespace(input, true, true);
|
|
4917
4917
|
const position = { position: 0 };
|
|
4918
4918
|
const type = collectASequenceOfCodePointsFast(
|
|
4919
4919
|
"/",
|
|
4920
|
-
|
|
4920
|
+
input,
|
|
4921
4921
|
position
|
|
4922
4922
|
);
|
|
4923
4923
|
if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) {
|
|
4924
4924
|
return "failure";
|
|
4925
4925
|
}
|
|
4926
|
-
if (position.position >=
|
|
4926
|
+
if (position.position >= input.length) {
|
|
4927
4927
|
return "failure";
|
|
4928
4928
|
}
|
|
4929
4929
|
position.position++;
|
|
4930
4930
|
let subtype = collectASequenceOfCodePointsFast(
|
|
4931
4931
|
";",
|
|
4932
|
-
|
|
4932
|
+
input,
|
|
4933
4933
|
position
|
|
4934
4934
|
);
|
|
4935
4935
|
subtype = removeHTTPWhitespace(subtype, false, true);
|
|
@@ -4946,41 +4946,41 @@ var require_data_url = __commonJS({
|
|
|
4946
4946
|
// https://mimesniff.spec.whatwg.org/#mime-type-essence
|
|
4947
4947
|
essence: `${typeLowercase}/${subtypeLowercase}`
|
|
4948
4948
|
};
|
|
4949
|
-
while (position.position <
|
|
4949
|
+
while (position.position < input.length) {
|
|
4950
4950
|
position.position++;
|
|
4951
4951
|
collectASequenceOfCodePoints(
|
|
4952
4952
|
// https://fetch.spec.whatwg.org/#http-whitespace
|
|
4953
4953
|
(char) => HTTP_WHITESPACE_REGEX.test(char),
|
|
4954
|
-
|
|
4954
|
+
input,
|
|
4955
4955
|
position
|
|
4956
4956
|
);
|
|
4957
4957
|
let parameterName = collectASequenceOfCodePoints(
|
|
4958
4958
|
(char) => char !== ";" && char !== "=",
|
|
4959
|
-
|
|
4959
|
+
input,
|
|
4960
4960
|
position
|
|
4961
4961
|
);
|
|
4962
4962
|
parameterName = parameterName.toLowerCase();
|
|
4963
|
-
if (position.position <
|
|
4964
|
-
if (
|
|
4963
|
+
if (position.position < input.length) {
|
|
4964
|
+
if (input[position.position] === ";") {
|
|
4965
4965
|
continue;
|
|
4966
4966
|
}
|
|
4967
4967
|
position.position++;
|
|
4968
4968
|
}
|
|
4969
|
-
if (position.position >=
|
|
4969
|
+
if (position.position >= input.length) {
|
|
4970
4970
|
break;
|
|
4971
4971
|
}
|
|
4972
4972
|
let parameterValue = null;
|
|
4973
|
-
if (
|
|
4974
|
-
parameterValue = collectAnHTTPQuotedString(
|
|
4973
|
+
if (input[position.position] === '"') {
|
|
4974
|
+
parameterValue = collectAnHTTPQuotedString(input, position, true);
|
|
4975
4975
|
collectASequenceOfCodePointsFast(
|
|
4976
4976
|
";",
|
|
4977
|
-
|
|
4977
|
+
input,
|
|
4978
4978
|
position
|
|
4979
4979
|
);
|
|
4980
4980
|
} else {
|
|
4981
4981
|
parameterValue = collectASequenceOfCodePointsFast(
|
|
4982
4982
|
";",
|
|
4983
|
-
|
|
4983
|
+
input,
|
|
4984
4984
|
position
|
|
4985
4985
|
);
|
|
4986
4986
|
parameterValue = removeHTTPWhitespace(parameterValue, false, true);
|
|
@@ -4994,28 +4994,28 @@ var require_data_url = __commonJS({
|
|
|
4994
4994
|
}
|
|
4995
4995
|
return mimeType;
|
|
4996
4996
|
}
|
|
4997
|
-
function collectAnHTTPQuotedString(
|
|
4997
|
+
function collectAnHTTPQuotedString(input, position, extractValue = false) {
|
|
4998
4998
|
const positionStart = position.position;
|
|
4999
4999
|
let value = "";
|
|
5000
|
-
assert(
|
|
5000
|
+
assert(input[position.position] === '"');
|
|
5001
5001
|
position.position++;
|
|
5002
5002
|
while (true) {
|
|
5003
5003
|
value += collectASequenceOfCodePoints(
|
|
5004
5004
|
(char) => char !== '"' && char !== "\\",
|
|
5005
|
-
|
|
5005
|
+
input,
|
|
5006
5006
|
position
|
|
5007
5007
|
);
|
|
5008
|
-
if (position.position >=
|
|
5008
|
+
if (position.position >= input.length) {
|
|
5009
5009
|
break;
|
|
5010
5010
|
}
|
|
5011
|
-
const quoteOrBackslash =
|
|
5011
|
+
const quoteOrBackslash = input[position.position];
|
|
5012
5012
|
position.position++;
|
|
5013
5013
|
if (quoteOrBackslash === "\\") {
|
|
5014
|
-
if (position.position >=
|
|
5014
|
+
if (position.position >= input.length) {
|
|
5015
5015
|
value += "\\";
|
|
5016
5016
|
break;
|
|
5017
5017
|
}
|
|
5018
|
-
value +=
|
|
5018
|
+
value += input[position.position];
|
|
5019
5019
|
position.position++;
|
|
5020
5020
|
} else {
|
|
5021
5021
|
assert(quoteOrBackslash === '"');
|
|
@@ -5025,7 +5025,7 @@ var require_data_url = __commonJS({
|
|
|
5025
5025
|
if (extractValue) {
|
|
5026
5026
|
return value;
|
|
5027
5027
|
}
|
|
5028
|
-
return
|
|
5028
|
+
return input.slice(positionStart, position.position);
|
|
5029
5029
|
}
|
|
5030
5030
|
function serializeAMimeType(mimeType) {
|
|
5031
5031
|
assert(mimeType !== "failure");
|
|
@@ -6460,27 +6460,27 @@ var require_util2 = __commonJS({
|
|
|
6460
6460
|
return mimeType;
|
|
6461
6461
|
}
|
|
6462
6462
|
function gettingDecodingSplitting(value) {
|
|
6463
|
-
const
|
|
6463
|
+
const input = value;
|
|
6464
6464
|
const position = { position: 0 };
|
|
6465
6465
|
const values = [];
|
|
6466
6466
|
let temporaryValue = "";
|
|
6467
|
-
while (position.position <
|
|
6467
|
+
while (position.position < input.length) {
|
|
6468
6468
|
temporaryValue += collectASequenceOfCodePoints(
|
|
6469
6469
|
(char) => char !== '"' && char !== ",",
|
|
6470
|
-
|
|
6470
|
+
input,
|
|
6471
6471
|
position
|
|
6472
6472
|
);
|
|
6473
|
-
if (position.position <
|
|
6474
|
-
if (
|
|
6473
|
+
if (position.position < input.length) {
|
|
6474
|
+
if (input.charCodeAt(position.position) === 34) {
|
|
6475
6475
|
temporaryValue += collectAnHTTPQuotedString(
|
|
6476
|
-
|
|
6476
|
+
input,
|
|
6477
6477
|
position
|
|
6478
6478
|
);
|
|
6479
|
-
if (position.position <
|
|
6479
|
+
if (position.position < input.length) {
|
|
6480
6480
|
continue;
|
|
6481
6481
|
}
|
|
6482
6482
|
} else {
|
|
6483
|
-
assert(
|
|
6483
|
+
assert(input.charCodeAt(position.position) === 44);
|
|
6484
6484
|
position.position++;
|
|
6485
6485
|
}
|
|
6486
6486
|
}
|
|
@@ -6767,7 +6767,7 @@ var require_formdata_parser = __commonJS({
|
|
|
6767
6767
|
}
|
|
6768
6768
|
return true;
|
|
6769
6769
|
}
|
|
6770
|
-
function multipartFormDataParser(
|
|
6770
|
+
function multipartFormDataParser(input, mimeType) {
|
|
6771
6771
|
assert(mimeType !== "failure" && mimeType.essence === "multipart/form-data");
|
|
6772
6772
|
const boundaryString = mimeType.parameters.get("boundary");
|
|
6773
6773
|
if (boundaryString === void 0) {
|
|
@@ -6776,40 +6776,40 @@ var require_formdata_parser = __commonJS({
|
|
|
6776
6776
|
const boundary = Buffer.from(`--${boundaryString}`, "utf8");
|
|
6777
6777
|
const entryList = [];
|
|
6778
6778
|
const position = { position: 0 };
|
|
6779
|
-
const firstBoundaryIndex =
|
|
6779
|
+
const firstBoundaryIndex = input.indexOf(boundary);
|
|
6780
6780
|
if (firstBoundaryIndex === -1) {
|
|
6781
6781
|
throw parsingError("no boundary found in multipart body");
|
|
6782
6782
|
}
|
|
6783
6783
|
position.position = firstBoundaryIndex;
|
|
6784
6784
|
while (true) {
|
|
6785
|
-
if (
|
|
6785
|
+
if (input.subarray(position.position, position.position + boundary.length).equals(boundary)) {
|
|
6786
6786
|
position.position += boundary.length;
|
|
6787
6787
|
} else {
|
|
6788
6788
|
throw parsingError("expected a value starting with -- and the boundary");
|
|
6789
6789
|
}
|
|
6790
|
-
if (bufferStartsWith(
|
|
6790
|
+
if (bufferStartsWith(input, dd, position)) {
|
|
6791
6791
|
return entryList;
|
|
6792
6792
|
}
|
|
6793
|
-
if (
|
|
6793
|
+
if (input[position.position] !== 13 || input[position.position + 1] !== 10) {
|
|
6794
6794
|
throw parsingError("expected CRLF");
|
|
6795
6795
|
}
|
|
6796
6796
|
position.position += 2;
|
|
6797
|
-
const result = parseMultipartFormDataHeaders(
|
|
6797
|
+
const result = parseMultipartFormDataHeaders(input, position);
|
|
6798
6798
|
let { name, filename, contentType, encoding } = result;
|
|
6799
6799
|
position.position += 2;
|
|
6800
6800
|
let body;
|
|
6801
6801
|
{
|
|
6802
|
-
const boundaryIndex =
|
|
6802
|
+
const boundaryIndex = input.indexOf(boundary.subarray(2), position.position);
|
|
6803
6803
|
if (boundaryIndex === -1) {
|
|
6804
6804
|
throw parsingError("expected boundary after body");
|
|
6805
6805
|
}
|
|
6806
|
-
body =
|
|
6806
|
+
body = input.subarray(position.position, boundaryIndex - 4);
|
|
6807
6807
|
position.position += body.length;
|
|
6808
6808
|
if (encoding === "base64") {
|
|
6809
6809
|
body = Buffer.from(body.toString(), "base64");
|
|
6810
6810
|
}
|
|
6811
6811
|
}
|
|
6812
|
-
if (
|
|
6812
|
+
if (input[position.position] !== 13 || input[position.position + 1] !== 10) {
|
|
6813
6813
|
throw parsingError("expected CRLF");
|
|
6814
6814
|
} else {
|
|
6815
6815
|
position.position += 2;
|
|
@@ -6829,36 +6829,36 @@ var require_formdata_parser = __commonJS({
|
|
|
6829
6829
|
entryList.push(makeEntry(name, value, filename));
|
|
6830
6830
|
}
|
|
6831
6831
|
}
|
|
6832
|
-
function parseContentDispositionAttribute(
|
|
6833
|
-
if (
|
|
6832
|
+
function parseContentDispositionAttribute(input, position) {
|
|
6833
|
+
if (input[position.position] === 59) {
|
|
6834
6834
|
position.position++;
|
|
6835
6835
|
}
|
|
6836
6836
|
collectASequenceOfBytes(
|
|
6837
6837
|
(char) => char === 32 || char === 9,
|
|
6838
|
-
|
|
6838
|
+
input,
|
|
6839
6839
|
position
|
|
6840
6840
|
);
|
|
6841
6841
|
const attributeName = collectASequenceOfBytes(
|
|
6842
6842
|
(char) => isToken(char) && char !== 61 && char !== 42,
|
|
6843
6843
|
// not = or *
|
|
6844
|
-
|
|
6844
|
+
input,
|
|
6845
6845
|
position
|
|
6846
6846
|
);
|
|
6847
6847
|
if (attributeName.length === 0) {
|
|
6848
6848
|
return null;
|
|
6849
6849
|
}
|
|
6850
6850
|
const attrNameStr = attributeName.toString("ascii").toLowerCase();
|
|
6851
|
-
const isExtended =
|
|
6851
|
+
const isExtended = input[position.position] === 42;
|
|
6852
6852
|
if (isExtended) {
|
|
6853
6853
|
position.position++;
|
|
6854
6854
|
}
|
|
6855
|
-
if (
|
|
6855
|
+
if (input[position.position] !== 61) {
|
|
6856
6856
|
return null;
|
|
6857
6857
|
}
|
|
6858
6858
|
position.position++;
|
|
6859
6859
|
collectASequenceOfBytes(
|
|
6860
6860
|
(char) => char === 32 || char === 9,
|
|
6861
|
-
|
|
6861
|
+
input,
|
|
6862
6862
|
position
|
|
6863
6863
|
);
|
|
6864
6864
|
let value;
|
|
@@ -6866,7 +6866,7 @@ var require_formdata_parser = __commonJS({
|
|
|
6866
6866
|
const headerValue = collectASequenceOfBytes(
|
|
6867
6867
|
(char) => char !== 32 && char !== 13 && char !== 10 && char !== 59,
|
|
6868
6868
|
// not space, CRLF, or ;
|
|
6869
|
-
|
|
6869
|
+
input,
|
|
6870
6870
|
position
|
|
6871
6871
|
);
|
|
6872
6872
|
if (headerValue[0] !== 117 && headerValue[0] !== 85 || // u or U
|
|
@@ -6877,15 +6877,15 @@ var require_formdata_parser = __commonJS({
|
|
|
6877
6877
|
throw parsingError("unknown encoding, expected utf-8''");
|
|
6878
6878
|
}
|
|
6879
6879
|
value = decodeURIComponent(decoder.decode(headerValue.subarray(7)));
|
|
6880
|
-
} else if (
|
|
6880
|
+
} else if (input[position.position] === 34) {
|
|
6881
6881
|
position.position++;
|
|
6882
6882
|
const quotedValue = collectASequenceOfBytes(
|
|
6883
6883
|
(char) => char !== 10 && char !== 13 && char !== 34,
|
|
6884
6884
|
// not LF, CR, or "
|
|
6885
|
-
|
|
6885
|
+
input,
|
|
6886
6886
|
position
|
|
6887
6887
|
);
|
|
6888
|
-
if (
|
|
6888
|
+
if (input[position.position] !== 34) {
|
|
6889
6889
|
throw parsingError("Closing quote not found");
|
|
6890
6890
|
}
|
|
6891
6891
|
position.position++;
|
|
@@ -6894,20 +6894,20 @@ var require_formdata_parser = __commonJS({
|
|
|
6894
6894
|
const tokenValue = collectASequenceOfBytes(
|
|
6895
6895
|
(char) => isToken(char) && char !== 59,
|
|
6896
6896
|
// not ;
|
|
6897
|
-
|
|
6897
|
+
input,
|
|
6898
6898
|
position
|
|
6899
6899
|
);
|
|
6900
6900
|
value = decoder.decode(tokenValue);
|
|
6901
6901
|
}
|
|
6902
6902
|
return { name: attrNameStr, value, extended: isExtended };
|
|
6903
6903
|
}
|
|
6904
|
-
function parseMultipartFormDataHeaders(
|
|
6904
|
+
function parseMultipartFormDataHeaders(input, position) {
|
|
6905
6905
|
let name = null;
|
|
6906
6906
|
let filename = null;
|
|
6907
6907
|
let contentType = null;
|
|
6908
6908
|
let encoding = null;
|
|
6909
6909
|
while (true) {
|
|
6910
|
-
if (
|
|
6910
|
+
if (input[position.position] === 13 && input[position.position + 1] === 10) {
|
|
6911
6911
|
if (name === null) {
|
|
6912
6912
|
throw parsingError("header name is null");
|
|
6913
6913
|
}
|
|
@@ -6915,20 +6915,20 @@ var require_formdata_parser = __commonJS({
|
|
|
6915
6915
|
}
|
|
6916
6916
|
let headerName = collectASequenceOfBytes(
|
|
6917
6917
|
(char) => char !== 10 && char !== 13 && char !== 58,
|
|
6918
|
-
|
|
6918
|
+
input,
|
|
6919
6919
|
position
|
|
6920
6920
|
);
|
|
6921
6921
|
headerName = removeChars(headerName, true, true, (char) => char === 9 || char === 32);
|
|
6922
6922
|
if (!HTTP_TOKEN_CODEPOINTS.test(headerName.toString())) {
|
|
6923
6923
|
throw parsingError("header name does not match the field-name token production");
|
|
6924
6924
|
}
|
|
6925
|
-
if (
|
|
6925
|
+
if (input[position.position] !== 58) {
|
|
6926
6926
|
throw parsingError("expected :");
|
|
6927
6927
|
}
|
|
6928
6928
|
position.position++;
|
|
6929
6929
|
collectASequenceOfBytes(
|
|
6930
6930
|
(char) => char === 32 || char === 9,
|
|
6931
|
-
|
|
6931
|
+
input,
|
|
6932
6932
|
position
|
|
6933
6933
|
);
|
|
6934
6934
|
switch (bufferToLowerCasedHeaderName(headerName)) {
|
|
@@ -6937,14 +6937,14 @@ var require_formdata_parser = __commonJS({
|
|
|
6937
6937
|
let filenameIsExtended = false;
|
|
6938
6938
|
const dispositionType = collectASequenceOfBytes(
|
|
6939
6939
|
(char) => isToken(char),
|
|
6940
|
-
|
|
6940
|
+
input,
|
|
6941
6941
|
position
|
|
6942
6942
|
);
|
|
6943
6943
|
if (dispositionType.toString("ascii").toLowerCase() !== "form-data") {
|
|
6944
6944
|
throw parsingError("expected form-data for content-disposition header");
|
|
6945
6945
|
}
|
|
6946
|
-
while (position.position <
|
|
6947
|
-
const attribute = parseContentDispositionAttribute(
|
|
6946
|
+
while (position.position < input.length && (input[position.position] !== 13 || input[position.position + 1] !== 10)) {
|
|
6947
|
+
const attribute = parseContentDispositionAttribute(input, position);
|
|
6948
6948
|
if (!attribute) {
|
|
6949
6949
|
break;
|
|
6950
6950
|
}
|
|
@@ -6967,7 +6967,7 @@ var require_formdata_parser = __commonJS({
|
|
|
6967
6967
|
case "content-type": {
|
|
6968
6968
|
let headerValue = collectASequenceOfBytes(
|
|
6969
6969
|
(char) => char !== 10 && char !== 13,
|
|
6970
|
-
|
|
6970
|
+
input,
|
|
6971
6971
|
position
|
|
6972
6972
|
);
|
|
6973
6973
|
headerValue = removeChars(headerValue, false, true, (char) => char === 9 || char === 32);
|
|
@@ -6977,7 +6977,7 @@ var require_formdata_parser = __commonJS({
|
|
|
6977
6977
|
case "content-transfer-encoding": {
|
|
6978
6978
|
let headerValue = collectASequenceOfBytes(
|
|
6979
6979
|
(char) => char !== 10 && char !== 13,
|
|
6980
|
-
|
|
6980
|
+
input,
|
|
6981
6981
|
position
|
|
6982
6982
|
);
|
|
6983
6983
|
headerValue = removeChars(headerValue, false, true, (char) => char === 9 || char === 32);
|
|
@@ -6987,24 +6987,24 @@ var require_formdata_parser = __commonJS({
|
|
|
6987
6987
|
default: {
|
|
6988
6988
|
collectASequenceOfBytes(
|
|
6989
6989
|
(char) => char !== 10 && char !== 13,
|
|
6990
|
-
|
|
6990
|
+
input,
|
|
6991
6991
|
position
|
|
6992
6992
|
);
|
|
6993
6993
|
}
|
|
6994
6994
|
}
|
|
6995
|
-
if (
|
|
6995
|
+
if (input[position.position] !== 13 || input[position.position + 1] !== 10) {
|
|
6996
6996
|
throw parsingError("expected CRLF");
|
|
6997
6997
|
} else {
|
|
6998
6998
|
position.position += 2;
|
|
6999
6999
|
}
|
|
7000
7000
|
}
|
|
7001
7001
|
}
|
|
7002
|
-
function collectASequenceOfBytes(condition,
|
|
7002
|
+
function collectASequenceOfBytes(condition, input, position) {
|
|
7003
7003
|
let start = position.position;
|
|
7004
|
-
while (start <
|
|
7004
|
+
while (start < input.length && condition(input[start])) {
|
|
7005
7005
|
++start;
|
|
7006
7006
|
}
|
|
7007
|
-
return
|
|
7007
|
+
return input.subarray(position.position, position.position = start);
|
|
7008
7008
|
}
|
|
7009
7009
|
function removeChars(buf, leading, trailing, predicate) {
|
|
7010
7010
|
let lead = 0;
|
|
@@ -7554,11 +7554,11 @@ var require_client_h1 = __commonJS({
|
|
|
7554
7554
|
* @param {import('net').Socket} socket
|
|
7555
7555
|
* @param {*} llhttp
|
|
7556
7556
|
*/
|
|
7557
|
-
constructor(client,
|
|
7557
|
+
constructor(client, socket, { exports: exports2 }) {
|
|
7558
7558
|
this.llhttp = exports2;
|
|
7559
7559
|
this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE);
|
|
7560
7560
|
this.client = client;
|
|
7561
|
-
this.socket =
|
|
7561
|
+
this.socket = socket;
|
|
7562
7562
|
this.timeout = null;
|
|
7563
7563
|
this.timeoutWeakRef = new WeakRef(this);
|
|
7564
7564
|
this.timeoutValue = null;
|
|
@@ -7578,21 +7578,21 @@ var require_client_h1 = __commonJS({
|
|
|
7578
7578
|
this.connection = "";
|
|
7579
7579
|
this.maxResponseSize = client[kMaxResponseSize];
|
|
7580
7580
|
}
|
|
7581
|
-
setTimeout(
|
|
7582
|
-
if (
|
|
7581
|
+
setTimeout(delay2, type) {
|
|
7582
|
+
if (delay2 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
|
|
7583
7583
|
if (this.timeout) {
|
|
7584
7584
|
timers.clearTimeout(this.timeout);
|
|
7585
7585
|
this.timeout = null;
|
|
7586
7586
|
}
|
|
7587
|
-
if (
|
|
7587
|
+
if (delay2) {
|
|
7588
7588
|
if (type & USE_FAST_TIMER) {
|
|
7589
|
-
this.timeout = timers.setFastTimeout(onParserTimeout,
|
|
7589
|
+
this.timeout = timers.setFastTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
|
|
7590
7590
|
} else {
|
|
7591
|
-
this.timeout = setTimeout(onParserTimeout,
|
|
7591
|
+
this.timeout = setTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
|
|
7592
7592
|
this.timeout?.unref();
|
|
7593
7593
|
}
|
|
7594
7594
|
}
|
|
7595
|
-
this.timeoutValue =
|
|
7595
|
+
this.timeoutValue = delay2;
|
|
7596
7596
|
} else if (this.timeout) {
|
|
7597
7597
|
if (this.timeout.refresh) {
|
|
7598
7598
|
this.timeout.refresh();
|
|
@@ -7633,7 +7633,7 @@ var require_client_h1 = __commonJS({
|
|
|
7633
7633
|
assert(currentParser === null);
|
|
7634
7634
|
assert(this.ptr != null);
|
|
7635
7635
|
assert(!this.paused);
|
|
7636
|
-
const { socket
|
|
7636
|
+
const { socket, llhttp } = this;
|
|
7637
7637
|
if (chunk.length > currentBufferSize) {
|
|
7638
7638
|
if (currentBufferPtr) {
|
|
7639
7639
|
llhttp.free(currentBufferPtr);
|
|
@@ -7658,13 +7658,13 @@ var require_client_h1 = __commonJS({
|
|
|
7658
7658
|
this.onUpgrade(data);
|
|
7659
7659
|
} else if (ret === constants.ERROR.PAUSED) {
|
|
7660
7660
|
this.paused = true;
|
|
7661
|
-
|
|
7661
|
+
socket.unshift(data);
|
|
7662
7662
|
} else {
|
|
7663
7663
|
throw this.createError(ret, data);
|
|
7664
7664
|
}
|
|
7665
7665
|
}
|
|
7666
7666
|
} catch (err) {
|
|
7667
|
-
util.destroy(
|
|
7667
|
+
util.destroy(socket, err);
|
|
7668
7668
|
}
|
|
7669
7669
|
}
|
|
7670
7670
|
finish() {
|
|
@@ -7724,12 +7724,12 @@ var require_client_h1 = __commonJS({
|
|
|
7724
7724
|
* @returns {0|-1}
|
|
7725
7725
|
*/
|
|
7726
7726
|
onMessageBegin() {
|
|
7727
|
-
const { socket
|
|
7728
|
-
if (
|
|
7727
|
+
const { socket, client } = this;
|
|
7728
|
+
if (socket.destroyed) {
|
|
7729
7729
|
return -1;
|
|
7730
7730
|
}
|
|
7731
7731
|
if (client[kRunning] === 0) {
|
|
7732
|
-
util.destroy(
|
|
7732
|
+
util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
|
|
7733
7733
|
return -1;
|
|
7734
7734
|
}
|
|
7735
7735
|
const request = client[kQueue][client[kRunningIdx]];
|
|
@@ -7792,10 +7792,10 @@ var require_client_h1 = __commonJS({
|
|
|
7792
7792
|
* @param {Buffer} head
|
|
7793
7793
|
*/
|
|
7794
7794
|
onUpgrade(head) {
|
|
7795
|
-
const { upgrade, client, socket
|
|
7795
|
+
const { upgrade, client, socket, headers, statusCode, statusText } = this;
|
|
7796
7796
|
assert(upgrade);
|
|
7797
|
-
assert(client[kSocket] ===
|
|
7798
|
-
assert(!
|
|
7797
|
+
assert(client[kSocket] === socket);
|
|
7798
|
+
assert(!socket.destroyed);
|
|
7799
7799
|
assert(!this.paused);
|
|
7800
7800
|
assert((headers.length & 1) === 0);
|
|
7801
7801
|
const request = client[kQueue][client[kRunningIdx]];
|
|
@@ -7806,21 +7806,21 @@ var require_client_h1 = __commonJS({
|
|
|
7806
7806
|
this.shouldKeepAlive = false;
|
|
7807
7807
|
this.headers = [];
|
|
7808
7808
|
this.headersSize = 0;
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
removeAllListeners(
|
|
7809
|
+
socket.unshift(head);
|
|
7810
|
+
socket[kParser].destroy();
|
|
7811
|
+
socket[kParser] = null;
|
|
7812
|
+
socket[kClient] = null;
|
|
7813
|
+
socket[kError] = null;
|
|
7814
|
+
removeAllListeners(socket);
|
|
7815
7815
|
client[kSocket] = null;
|
|
7816
7816
|
client[kHTTPContext] = null;
|
|
7817
7817
|
client[kQueue][client[kRunningIdx]++] = null;
|
|
7818
7818
|
client.emit("disconnect", client[kUrl], [client], new InformationalError("upgrade"));
|
|
7819
7819
|
try {
|
|
7820
|
-
request.onUpgrade(statusCode, headers,
|
|
7820
|
+
request.onUpgrade(statusCode, headers, socket, statusText);
|
|
7821
7821
|
} catch (err) {
|
|
7822
7822
|
util.errorRequest(client, request, err);
|
|
7823
|
-
util.destroy(
|
|
7823
|
+
util.destroy(socket, err);
|
|
7824
7824
|
}
|
|
7825
7825
|
client[kResume]();
|
|
7826
7826
|
}
|
|
@@ -7831,12 +7831,12 @@ var require_client_h1 = __commonJS({
|
|
|
7831
7831
|
* @returns {number}
|
|
7832
7832
|
*/
|
|
7833
7833
|
onHeadersComplete(statusCode, upgrade, shouldKeepAlive) {
|
|
7834
|
-
const { client, socket
|
|
7835
|
-
if (
|
|
7834
|
+
const { client, socket, headers, statusText } = this;
|
|
7835
|
+
if (socket.destroyed) {
|
|
7836
7836
|
return -1;
|
|
7837
7837
|
}
|
|
7838
7838
|
if (client[kRunning] === 0) {
|
|
7839
|
-
util.destroy(
|
|
7839
|
+
util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
|
|
7840
7840
|
return -1;
|
|
7841
7841
|
}
|
|
7842
7842
|
const request = client[kQueue][client[kRunningIdx]];
|
|
@@ -7846,17 +7846,17 @@ var require_client_h1 = __commonJS({
|
|
|
7846
7846
|
assert(!this.upgrade);
|
|
7847
7847
|
assert(this.statusCode < 200);
|
|
7848
7848
|
if (statusCode === 100) {
|
|
7849
|
-
util.destroy(
|
|
7849
|
+
util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
|
|
7850
7850
|
return -1;
|
|
7851
7851
|
}
|
|
7852
7852
|
if (upgrade && !request.upgrade) {
|
|
7853
|
-
util.destroy(
|
|
7853
|
+
util.destroy(socket, new SocketError("bad upgrade", util.getSocketInfo(socket)));
|
|
7854
7854
|
return -1;
|
|
7855
7855
|
}
|
|
7856
7856
|
assert(this.timeoutType === TIMEOUT_HEADERS);
|
|
7857
7857
|
this.statusCode = statusCode;
|
|
7858
7858
|
this.shouldKeepAlive = shouldKeepAlive || // Override llhttp value which does not allow keepAlive for HEAD.
|
|
7859
|
-
request.method === "HEAD" && !
|
|
7859
|
+
request.method === "HEAD" && !socket[kReset] && this.connection.toLowerCase() === "keep-alive";
|
|
7860
7860
|
if (this.statusCode >= 200) {
|
|
7861
7861
|
const bodyTimeout = request.bodyTimeout != null ? request.bodyTimeout : client[kBodyTimeout];
|
|
7862
7862
|
this.setTimeout(bodyTimeout, TIMEOUT_BODY);
|
|
@@ -7886,7 +7886,7 @@ var require_client_h1 = __commonJS({
|
|
|
7886
7886
|
client[kKeepAliveMaxTimeout]
|
|
7887
7887
|
);
|
|
7888
7888
|
if (timeout <= 0) {
|
|
7889
|
-
|
|
7889
|
+
socket[kReset] = true;
|
|
7890
7890
|
} else {
|
|
7891
7891
|
client[kKeepAliveTimeoutValue] = timeout;
|
|
7892
7892
|
}
|
|
@@ -7894,7 +7894,7 @@ var require_client_h1 = __commonJS({
|
|
|
7894
7894
|
client[kKeepAliveTimeoutValue] = client[kKeepAliveDefaultTimeout];
|
|
7895
7895
|
}
|
|
7896
7896
|
} else {
|
|
7897
|
-
|
|
7897
|
+
socket[kReset] = true;
|
|
7898
7898
|
}
|
|
7899
7899
|
const pause = request.onHeaders(statusCode, headers, this.resume, statusText) === false;
|
|
7900
7900
|
if (request.aborted) {
|
|
@@ -7906,8 +7906,8 @@ var require_client_h1 = __commonJS({
|
|
|
7906
7906
|
if (statusCode < 200) {
|
|
7907
7907
|
return 1;
|
|
7908
7908
|
}
|
|
7909
|
-
if (
|
|
7910
|
-
|
|
7909
|
+
if (socket[kBlocking]) {
|
|
7910
|
+
socket[kBlocking] = false;
|
|
7911
7911
|
client[kResume]();
|
|
7912
7912
|
}
|
|
7913
7913
|
return pause ? constants.ERROR.PAUSED : 0;
|
|
@@ -7917,8 +7917,8 @@ var require_client_h1 = __commonJS({
|
|
|
7917
7917
|
* @returns {number}
|
|
7918
7918
|
*/
|
|
7919
7919
|
onBody(buf) {
|
|
7920
|
-
const { client, socket
|
|
7921
|
-
if (
|
|
7920
|
+
const { client, socket, statusCode, maxResponseSize } = this;
|
|
7921
|
+
if (socket.destroyed) {
|
|
7922
7922
|
return -1;
|
|
7923
7923
|
}
|
|
7924
7924
|
const request = client[kQueue][client[kRunningIdx]];
|
|
@@ -7931,7 +7931,7 @@ var require_client_h1 = __commonJS({
|
|
|
7931
7931
|
}
|
|
7932
7932
|
assert(statusCode >= 200);
|
|
7933
7933
|
if (maxResponseSize > -1 && this.bytesRead + buf.length > maxResponseSize) {
|
|
7934
|
-
util.destroy(
|
|
7934
|
+
util.destroy(socket, new ResponseExceededMaxSizeError());
|
|
7935
7935
|
return -1;
|
|
7936
7936
|
}
|
|
7937
7937
|
this.bytesRead += buf.length;
|
|
@@ -7944,8 +7944,8 @@ var require_client_h1 = __commonJS({
|
|
|
7944
7944
|
* @returns {number}
|
|
7945
7945
|
*/
|
|
7946
7946
|
onMessageComplete() {
|
|
7947
|
-
const { client, socket
|
|
7948
|
-
if (
|
|
7947
|
+
const { client, socket, statusCode, upgrade, headers, contentLength, bytesRead, shouldKeepAlive } = this;
|
|
7948
|
+
if (socket.destroyed && (!statusCode || shouldKeepAlive)) {
|
|
7949
7949
|
return -1;
|
|
7950
7950
|
}
|
|
7951
7951
|
if (upgrade) {
|
|
@@ -7967,21 +7967,21 @@ var require_client_h1 = __commonJS({
|
|
|
7967
7967
|
return 0;
|
|
7968
7968
|
}
|
|
7969
7969
|
if (request.method !== "HEAD" && contentLength && bytesRead !== parseInt(contentLength, 10)) {
|
|
7970
|
-
util.destroy(
|
|
7970
|
+
util.destroy(socket, new ResponseContentLengthMismatchError());
|
|
7971
7971
|
return -1;
|
|
7972
7972
|
}
|
|
7973
7973
|
request.onComplete(headers);
|
|
7974
7974
|
client[kQueue][client[kRunningIdx]++] = null;
|
|
7975
|
-
|
|
7976
|
-
if (
|
|
7975
|
+
socket[kSocketUsed] = client[kPending] === 0;
|
|
7976
|
+
if (socket[kWriting]) {
|
|
7977
7977
|
assert(client[kRunning] === 0);
|
|
7978
|
-
util.destroy(
|
|
7978
|
+
util.destroy(socket, new InformationalError("reset"));
|
|
7979
7979
|
return constants.ERROR.PAUSED;
|
|
7980
7980
|
} else if (!shouldKeepAlive) {
|
|
7981
|
-
util.destroy(
|
|
7981
|
+
util.destroy(socket, new InformationalError("reset"));
|
|
7982
7982
|
return constants.ERROR.PAUSED;
|
|
7983
|
-
} else if (
|
|
7984
|
-
util.destroy(
|
|
7983
|
+
} else if (socket[kReset] && client[kRunning] === 0) {
|
|
7984
|
+
util.destroy(socket, new InformationalError("reset"));
|
|
7985
7985
|
return constants.ERROR.PAUSED;
|
|
7986
7986
|
} else if (client[kPipelining] == null || client[kPipelining] === 1) {
|
|
7987
7987
|
setImmediate(client[kResume]);
|
|
@@ -7996,46 +7996,46 @@ var require_client_h1 = __commonJS({
|
|
|
7996
7996
|
if (!parser) {
|
|
7997
7997
|
return;
|
|
7998
7998
|
}
|
|
7999
|
-
const { socket
|
|
7999
|
+
const { socket, timeoutType, client, paused } = parser;
|
|
8000
8000
|
if (timeoutType === TIMEOUT_HEADERS) {
|
|
8001
|
-
if (!
|
|
8001
|
+
if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) {
|
|
8002
8002
|
assert(!paused, "cannot be paused while waiting for headers");
|
|
8003
|
-
util.destroy(
|
|
8003
|
+
util.destroy(socket, new HeadersTimeoutError());
|
|
8004
8004
|
}
|
|
8005
8005
|
} else if (timeoutType === TIMEOUT_BODY) {
|
|
8006
8006
|
if (!paused) {
|
|
8007
|
-
util.destroy(
|
|
8007
|
+
util.destroy(socket, new BodyTimeoutError());
|
|
8008
8008
|
}
|
|
8009
8009
|
} else if (timeoutType === TIMEOUT_KEEP_ALIVE) {
|
|
8010
8010
|
assert(client[kRunning] === 0 && client[kKeepAliveTimeoutValue]);
|
|
8011
|
-
util.destroy(
|
|
8011
|
+
util.destroy(socket, new InformationalError("socket idle timeout"));
|
|
8012
8012
|
}
|
|
8013
8013
|
}
|
|
8014
|
-
function connectH1(client,
|
|
8015
|
-
client[kSocket] =
|
|
8014
|
+
function connectH1(client, socket) {
|
|
8015
|
+
client[kSocket] = socket;
|
|
8016
8016
|
if (!llhttpInstance) {
|
|
8017
8017
|
llhttpInstance = lazyllhttp();
|
|
8018
8018
|
}
|
|
8019
|
-
if (
|
|
8020
|
-
throw
|
|
8019
|
+
if (socket.errored) {
|
|
8020
|
+
throw socket.errored;
|
|
8021
8021
|
}
|
|
8022
|
-
if (
|
|
8022
|
+
if (socket.destroyed) {
|
|
8023
8023
|
throw new SocketError("destroyed");
|
|
8024
8024
|
}
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
util.addListener(
|
|
8034
|
-
util.addListener(
|
|
8035
|
-
util.addListener(
|
|
8036
|
-
util.addListener(
|
|
8037
|
-
|
|
8038
|
-
|
|
8025
|
+
socket[kNoRef] = false;
|
|
8026
|
+
socket[kWriting] = false;
|
|
8027
|
+
socket[kReset] = false;
|
|
8028
|
+
socket[kBlocking] = false;
|
|
8029
|
+
socket[kIdleSocketValidation] = 0;
|
|
8030
|
+
socket[kIdleSocketValidationTimeout] = null;
|
|
8031
|
+
socket[kSocketUsed] = false;
|
|
8032
|
+
socket[kParser] = new Parser(client, socket, llhttpInstance);
|
|
8033
|
+
util.addListener(socket, "error", onHttpSocketError);
|
|
8034
|
+
util.addListener(socket, "readable", onHttpSocketReadable);
|
|
8035
|
+
util.addListener(socket, "end", onHttpSocketEnd);
|
|
8036
|
+
util.addListener(socket, "close", onHttpSocketClose);
|
|
8037
|
+
socket[kClosed] = false;
|
|
8038
|
+
socket.on("close", onSocketClose);
|
|
8039
8039
|
return {
|
|
8040
8040
|
version: "h1",
|
|
8041
8041
|
defaultPipelining: 1,
|
|
@@ -8050,25 +8050,25 @@ var require_client_h1 = __commonJS({
|
|
|
8050
8050
|
* @param {() => void} callback
|
|
8051
8051
|
*/
|
|
8052
8052
|
destroy(err, callback) {
|
|
8053
|
-
if (
|
|
8053
|
+
if (socket[kClosed]) {
|
|
8054
8054
|
queueMicrotask(callback);
|
|
8055
8055
|
} else {
|
|
8056
|
-
|
|
8057
|
-
|
|
8056
|
+
socket.on("close", callback);
|
|
8057
|
+
socket.destroy(err);
|
|
8058
8058
|
}
|
|
8059
8059
|
},
|
|
8060
8060
|
/**
|
|
8061
8061
|
* @returns {boolean}
|
|
8062
8062
|
*/
|
|
8063
8063
|
get destroyed() {
|
|
8064
|
-
return
|
|
8064
|
+
return socket.destroyed;
|
|
8065
8065
|
},
|
|
8066
8066
|
/**
|
|
8067
8067
|
* @param {import('../core/request.js')} request
|
|
8068
8068
|
* @returns {boolean}
|
|
8069
8069
|
*/
|
|
8070
8070
|
busy(request) {
|
|
8071
|
-
if (
|
|
8071
|
+
if (socket[kWriting] || socket[kReset] || socket[kBlocking] || socket[kIdleSocketValidation] === 1) {
|
|
8072
8072
|
return true;
|
|
8073
8073
|
}
|
|
8074
8074
|
if (request) {
|
|
@@ -8147,67 +8147,67 @@ var require_client_h1 = __commonJS({
|
|
|
8147
8147
|
function onSocketClose() {
|
|
8148
8148
|
this[kClosed] = true;
|
|
8149
8149
|
}
|
|
8150
|
-
function clearIdleSocketValidation(
|
|
8151
|
-
if (
|
|
8152
|
-
clearImmediate(
|
|
8153
|
-
|
|
8150
|
+
function clearIdleSocketValidation(socket) {
|
|
8151
|
+
if (socket[kIdleSocketValidationTimeout]) {
|
|
8152
|
+
clearImmediate(socket[kIdleSocketValidationTimeout]);
|
|
8153
|
+
socket[kIdleSocketValidationTimeout] = null;
|
|
8154
8154
|
}
|
|
8155
|
-
|
|
8155
|
+
socket[kIdleSocketValidation] = 0;
|
|
8156
8156
|
}
|
|
8157
|
-
function scheduleIdleSocketValidation(client,
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
if (client[kSocket] ===
|
|
8157
|
+
function scheduleIdleSocketValidation(client, socket) {
|
|
8158
|
+
socket[kIdleSocketValidation] = 1;
|
|
8159
|
+
socket[kIdleSocketValidationTimeout] = setImmediate(() => {
|
|
8160
|
+
socket[kIdleSocketValidationTimeout] = null;
|
|
8161
|
+
socket[kIdleSocketValidation] = 2;
|
|
8162
|
+
if (client[kSocket] === socket && !socket.destroyed) {
|
|
8163
8163
|
client[kResume]();
|
|
8164
8164
|
}
|
|
8165
8165
|
});
|
|
8166
8166
|
}
|
|
8167
8167
|
function resumeH1(client) {
|
|
8168
|
-
const
|
|
8169
|
-
if (
|
|
8168
|
+
const socket = client[kSocket];
|
|
8169
|
+
if (socket && !socket.destroyed) {
|
|
8170
8170
|
if (client[kSize] === 0) {
|
|
8171
|
-
if (!
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
}
|
|
8175
|
-
} else if (
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
}
|
|
8179
|
-
if (client[kRunning] === 0 && client[kPending] > 0 &&
|
|
8180
|
-
if (
|
|
8181
|
-
scheduleIdleSocketValidation(client,
|
|
8182
|
-
|
|
8183
|
-
if (
|
|
8171
|
+
if (!socket[kNoRef] && socket.unref) {
|
|
8172
|
+
socket.unref();
|
|
8173
|
+
socket[kNoRef] = true;
|
|
8174
|
+
}
|
|
8175
|
+
} else if (socket[kNoRef] && socket.ref) {
|
|
8176
|
+
socket.ref();
|
|
8177
|
+
socket[kNoRef] = false;
|
|
8178
|
+
}
|
|
8179
|
+
if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) {
|
|
8180
|
+
if (socket[kIdleSocketValidation] === 0) {
|
|
8181
|
+
scheduleIdleSocketValidation(client, socket);
|
|
8182
|
+
socket[kParser].readMore();
|
|
8183
|
+
if (socket.destroyed) {
|
|
8184
8184
|
return;
|
|
8185
8185
|
}
|
|
8186
8186
|
return;
|
|
8187
8187
|
}
|
|
8188
|
-
if (
|
|
8189
|
-
|
|
8190
|
-
if (
|
|
8188
|
+
if (socket[kIdleSocketValidation] === 1) {
|
|
8189
|
+
socket[kParser].readMore();
|
|
8190
|
+
if (socket.destroyed) {
|
|
8191
8191
|
return;
|
|
8192
8192
|
}
|
|
8193
8193
|
return;
|
|
8194
8194
|
}
|
|
8195
8195
|
}
|
|
8196
8196
|
if (client[kRunning] === 0) {
|
|
8197
|
-
|
|
8198
|
-
if (
|
|
8197
|
+
socket[kParser].readMore();
|
|
8198
|
+
if (socket.destroyed) {
|
|
8199
8199
|
return;
|
|
8200
8200
|
}
|
|
8201
8201
|
}
|
|
8202
8202
|
if (client[kSize] === 0) {
|
|
8203
|
-
if (
|
|
8204
|
-
|
|
8203
|
+
if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) {
|
|
8204
|
+
socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE);
|
|
8205
8205
|
}
|
|
8206
|
-
} else if (client[kRunning] > 0 &&
|
|
8207
|
-
if (
|
|
8206
|
+
} else if (client[kRunning] > 0 && socket[kParser].statusCode < 200) {
|
|
8207
|
+
if (socket[kParser].timeoutType !== TIMEOUT_HEADERS) {
|
|
8208
8208
|
const request = client[kQueue][client[kRunningIdx]];
|
|
8209
8209
|
const headersTimeout = request.headersTimeout != null ? request.headersTimeout : client[kHeadersTimeout];
|
|
8210
|
-
|
|
8210
|
+
socket[kParser].setTimeout(headersTimeout, TIMEOUT_HEADERS);
|
|
8211
8211
|
}
|
|
8212
8212
|
}
|
|
8213
8213
|
}
|
|
@@ -8215,21 +8215,21 @@ var require_client_h1 = __commonJS({
|
|
|
8215
8215
|
function shouldSendContentLength(method) {
|
|
8216
8216
|
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
|
|
8217
8217
|
}
|
|
8218
|
-
function setTypeOfService(
|
|
8219
|
-
if (typeof
|
|
8218
|
+
function setTypeOfService(socket, request) {
|
|
8219
|
+
if (typeof socket.setTypeOfService !== "function") {
|
|
8220
8220
|
return;
|
|
8221
8221
|
}
|
|
8222
8222
|
const typeOfService = request.typeOfService;
|
|
8223
8223
|
if (typeOfService === void 0) {
|
|
8224
8224
|
return;
|
|
8225
8225
|
}
|
|
8226
|
-
const currentTypeOfService =
|
|
8226
|
+
const currentTypeOfService = socket[kTypeOfService];
|
|
8227
8227
|
if (currentTypeOfService === typeOfService) {
|
|
8228
8228
|
return;
|
|
8229
8229
|
}
|
|
8230
8230
|
try {
|
|
8231
|
-
|
|
8232
|
-
|
|
8231
|
+
socket.setTypeOfService(typeOfService);
|
|
8232
|
+
socket[kTypeOfService] = typeOfService;
|
|
8233
8233
|
} catch {
|
|
8234
8234
|
}
|
|
8235
8235
|
}
|
|
@@ -8276,15 +8276,15 @@ var require_client_h1 = __commonJS({
|
|
|
8276
8276
|
}
|
|
8277
8277
|
process.emitWarning(new RequestContentLengthMismatchError());
|
|
8278
8278
|
}
|
|
8279
|
-
const
|
|
8280
|
-
clearIdleSocketValidation(
|
|
8279
|
+
const socket = client[kSocket];
|
|
8280
|
+
clearIdleSocketValidation(socket);
|
|
8281
8281
|
const abort = (err) => {
|
|
8282
8282
|
if (request.aborted || request.completed) {
|
|
8283
8283
|
return;
|
|
8284
8284
|
}
|
|
8285
8285
|
util.errorRequest(client, request, err || new RequestAbortedError());
|
|
8286
8286
|
util.destroy(body);
|
|
8287
|
-
util.destroy(
|
|
8287
|
+
util.destroy(socket, new InformationalError("aborted"));
|
|
8288
8288
|
};
|
|
8289
8289
|
try {
|
|
8290
8290
|
request.onConnect(abort);
|
|
@@ -8295,21 +8295,21 @@ var require_client_h1 = __commonJS({
|
|
|
8295
8295
|
return false;
|
|
8296
8296
|
}
|
|
8297
8297
|
if (method === "HEAD") {
|
|
8298
|
-
|
|
8298
|
+
socket[kReset] = true;
|
|
8299
8299
|
}
|
|
8300
8300
|
if (upgrade || method === "CONNECT") {
|
|
8301
|
-
|
|
8301
|
+
socket[kReset] = true;
|
|
8302
8302
|
}
|
|
8303
8303
|
if (reset != null) {
|
|
8304
|
-
|
|
8304
|
+
socket[kReset] = reset;
|
|
8305
8305
|
}
|
|
8306
|
-
if (client[kMaxRequests] &&
|
|
8307
|
-
|
|
8306
|
+
if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
|
|
8307
|
+
socket[kReset] = true;
|
|
8308
8308
|
}
|
|
8309
8309
|
if (blocking) {
|
|
8310
|
-
|
|
8310
|
+
socket[kBlocking] = true;
|
|
8311
8311
|
}
|
|
8312
|
-
setTypeOfService(
|
|
8312
|
+
setTypeOfService(socket, request);
|
|
8313
8313
|
let header = `${method} ${path8} HTTP/1.1\r
|
|
8314
8314
|
`;
|
|
8315
8315
|
if (typeof host === "string") {
|
|
@@ -8322,7 +8322,7 @@ var require_client_h1 = __commonJS({
|
|
|
8322
8322
|
header += `connection: upgrade\r
|
|
8323
8323
|
upgrade: ${upgrade}\r
|
|
8324
8324
|
`;
|
|
8325
|
-
} else if (client[kPipelining] && !
|
|
8325
|
+
} else if (client[kPipelining] && !socket[kReset]) {
|
|
8326
8326
|
header += "connection: keep-alive\r\n";
|
|
8327
8327
|
} else {
|
|
8328
8328
|
header += "connection: close\r\n";
|
|
@@ -8343,31 +8343,31 @@ upgrade: ${upgrade}\r
|
|
|
8343
8343
|
}
|
|
8344
8344
|
}
|
|
8345
8345
|
if (channels.sendHeaders.hasSubscribers) {
|
|
8346
|
-
channels.sendHeaders.publish({ request, headers: header, socket
|
|
8346
|
+
channels.sendHeaders.publish({ request, headers: header, socket });
|
|
8347
8347
|
}
|
|
8348
8348
|
if (!body || bodyLength === 0) {
|
|
8349
|
-
writeBuffer(abort, null, client, request,
|
|
8349
|
+
writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload);
|
|
8350
8350
|
} else if (util.isBuffer(body)) {
|
|
8351
|
-
writeBuffer(abort, body, client, request,
|
|
8351
|
+
writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload);
|
|
8352
8352
|
} else if (util.isBlobLike(body)) {
|
|
8353
8353
|
if (typeof body.stream === "function") {
|
|
8354
|
-
writeIterable(abort, body.stream(), client, request,
|
|
8354
|
+
writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload);
|
|
8355
8355
|
} else {
|
|
8356
|
-
writeBlob(abort, body, client, request,
|
|
8356
|
+
writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload);
|
|
8357
8357
|
}
|
|
8358
8358
|
} else if (util.isStream(body)) {
|
|
8359
|
-
writeStream(abort, body, client, request,
|
|
8359
|
+
writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload);
|
|
8360
8360
|
} else if (util.isIterable(body)) {
|
|
8361
|
-
writeIterable(abort, body, client, request,
|
|
8361
|
+
writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload);
|
|
8362
8362
|
} else {
|
|
8363
8363
|
assert(false);
|
|
8364
8364
|
}
|
|
8365
8365
|
return true;
|
|
8366
8366
|
}
|
|
8367
|
-
function writeStream(abort, body, client, request,
|
|
8367
|
+
function writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload) {
|
|
8368
8368
|
assert(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
|
|
8369
8369
|
let finished = false;
|
|
8370
|
-
const writer = new AsyncWriter({ abort, socket
|
|
8370
|
+
const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
|
|
8371
8371
|
const onData = function(chunk) {
|
|
8372
8372
|
if (finished) {
|
|
8373
8373
|
return;
|
|
@@ -8402,8 +8402,8 @@ upgrade: ${upgrade}\r
|
|
|
8402
8402
|
return;
|
|
8403
8403
|
}
|
|
8404
8404
|
finished = true;
|
|
8405
|
-
assert(
|
|
8406
|
-
|
|
8405
|
+
assert(socket.destroyed || socket[kWriting] && client[kRunning] <= 1);
|
|
8406
|
+
socket.off("drain", onDrain).off("error", onFinished);
|
|
8407
8407
|
body.removeListener("data", onData).removeListener("end", onFinished).removeListener("close", onClose);
|
|
8408
8408
|
if (!err) {
|
|
8409
8409
|
try {
|
|
@@ -8423,7 +8423,7 @@ upgrade: ${upgrade}\r
|
|
|
8423
8423
|
if (body.resume) {
|
|
8424
8424
|
body.resume();
|
|
8425
8425
|
}
|
|
8426
|
-
|
|
8426
|
+
socket.on("drain", onDrain).on("error", onFinished);
|
|
8427
8427
|
if (body.errorEmitted ?? body.errored) {
|
|
8428
8428
|
setImmediate(onFinished, body.errored);
|
|
8429
8429
|
} else if (body.endEmitted ?? body.readableEnded) {
|
|
@@ -8433,29 +8433,29 @@ upgrade: ${upgrade}\r
|
|
|
8433
8433
|
setImmediate(onClose);
|
|
8434
8434
|
}
|
|
8435
8435
|
}
|
|
8436
|
-
function writeBuffer(abort, body, client, request,
|
|
8436
|
+
function writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload) {
|
|
8437
8437
|
try {
|
|
8438
8438
|
if (!body) {
|
|
8439
8439
|
if (contentLength === 0) {
|
|
8440
|
-
|
|
8440
|
+
socket.write(`${header}content-length: 0\r
|
|
8441
8441
|
\r
|
|
8442
8442
|
`, "latin1");
|
|
8443
8443
|
} else {
|
|
8444
8444
|
assert(contentLength === null, "no body must not have content length");
|
|
8445
|
-
|
|
8445
|
+
socket.write(`${header}\r
|
|
8446
8446
|
`, "latin1");
|
|
8447
8447
|
}
|
|
8448
8448
|
} else if (util.isBuffer(body)) {
|
|
8449
8449
|
assert(contentLength === body.byteLength, "buffer body must have content length");
|
|
8450
|
-
|
|
8451
|
-
|
|
8450
|
+
socket.cork();
|
|
8451
|
+
socket.write(`${header}content-length: ${contentLength}\r
|
|
8452
8452
|
\r
|
|
8453
8453
|
`, "latin1");
|
|
8454
|
-
|
|
8455
|
-
|
|
8454
|
+
socket.write(body);
|
|
8455
|
+
socket.uncork();
|
|
8456
8456
|
request.onBodySent(body);
|
|
8457
8457
|
if (!expectsPayload && request.reset !== false) {
|
|
8458
|
-
|
|
8458
|
+
socket[kReset] = true;
|
|
8459
8459
|
}
|
|
8460
8460
|
}
|
|
8461
8461
|
request.onRequestSent();
|
|
@@ -8464,30 +8464,30 @@ upgrade: ${upgrade}\r
|
|
|
8464
8464
|
abort(err);
|
|
8465
8465
|
}
|
|
8466
8466
|
}
|
|
8467
|
-
async function writeBlob(abort, body, client, request,
|
|
8467
|
+
async function writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload) {
|
|
8468
8468
|
assert(contentLength === body.size, "blob body must have content length");
|
|
8469
8469
|
try {
|
|
8470
8470
|
if (contentLength != null && contentLength !== body.size) {
|
|
8471
8471
|
throw new RequestContentLengthMismatchError();
|
|
8472
8472
|
}
|
|
8473
8473
|
const buffer = Buffer.from(await body.arrayBuffer());
|
|
8474
|
-
|
|
8475
|
-
|
|
8474
|
+
socket.cork();
|
|
8475
|
+
socket.write(`${header}content-length: ${contentLength}\r
|
|
8476
8476
|
\r
|
|
8477
8477
|
`, "latin1");
|
|
8478
|
-
|
|
8479
|
-
|
|
8478
|
+
socket.write(buffer);
|
|
8479
|
+
socket.uncork();
|
|
8480
8480
|
request.onBodySent(buffer);
|
|
8481
8481
|
request.onRequestSent();
|
|
8482
8482
|
if (!expectsPayload && request.reset !== false) {
|
|
8483
|
-
|
|
8483
|
+
socket[kReset] = true;
|
|
8484
8484
|
}
|
|
8485
8485
|
client[kResume]();
|
|
8486
8486
|
} catch (err) {
|
|
8487
8487
|
abort(err);
|
|
8488
8488
|
}
|
|
8489
8489
|
}
|
|
8490
|
-
async function writeIterable(abort, body, client, request,
|
|
8490
|
+
async function writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload) {
|
|
8491
8491
|
assert(contentLength !== 0 || client[kRunning] === 0, "iterator body cannot be pipelined");
|
|
8492
8492
|
let callback = null;
|
|
8493
8493
|
function onDrain() {
|
|
@@ -8499,18 +8499,18 @@ upgrade: ${upgrade}\r
|
|
|
8499
8499
|
}
|
|
8500
8500
|
const waitForDrain = () => new Promise((resolve, reject) => {
|
|
8501
8501
|
assert(callback === null);
|
|
8502
|
-
if (
|
|
8503
|
-
reject(
|
|
8502
|
+
if (socket[kError]) {
|
|
8503
|
+
reject(socket[kError]);
|
|
8504
8504
|
} else {
|
|
8505
8505
|
callback = resolve;
|
|
8506
8506
|
}
|
|
8507
8507
|
});
|
|
8508
|
-
|
|
8509
|
-
const writer = new AsyncWriter({ abort, socket
|
|
8508
|
+
socket.on("close", onDrain).on("drain", onDrain);
|
|
8509
|
+
const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
|
|
8510
8510
|
try {
|
|
8511
8511
|
for await (const chunk of body) {
|
|
8512
|
-
if (
|
|
8513
|
-
throw
|
|
8512
|
+
if (socket[kError]) {
|
|
8513
|
+
throw socket[kError];
|
|
8514
8514
|
}
|
|
8515
8515
|
if (!writer.write(chunk)) {
|
|
8516
8516
|
await waitForDrain();
|
|
@@ -8520,7 +8520,7 @@ upgrade: ${upgrade}\r
|
|
|
8520
8520
|
} catch (err) {
|
|
8521
8521
|
writer.destroy(err);
|
|
8522
8522
|
} finally {
|
|
8523
|
-
|
|
8523
|
+
socket.off("close", onDrain).off("drain", onDrain);
|
|
8524
8524
|
}
|
|
8525
8525
|
}
|
|
8526
8526
|
var AsyncWriter = class {
|
|
@@ -8535,8 +8535,8 @@ upgrade: ${upgrade}\r
|
|
|
8535
8535
|
* @param {boolean} arg.expectsPayload
|
|
8536
8536
|
* @param {string} arg.header
|
|
8537
8537
|
*/
|
|
8538
|
-
constructor({ abort, socket
|
|
8539
|
-
this.socket =
|
|
8538
|
+
constructor({ abort, socket, request, contentLength, client, expectsPayload, header }) {
|
|
8539
|
+
this.socket = socket;
|
|
8540
8540
|
this.request = request;
|
|
8541
8541
|
this.contentLength = contentLength;
|
|
8542
8542
|
this.client = client;
|
|
@@ -8544,18 +8544,18 @@ upgrade: ${upgrade}\r
|
|
|
8544
8544
|
this.expectsPayload = expectsPayload;
|
|
8545
8545
|
this.header = header;
|
|
8546
8546
|
this.abort = abort;
|
|
8547
|
-
|
|
8547
|
+
socket[kWriting] = true;
|
|
8548
8548
|
}
|
|
8549
8549
|
/**
|
|
8550
8550
|
* @param {Buffer} chunk
|
|
8551
8551
|
* @returns
|
|
8552
8552
|
*/
|
|
8553
8553
|
write(chunk) {
|
|
8554
|
-
const { socket
|
|
8555
|
-
if (
|
|
8556
|
-
throw
|
|
8554
|
+
const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this;
|
|
8555
|
+
if (socket[kError]) {
|
|
8556
|
+
throw socket[kError];
|
|
8557
8557
|
}
|
|
8558
|
-
if (
|
|
8558
|
+
if (socket.destroyed) {
|
|
8559
8559
|
return false;
|
|
8560
8560
|
}
|
|
8561
8561
|
const len = Buffer.byteLength(chunk);
|
|
@@ -8568,33 +8568,33 @@ upgrade: ${upgrade}\r
|
|
|
8568
8568
|
}
|
|
8569
8569
|
process.emitWarning(new RequestContentLengthMismatchError());
|
|
8570
8570
|
}
|
|
8571
|
-
|
|
8571
|
+
socket.cork();
|
|
8572
8572
|
if (bytesWritten === 0) {
|
|
8573
8573
|
if (!expectsPayload && request.reset !== false) {
|
|
8574
|
-
|
|
8574
|
+
socket[kReset] = true;
|
|
8575
8575
|
}
|
|
8576
8576
|
if (contentLength === null) {
|
|
8577
|
-
|
|
8577
|
+
socket.write(`${header}transfer-encoding: chunked\r
|
|
8578
8578
|
`, "latin1");
|
|
8579
8579
|
} else {
|
|
8580
|
-
|
|
8580
|
+
socket.write(`${header}content-length: ${contentLength}\r
|
|
8581
8581
|
\r
|
|
8582
8582
|
`, "latin1");
|
|
8583
8583
|
}
|
|
8584
8584
|
}
|
|
8585
8585
|
if (contentLength === null) {
|
|
8586
|
-
|
|
8586
|
+
socket.write(`\r
|
|
8587
8587
|
${len.toString(16)}\r
|
|
8588
8588
|
`, "latin1");
|
|
8589
8589
|
}
|
|
8590
8590
|
this.bytesWritten += len;
|
|
8591
|
-
const ret =
|
|
8592
|
-
|
|
8591
|
+
const ret = socket.write(chunk);
|
|
8592
|
+
socket.uncork();
|
|
8593
8593
|
request.onBodySent(chunk);
|
|
8594
8594
|
if (!ret) {
|
|
8595
|
-
if (
|
|
8596
|
-
if (
|
|
8597
|
-
|
|
8595
|
+
if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
|
|
8596
|
+
if (socket[kParser].timeout.refresh) {
|
|
8597
|
+
socket[kParser].timeout.refresh();
|
|
8598
8598
|
}
|
|
8599
8599
|
}
|
|
8600
8600
|
}
|
|
@@ -8604,26 +8604,26 @@ ${len.toString(16)}\r
|
|
|
8604
8604
|
* @returns {void}
|
|
8605
8605
|
*/
|
|
8606
8606
|
end() {
|
|
8607
|
-
const { socket
|
|
8607
|
+
const { socket, contentLength, client, bytesWritten, expectsPayload, header, request } = this;
|
|
8608
8608
|
request.onRequestSent();
|
|
8609
|
-
|
|
8610
|
-
if (
|
|
8611
|
-
throw
|
|
8609
|
+
socket[kWriting] = false;
|
|
8610
|
+
if (socket[kError]) {
|
|
8611
|
+
throw socket[kError];
|
|
8612
8612
|
}
|
|
8613
|
-
if (
|
|
8613
|
+
if (socket.destroyed) {
|
|
8614
8614
|
return;
|
|
8615
8615
|
}
|
|
8616
8616
|
if (bytesWritten === 0) {
|
|
8617
8617
|
if (expectsPayload) {
|
|
8618
|
-
|
|
8618
|
+
socket.write(`${header}content-length: 0\r
|
|
8619
8619
|
\r
|
|
8620
8620
|
`, "latin1");
|
|
8621
8621
|
} else {
|
|
8622
|
-
|
|
8622
|
+
socket.write(`${header}\r
|
|
8623
8623
|
`, "latin1");
|
|
8624
8624
|
}
|
|
8625
8625
|
} else if (contentLength === null) {
|
|
8626
|
-
|
|
8626
|
+
socket.write("\r\n0\r\n\r\n", "latin1");
|
|
8627
8627
|
}
|
|
8628
8628
|
if (contentLength !== null && bytesWritten !== contentLength) {
|
|
8629
8629
|
if (client[kStrictContentLength]) {
|
|
@@ -8632,9 +8632,9 @@ ${len.toString(16)}\r
|
|
|
8632
8632
|
process.emitWarning(new RequestContentLengthMismatchError());
|
|
8633
8633
|
}
|
|
8634
8634
|
}
|
|
8635
|
-
if (
|
|
8636
|
-
if (
|
|
8637
|
-
|
|
8635
|
+
if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
|
|
8636
|
+
if (socket[kParser].timeout.refresh) {
|
|
8637
|
+
socket[kParser].timeout.refresh();
|
|
8638
8638
|
}
|
|
8639
8639
|
}
|
|
8640
8640
|
client[kResume]();
|
|
@@ -8644,8 +8644,8 @@ ${len.toString(16)}\r
|
|
|
8644
8644
|
* @returns {void}
|
|
8645
8645
|
*/
|
|
8646
8646
|
destroy(err) {
|
|
8647
|
-
const { socket
|
|
8648
|
-
|
|
8647
|
+
const { socket, client, abort } = this;
|
|
8648
|
+
socket[kWriting] = false;
|
|
8649
8649
|
if (err) {
|
|
8650
8650
|
assert(client[kRunning] <= 1, "pipeline should only contain this request");
|
|
8651
8651
|
abort(err);
|
|
@@ -8737,12 +8737,12 @@ var require_client_h2 = __commonJS({
|
|
|
8737
8737
|
}
|
|
8738
8738
|
return result;
|
|
8739
8739
|
}
|
|
8740
|
-
function connectH2(client,
|
|
8741
|
-
client[kSocket] =
|
|
8740
|
+
function connectH2(client, socket) {
|
|
8741
|
+
client[kSocket] = socket;
|
|
8742
8742
|
const http2InitialWindowSize = client[kHTTP2InitialWindowSize];
|
|
8743
8743
|
const http2ConnectionWindowSize = client[kHTTP2ConnectionWindowSize];
|
|
8744
8744
|
const session = http2.connect(client[kUrl], {
|
|
8745
|
-
createConnection: () =>
|
|
8745
|
+
createConnection: () => socket,
|
|
8746
8746
|
peerMaxConcurrentStreams: client[kMaxConcurrentStreams],
|
|
8747
8747
|
settings: {
|
|
8748
8748
|
// TODO(metcoder95): add support for PUSH
|
|
@@ -8750,10 +8750,10 @@ var require_client_h2 = __commonJS({
|
|
|
8750
8750
|
...http2InitialWindowSize != null ? { initialWindowSize: http2InitialWindowSize } : null
|
|
8751
8751
|
}
|
|
8752
8752
|
});
|
|
8753
|
-
client[kSocket] =
|
|
8753
|
+
client[kSocket] = socket;
|
|
8754
8754
|
session[kOpenStreams] = 0;
|
|
8755
8755
|
session[kClient] = client;
|
|
8756
|
-
session[kSocket] =
|
|
8756
|
+
session[kSocket] = socket;
|
|
8757
8757
|
session[kHTTP2SessionState] = {
|
|
8758
8758
|
ping: {
|
|
8759
8759
|
interval: client[kPingInterval] === 0 ? null : setInterval(onHttp2SendPing, client[kPingInterval], session).unref()
|
|
@@ -8772,12 +8772,12 @@ var require_client_h2 = __commonJS({
|
|
|
8772
8772
|
util.addListener(session, "remoteSettings", onHttp2RemoteSettings);
|
|
8773
8773
|
session.unref();
|
|
8774
8774
|
client[kHTTP2Session] = session;
|
|
8775
|
-
|
|
8776
|
-
util.addListener(
|
|
8777
|
-
util.addListener(
|
|
8778
|
-
util.addListener(
|
|
8779
|
-
|
|
8780
|
-
|
|
8775
|
+
socket[kHTTP2Session] = session;
|
|
8776
|
+
util.addListener(socket, "error", onHttp2SocketError);
|
|
8777
|
+
util.addListener(socket, "end", onHttp2SocketEnd);
|
|
8778
|
+
util.addListener(socket, "close", onHttp2SocketClose);
|
|
8779
|
+
socket[kClosed] = false;
|
|
8780
|
+
socket.on("close", onSocketClose);
|
|
8781
8781
|
return {
|
|
8782
8782
|
version: "h2",
|
|
8783
8783
|
defaultPipelining: Infinity,
|
|
@@ -8799,17 +8799,17 @@ var require_client_h2 = __commonJS({
|
|
|
8799
8799
|
* @param {() => void} callback
|
|
8800
8800
|
*/
|
|
8801
8801
|
destroy(err, callback) {
|
|
8802
|
-
if (
|
|
8802
|
+
if (socket[kClosed]) {
|
|
8803
8803
|
queueMicrotask(callback);
|
|
8804
8804
|
} else {
|
|
8805
|
-
|
|
8805
|
+
socket.destroy(err).on("close", callback);
|
|
8806
8806
|
}
|
|
8807
8807
|
},
|
|
8808
8808
|
/**
|
|
8809
8809
|
* @type {boolean}
|
|
8810
8810
|
*/
|
|
8811
8811
|
get destroyed() {
|
|
8812
|
-
return
|
|
8812
|
+
return socket.destroyed;
|
|
8813
8813
|
},
|
|
8814
8814
|
/**
|
|
8815
8815
|
* @param {import('../core/request.js')} request
|
|
@@ -8830,13 +8830,13 @@ var require_client_h2 = __commonJS({
|
|
|
8830
8830
|
};
|
|
8831
8831
|
}
|
|
8832
8832
|
function resumeH2(client) {
|
|
8833
|
-
const
|
|
8834
|
-
if (
|
|
8833
|
+
const socket = client[kSocket];
|
|
8834
|
+
if (socket?.destroyed === false) {
|
|
8835
8835
|
if (client[kSize] === 0) {
|
|
8836
|
-
|
|
8836
|
+
socket.unref();
|
|
8837
8837
|
client[kHTTP2Session].unref();
|
|
8838
8838
|
} else {
|
|
8839
|
-
|
|
8839
|
+
socket.ref();
|
|
8840
8840
|
client[kHTTP2Session].ref();
|
|
8841
8841
|
}
|
|
8842
8842
|
}
|
|
@@ -8871,10 +8871,10 @@ var require_client_h2 = __commonJS({
|
|
|
8871
8871
|
session.ping(onPing.bind(session));
|
|
8872
8872
|
function onPing(err, duration) {
|
|
8873
8873
|
const client = this[kClient];
|
|
8874
|
-
const
|
|
8874
|
+
const socket = this[kClient];
|
|
8875
8875
|
if (err != null) {
|
|
8876
8876
|
const error = new InformationalError(`HTTP/2: "PING" errored - type ${err.message}`);
|
|
8877
|
-
|
|
8877
|
+
socket[kError] = error;
|
|
8878
8878
|
client[kOnError](error);
|
|
8879
8879
|
} else {
|
|
8880
8880
|
client.emit("ping", duration);
|
|
@@ -8938,8 +8938,8 @@ var require_client_h2 = __commonJS({
|
|
|
8938
8938
|
}
|
|
8939
8939
|
function onHttp2SessionClose() {
|
|
8940
8940
|
const { [kClient]: client, [kHTTP2SessionState]: state } = this;
|
|
8941
|
-
const { [kSocket]:
|
|
8942
|
-
const err = this[kSocket][kError] || this[kError] || new SocketError("closed", util.getSocketInfo(
|
|
8941
|
+
const { [kSocket]: socket } = client;
|
|
8942
|
+
const err = this[kSocket][kError] || this[kError] || new SocketError("closed", util.getSocketInfo(socket));
|
|
8943
8943
|
client[kSocket] = null;
|
|
8944
8944
|
client[kHTTPContext] = null;
|
|
8945
8945
|
if (state.ping.interval != null) {
|
|
@@ -9312,7 +9312,7 @@ var require_client_h2 = __commonJS({
|
|
|
9312
9312
|
}
|
|
9313
9313
|
}
|
|
9314
9314
|
}
|
|
9315
|
-
function writeBuffer(abort, h2stream, body, client, request,
|
|
9315
|
+
function writeBuffer(abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
|
|
9316
9316
|
try {
|
|
9317
9317
|
if (body != null && util.isBuffer(body)) {
|
|
9318
9318
|
assert(contentLength === body.byteLength, "buffer body must have content length");
|
|
@@ -9323,7 +9323,7 @@ var require_client_h2 = __commonJS({
|
|
|
9323
9323
|
request.onBodySent(body);
|
|
9324
9324
|
}
|
|
9325
9325
|
if (!expectsPayload) {
|
|
9326
|
-
|
|
9326
|
+
socket[kReset] = true;
|
|
9327
9327
|
}
|
|
9328
9328
|
request.onRequestSent();
|
|
9329
9329
|
client[kResume]();
|
|
@@ -9331,7 +9331,7 @@ var require_client_h2 = __commonJS({
|
|
|
9331
9331
|
abort(error);
|
|
9332
9332
|
}
|
|
9333
9333
|
}
|
|
9334
|
-
function writeStream(abort,
|
|
9334
|
+
function writeStream(abort, socket, expectsPayload, h2stream, body, client, request, contentLength) {
|
|
9335
9335
|
assert(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
|
|
9336
9336
|
const pipe = pipeline(
|
|
9337
9337
|
body,
|
|
@@ -9344,7 +9344,7 @@ var require_client_h2 = __commonJS({
|
|
|
9344
9344
|
util.removeAllListeners(pipe);
|
|
9345
9345
|
request.onRequestSent();
|
|
9346
9346
|
if (!expectsPayload) {
|
|
9347
|
-
|
|
9347
|
+
socket[kReset] = true;
|
|
9348
9348
|
}
|
|
9349
9349
|
client[kResume]();
|
|
9350
9350
|
}
|
|
@@ -9355,7 +9355,7 @@ var require_client_h2 = __commonJS({
|
|
|
9355
9355
|
request.onBodySent(chunk);
|
|
9356
9356
|
}
|
|
9357
9357
|
}
|
|
9358
|
-
async function writeBlob(abort, h2stream, body, client, request,
|
|
9358
|
+
async function writeBlob(abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
|
|
9359
9359
|
assert(contentLength === body.size, "blob body must have content length");
|
|
9360
9360
|
try {
|
|
9361
9361
|
if (contentLength != null && contentLength !== body.size) {
|
|
@@ -9369,14 +9369,14 @@ var require_client_h2 = __commonJS({
|
|
|
9369
9369
|
request.onBodySent(buffer);
|
|
9370
9370
|
request.onRequestSent();
|
|
9371
9371
|
if (!expectsPayload) {
|
|
9372
|
-
|
|
9372
|
+
socket[kReset] = true;
|
|
9373
9373
|
}
|
|
9374
9374
|
client[kResume]();
|
|
9375
9375
|
} catch (err) {
|
|
9376
9376
|
abort(err);
|
|
9377
9377
|
}
|
|
9378
9378
|
}
|
|
9379
|
-
async function writeIterable(abort, h2stream, body, client, request,
|
|
9379
|
+
async function writeIterable(abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
|
|
9380
9380
|
assert(contentLength !== 0 || client[kRunning] === 0, "iterator body cannot be pipelined");
|
|
9381
9381
|
let callback = null;
|
|
9382
9382
|
function onDrain() {
|
|
@@ -9388,8 +9388,8 @@ var require_client_h2 = __commonJS({
|
|
|
9388
9388
|
}
|
|
9389
9389
|
const waitForDrain = () => new Promise((resolve, reject) => {
|
|
9390
9390
|
assert(callback === null);
|
|
9391
|
-
if (
|
|
9392
|
-
reject(
|
|
9391
|
+
if (socket[kError]) {
|
|
9392
|
+
reject(socket[kError]);
|
|
9393
9393
|
} else {
|
|
9394
9394
|
callback = resolve;
|
|
9395
9395
|
}
|
|
@@ -9397,8 +9397,8 @@ var require_client_h2 = __commonJS({
|
|
|
9397
9397
|
h2stream.on("close", onDrain).on("drain", onDrain);
|
|
9398
9398
|
try {
|
|
9399
9399
|
for await (const chunk of body) {
|
|
9400
|
-
if (
|
|
9401
|
-
throw
|
|
9400
|
+
if (socket[kError]) {
|
|
9401
|
+
throw socket[kError];
|
|
9402
9402
|
}
|
|
9403
9403
|
const res = h2stream.write(chunk);
|
|
9404
9404
|
request.onBodySent(chunk);
|
|
@@ -9409,7 +9409,7 @@ var require_client_h2 = __commonJS({
|
|
|
9409
9409
|
h2stream.end();
|
|
9410
9410
|
request.onRequestSent();
|
|
9411
9411
|
if (!expectsPayload) {
|
|
9412
|
-
|
|
9412
|
+
socket[kReset] = true;
|
|
9413
9413
|
}
|
|
9414
9414
|
client[kResume]();
|
|
9415
9415
|
} catch (err) {
|
|
@@ -9427,7 +9427,7 @@ var require_client = __commonJS({
|
|
|
9427
9427
|
"node_modules/undici/lib/dispatcher/client.js"(exports, module) {
|
|
9428
9428
|
"use strict";
|
|
9429
9429
|
var assert = __require("node:assert");
|
|
9430
|
-
var
|
|
9430
|
+
var net2 = __require("node:net");
|
|
9431
9431
|
var http = __require("node:http");
|
|
9432
9432
|
var util = require_util();
|
|
9433
9433
|
var { ClientStats } = require_stats();
|
|
@@ -9583,7 +9583,7 @@ var require_client = __commonJS({
|
|
|
9583
9583
|
if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
|
|
9584
9584
|
throw new InvalidArgumentError("maxRequestsPerClient must be a positive number");
|
|
9585
9585
|
}
|
|
9586
|
-
if (localAddress != null && (typeof localAddress !== "string" ||
|
|
9586
|
+
if (localAddress != null && (typeof localAddress !== "string" || net2.isIP(localAddress) === 0)) {
|
|
9587
9587
|
throw new InvalidArgumentError("localAddress must be valid string IP address");
|
|
9588
9588
|
}
|
|
9589
9589
|
if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
|
|
@@ -9763,7 +9763,7 @@ var require_client = __commonJS({
|
|
|
9763
9763
|
const idx = hostname.indexOf("]");
|
|
9764
9764
|
assert(idx !== -1);
|
|
9765
9765
|
const ip = hostname.substring(1, idx);
|
|
9766
|
-
assert(
|
|
9766
|
+
assert(net2.isIPv6(ip));
|
|
9767
9767
|
hostname = ip;
|
|
9768
9768
|
}
|
|
9769
9769
|
client[kConnecting] = true;
|
|
@@ -9789,31 +9789,31 @@ var require_client = __commonJS({
|
|
|
9789
9789
|
port,
|
|
9790
9790
|
servername: client[kServerName],
|
|
9791
9791
|
localAddress: client[kLocalAddress]
|
|
9792
|
-
}, (err,
|
|
9792
|
+
}, (err, socket) => {
|
|
9793
9793
|
if (err) {
|
|
9794
9794
|
handleConnectError(client, err, { host, hostname, protocol, port });
|
|
9795
9795
|
client[kResume]();
|
|
9796
9796
|
return;
|
|
9797
9797
|
}
|
|
9798
9798
|
if (client.destroyed) {
|
|
9799
|
-
util.destroy(
|
|
9799
|
+
util.destroy(socket.on("error", noop), new ClientDestroyedError());
|
|
9800
9800
|
client[kResume]();
|
|
9801
9801
|
return;
|
|
9802
9802
|
}
|
|
9803
|
-
assert(
|
|
9803
|
+
assert(socket);
|
|
9804
9804
|
try {
|
|
9805
|
-
client[kHTTPContext] =
|
|
9805
|
+
client[kHTTPContext] = socket.alpnProtocol === "h2" ? connectH2(client, socket) : connectH1(client, socket);
|
|
9806
9806
|
} catch (err2) {
|
|
9807
|
-
|
|
9807
|
+
socket.destroy().on("error", noop);
|
|
9808
9808
|
handleConnectError(client, err2, { host, hostname, protocol, port });
|
|
9809
9809
|
client[kResume]();
|
|
9810
9810
|
return;
|
|
9811
9811
|
}
|
|
9812
9812
|
client[kConnecting] = false;
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9813
|
+
socket[kCounter] = 0;
|
|
9814
|
+
socket[kMaxRequests] = client[kMaxRequests];
|
|
9815
|
+
socket[kClient] = client;
|
|
9816
|
+
socket[kError] = null;
|
|
9817
9817
|
if (channels.connected.hasSubscribers) {
|
|
9818
9818
|
channels.connected.publish({
|
|
9819
9819
|
connectParams: {
|
|
@@ -9826,7 +9826,7 @@ var require_client = __commonJS({
|
|
|
9826
9826
|
localAddress: client[kLocalAddress]
|
|
9827
9827
|
},
|
|
9828
9828
|
connector: client[kConnector],
|
|
9829
|
-
socket
|
|
9829
|
+
socket
|
|
9830
9830
|
});
|
|
9831
9831
|
}
|
|
9832
9832
|
client.emit("connect", client[kUrl], [client]);
|
|
@@ -10590,7 +10590,7 @@ var require_agent = __commonJS({
|
|
|
10590
10590
|
function defaultFactory(origin, opts) {
|
|
10591
10591
|
return opts && opts.connections === 1 ? new Client(origin, opts) : new Pool(origin, opts);
|
|
10592
10592
|
}
|
|
10593
|
-
var
|
|
10593
|
+
var Agent2 = class extends DispatcherBase {
|
|
10594
10594
|
constructor({ factory = defaultFactory, maxOrigins = Infinity, connect: connect2, tls, ...options } = {}) {
|
|
10595
10595
|
if (typeof factory !== "function") {
|
|
10596
10596
|
throw new InvalidArgumentError("factory must be a function.");
|
|
@@ -10702,7 +10702,7 @@ var require_agent = __commonJS({
|
|
|
10702
10702
|
return allClientStats;
|
|
10703
10703
|
}
|
|
10704
10704
|
};
|
|
10705
|
-
module.exports =
|
|
10705
|
+
module.exports = Agent2;
|
|
10706
10706
|
}
|
|
10707
10707
|
});
|
|
10708
10708
|
|
|
@@ -10711,10 +10711,10 @@ var require_socks5_utils = __commonJS({
|
|
|
10711
10711
|
"node_modules/undici/lib/core/socks5-utils.js"(exports, module) {
|
|
10712
10712
|
"use strict";
|
|
10713
10713
|
var { Buffer: Buffer2 } = __require("node:buffer");
|
|
10714
|
-
var
|
|
10714
|
+
var net2 = __require("node:net");
|
|
10715
10715
|
var { InvalidArgumentError } = require_errors();
|
|
10716
10716
|
function parseAddress(address) {
|
|
10717
|
-
if (
|
|
10717
|
+
if (net2.isIPv4(address)) {
|
|
10718
10718
|
const parts = address.split(".").map(Number);
|
|
10719
10719
|
return {
|
|
10720
10720
|
type: 1,
|
|
@@ -10722,7 +10722,7 @@ var require_socks5_utils = __commonJS({
|
|
|
10722
10722
|
buffer: Buffer2.from(parts)
|
|
10723
10723
|
};
|
|
10724
10724
|
}
|
|
10725
|
-
if (
|
|
10725
|
+
if (net2.isIPv6(address)) {
|
|
10726
10726
|
return {
|
|
10727
10727
|
type: 4,
|
|
10728
10728
|
// IPv6
|
|
@@ -10745,7 +10745,7 @@ var require_socks5_utils = __commonJS({
|
|
|
10745
10745
|
if (address.includes(".")) {
|
|
10746
10746
|
const lastColonIndex = address.lastIndexOf(":");
|
|
10747
10747
|
const ipv4Part = address.slice(lastColonIndex + 1);
|
|
10748
|
-
if (
|
|
10748
|
+
if (net2.isIPv4(ipv4Part)) {
|
|
10749
10749
|
const octets = ipv4Part.split(".").map(Number);
|
|
10750
10750
|
const high = (octets[0] << 8 | octets[1]).toString(16);
|
|
10751
10751
|
const low = (octets[2] << 8 | octets[3]).toString(16);
|
|
@@ -10917,12 +10917,12 @@ var require_socks5_client = __commonJS({
|
|
|
10917
10917
|
CLOSED: "closed"
|
|
10918
10918
|
};
|
|
10919
10919
|
var Socks5Client = class extends EventEmitter {
|
|
10920
|
-
constructor(
|
|
10920
|
+
constructor(socket, options = {}) {
|
|
10921
10921
|
super();
|
|
10922
|
-
if (!
|
|
10922
|
+
if (!socket) {
|
|
10923
10923
|
throw new InvalidArgumentError("socket is required");
|
|
10924
10924
|
}
|
|
10925
|
-
this.socket =
|
|
10925
|
+
this.socket = socket;
|
|
10926
10926
|
this.options = options;
|
|
10927
10927
|
this.state = STATES.INITIAL;
|
|
10928
10928
|
this.buffer = EMPTY_BUFFER;
|
|
@@ -11260,24 +11260,24 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
11260
11260
|
const proxyHost = this[kProxyUrl].hostname;
|
|
11261
11261
|
const proxyPort = parseInt(this[kProxyUrl].port) || 1080;
|
|
11262
11262
|
debug("creating SOCKS5 connection to", proxyHost, proxyPort);
|
|
11263
|
-
const
|
|
11263
|
+
const socket = await new Promise((resolve, reject) => {
|
|
11264
11264
|
this[kConnector]({
|
|
11265
11265
|
hostname: proxyHost,
|
|
11266
11266
|
host: proxyHost,
|
|
11267
11267
|
port: proxyPort,
|
|
11268
11268
|
protocol: this[kProxyProtocol]
|
|
11269
|
-
}, (err,
|
|
11269
|
+
}, (err, socket2) => {
|
|
11270
11270
|
if (err) {
|
|
11271
11271
|
reject(err);
|
|
11272
11272
|
} else {
|
|
11273
|
-
resolve(
|
|
11273
|
+
resolve(socket2);
|
|
11274
11274
|
}
|
|
11275
11275
|
});
|
|
11276
11276
|
});
|
|
11277
|
-
const socks5Client = new Socks5Client(
|
|
11277
|
+
const socks5Client = new Socks5Client(socket, this[kProxyAuth]);
|
|
11278
11278
|
socks5Client.on("error", (err) => {
|
|
11279
11279
|
debug("SOCKS5 error:", err);
|
|
11280
|
-
|
|
11280
|
+
socket.destroy();
|
|
11281
11281
|
});
|
|
11282
11282
|
await socks5Client.handshake();
|
|
11283
11283
|
await new Promise((resolve, reject) => {
|
|
@@ -11321,7 +11321,7 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
11321
11321
|
socks5Client.once("connected", onConnected);
|
|
11322
11322
|
socks5Client.once("error", onError);
|
|
11323
11323
|
});
|
|
11324
|
-
return
|
|
11324
|
+
return socket;
|
|
11325
11325
|
}
|
|
11326
11326
|
/**
|
|
11327
11327
|
* Dispatch a request through the SOCKS5 proxy
|
|
@@ -11342,8 +11342,8 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
11342
11342
|
const targetHost = url.hostname;
|
|
11343
11343
|
const targetPort = parseInt(url.port) || (url.protocol === "https:" ? 443 : 80);
|
|
11344
11344
|
debug("establishing SOCKS5 connection to", targetHost, targetPort);
|
|
11345
|
-
const
|
|
11346
|
-
let finalSocket =
|
|
11345
|
+
const socket = await this.createSocks5Connection(targetHost, targetPort);
|
|
11346
|
+
let finalSocket = socket;
|
|
11347
11347
|
if (url.protocol === "https:") {
|
|
11348
11348
|
if (!tls) {
|
|
11349
11349
|
tls = __require("node:tls");
|
|
@@ -11351,7 +11351,7 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
11351
11351
|
debug("upgrading to TLS");
|
|
11352
11352
|
finalSocket = tls.connect({
|
|
11353
11353
|
...this[kRequestTls],
|
|
11354
|
-
socket
|
|
11354
|
+
socket,
|
|
11355
11355
|
servername: this[kRequestTls]?.servername || targetHost
|
|
11356
11356
|
});
|
|
11357
11357
|
await new Promise((resolve, reject) => {
|
|
@@ -11408,7 +11408,7 @@ var require_proxy_agent = __commonJS({
|
|
|
11408
11408
|
"node_modules/undici/lib/dispatcher/proxy-agent.js"(exports, module) {
|
|
11409
11409
|
"use strict";
|
|
11410
11410
|
var { kProxy, kClose, kDestroy, kDispatch } = require_symbols();
|
|
11411
|
-
var
|
|
11411
|
+
var Agent2 = require_agent();
|
|
11412
11412
|
var Pool = require_pool();
|
|
11413
11413
|
var DispatcherBase = require_dispatcher_base();
|
|
11414
11414
|
var { InvalidArgumentError, RequestAbortedError, SecureProxyConnectionError } = require_errors();
|
|
@@ -11539,7 +11539,7 @@ var require_proxy_agent = __commonJS({
|
|
|
11539
11539
|
} else {
|
|
11540
11540
|
this[kClient] = clientFactory(url, { connect: connect2 });
|
|
11541
11541
|
}
|
|
11542
|
-
this[kAgent] = new
|
|
11542
|
+
this[kAgent] = new Agent2({
|
|
11543
11543
|
...opts,
|
|
11544
11544
|
factory,
|
|
11545
11545
|
connect: async (opts2, callback) => {
|
|
@@ -11564,20 +11564,20 @@ var require_proxy_agent = __commonJS({
|
|
|
11564
11564
|
},
|
|
11565
11565
|
servername: this[kProxyTls]?.servername || proxyHostname
|
|
11566
11566
|
};
|
|
11567
|
-
const { socket
|
|
11567
|
+
const { socket, statusCode } = await this[kClient].connect(connectParams);
|
|
11568
11568
|
if (statusCode !== 200) {
|
|
11569
|
-
|
|
11569
|
+
socket.on("error", noop).destroy();
|
|
11570
11570
|
callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`));
|
|
11571
11571
|
return;
|
|
11572
11572
|
}
|
|
11573
11573
|
if (channels.proxyConnected.hasSubscribers) {
|
|
11574
11574
|
channels.proxyConnected.publish({
|
|
11575
|
-
socket
|
|
11575
|
+
socket,
|
|
11576
11576
|
connectParams
|
|
11577
11577
|
});
|
|
11578
11578
|
}
|
|
11579
11579
|
if (opts2.protocol !== "https:") {
|
|
11580
|
-
callback(null,
|
|
11580
|
+
callback(null, socket);
|
|
11581
11581
|
return;
|
|
11582
11582
|
}
|
|
11583
11583
|
let servername;
|
|
@@ -11586,7 +11586,7 @@ var require_proxy_agent = __commonJS({
|
|
|
11586
11586
|
} else {
|
|
11587
11587
|
servername = opts2.servername;
|
|
11588
11588
|
}
|
|
11589
|
-
this[kConnectEndpoint]({ ...opts2, servername, httpSocket:
|
|
11589
|
+
this[kConnectEndpoint]({ ...opts2, servername, httpSocket: socket }, callback);
|
|
11590
11590
|
} catch (err) {
|
|
11591
11591
|
if (err.code === "ERR_TLS_CERT_ALTNAME_INVALID") {
|
|
11592
11592
|
callback(new SecureProxyConnectionError(err));
|
|
@@ -11667,7 +11667,7 @@ var require_env_http_proxy_agent = __commonJS({
|
|
|
11667
11667
|
var DispatcherBase = require_dispatcher_base();
|
|
11668
11668
|
var { kClose, kDestroy, kClosed, kDestroyed, kDispatch, kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent } = require_symbols();
|
|
11669
11669
|
var ProxyAgent = require_proxy_agent();
|
|
11670
|
-
var
|
|
11670
|
+
var Agent2 = require_agent();
|
|
11671
11671
|
var DEFAULT_PORTS = {
|
|
11672
11672
|
"http:": 80,
|
|
11673
11673
|
"https:": 443
|
|
@@ -11680,7 +11680,7 @@ var require_env_http_proxy_agent = __commonJS({
|
|
|
11680
11680
|
super();
|
|
11681
11681
|
this.#opts = opts;
|
|
11682
11682
|
const { httpProxy, httpsProxy, noProxy, ...agentOpts } = opts;
|
|
11683
|
-
this[kNoProxyAgent] = new
|
|
11683
|
+
this[kNoProxyAgent] = new Agent2(agentOpts);
|
|
11684
11684
|
const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY;
|
|
11685
11685
|
if (HTTP_PROXY) {
|
|
11686
11686
|
this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY });
|
|
@@ -11985,8 +11985,8 @@ var require_retry_handler = __commonJS({
|
|
|
11985
11985
|
this.handler.onRequestStart?.(this.controllerProxy, context);
|
|
11986
11986
|
}
|
|
11987
11987
|
}
|
|
11988
|
-
onRequestUpgrade(_controller, statusCode, headers,
|
|
11989
|
-
this.handler.onRequestUpgrade?.(this.controllerProxy, statusCode, headers,
|
|
11988
|
+
onRequestUpgrade(_controller, statusCode, headers, socket) {
|
|
11989
|
+
this.handler.onRequestUpgrade?.(this.controllerProxy, statusCode, headers, socket);
|
|
11990
11990
|
}
|
|
11991
11991
|
static [kRetryHandlerDefaultRetry](err, { state, opts }, cb) {
|
|
11992
11992
|
const { statusCode, code, headers } = err;
|
|
@@ -13066,7 +13066,7 @@ var require_api_pipeline = __commonJS({
|
|
|
13066
13066
|
var {
|
|
13067
13067
|
Readable,
|
|
13068
13068
|
Duplex,
|
|
13069
|
-
PassThrough
|
|
13069
|
+
PassThrough: PassThrough2
|
|
13070
13070
|
} = __require("node:stream");
|
|
13071
13071
|
var assert = __require("node:assert");
|
|
13072
13072
|
var { AsyncResource } = __require("node:async_hooks");
|
|
@@ -13253,7 +13253,7 @@ var require_api_pipeline = __commonJS({
|
|
|
13253
13253
|
this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler);
|
|
13254
13254
|
return pipelineHandler.ret;
|
|
13255
13255
|
} catch (err) {
|
|
13256
|
-
return new
|
|
13256
|
+
return new PassThrough2().destroy(err);
|
|
13257
13257
|
}
|
|
13258
13258
|
}
|
|
13259
13259
|
module.exports = pipeline;
|
|
@@ -13302,15 +13302,15 @@ var require_api_upgrade = __commonJS({
|
|
|
13302
13302
|
onHeaders() {
|
|
13303
13303
|
throw new SocketError("bad upgrade", null);
|
|
13304
13304
|
}
|
|
13305
|
-
onUpgrade(statusCode, rawHeaders,
|
|
13306
|
-
assert(
|
|
13305
|
+
onUpgrade(statusCode, rawHeaders, socket) {
|
|
13306
|
+
assert(socket[kHTTP2Stream] === true ? statusCode === 200 : statusCode === 101);
|
|
13307
13307
|
const { callback, opaque, context } = this;
|
|
13308
13308
|
removeSignal(this);
|
|
13309
13309
|
this.callback = null;
|
|
13310
13310
|
const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders);
|
|
13311
13311
|
this.runInAsyncScope(callback, null, null, {
|
|
13312
13312
|
headers,
|
|
13313
|
-
socket
|
|
13313
|
+
socket,
|
|
13314
13314
|
opaque,
|
|
13315
13315
|
context
|
|
13316
13316
|
});
|
|
@@ -13394,7 +13394,7 @@ var require_api_connect = __commonJS({
|
|
|
13394
13394
|
onHeaders() {
|
|
13395
13395
|
throw new SocketError("bad connect", null);
|
|
13396
13396
|
}
|
|
13397
|
-
onUpgrade(statusCode, rawHeaders,
|
|
13397
|
+
onUpgrade(statusCode, rawHeaders, socket) {
|
|
13398
13398
|
const { callback, opaque, context } = this;
|
|
13399
13399
|
removeSignal(this);
|
|
13400
13400
|
this.callback = null;
|
|
@@ -13405,7 +13405,7 @@ var require_api_connect = __commonJS({
|
|
|
13405
13405
|
this.runInAsyncScope(callback, null, null, {
|
|
13406
13406
|
statusCode,
|
|
13407
13407
|
headers,
|
|
13408
|
-
socket
|
|
13408
|
+
socket,
|
|
13409
13409
|
opaque,
|
|
13410
13410
|
context
|
|
13411
13411
|
});
|
|
@@ -13758,7 +13758,7 @@ var require_mock_utils = __commonJS({
|
|
|
13758
13758
|
if (mockDispatch2.data.callback) {
|
|
13759
13759
|
mockDispatch2.data = { ...mockDispatch2.data, ...mockDispatch2.data.callback(opts) };
|
|
13760
13760
|
}
|
|
13761
|
-
const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch2;
|
|
13761
|
+
const { data: { statusCode, data, headers, trailers, error }, delay: delay2, persist } = mockDispatch2;
|
|
13762
13762
|
const { timesInvoked, times } = mockDispatch2;
|
|
13763
13763
|
mockDispatch2.consumed = !persist && timesInvoked >= times;
|
|
13764
13764
|
mockDispatch2.pending = timesInvoked < times;
|
|
@@ -13781,11 +13781,11 @@ var require_mock_utils = __commonJS({
|
|
|
13781
13781
|
handler.onError(err);
|
|
13782
13782
|
}
|
|
13783
13783
|
handler.onConnect?.(abort, null);
|
|
13784
|
-
if (typeof
|
|
13784
|
+
if (typeof delay2 === "number" && delay2 > 0) {
|
|
13785
13785
|
timer = setTimeout(() => {
|
|
13786
13786
|
timer = null;
|
|
13787
13787
|
handleReply(this[kDispatches]);
|
|
13788
|
-
},
|
|
13788
|
+
}, delay2);
|
|
13789
13789
|
} else {
|
|
13790
13790
|
handleReply(this[kDispatches]);
|
|
13791
13791
|
}
|
|
@@ -14429,7 +14429,7 @@ var require_mock_agent = __commonJS({
|
|
|
14429
14429
|
"node_modules/undici/lib/mock/mock-agent.js"(exports, module) {
|
|
14430
14430
|
"use strict";
|
|
14431
14431
|
var { kClients } = require_symbols();
|
|
14432
|
-
var
|
|
14432
|
+
var Agent2 = require_agent();
|
|
14433
14433
|
var {
|
|
14434
14434
|
kAgent,
|
|
14435
14435
|
kMockAgentSet,
|
|
@@ -14467,7 +14467,7 @@ var require_mock_agent = __commonJS({
|
|
|
14467
14467
|
if (opts?.agent && typeof opts.agent.dispatch !== "function") {
|
|
14468
14468
|
throw new InvalidArgumentError("Argument opts.agent must implement Agent");
|
|
14469
14469
|
}
|
|
14470
|
-
const agent = opts?.agent ? opts.agent : new
|
|
14470
|
+
const agent = opts?.agent ? opts.agent : new Agent2(opts);
|
|
14471
14471
|
this[kAgent] = agent;
|
|
14472
14472
|
this[kClients] = agent[kClients];
|
|
14473
14473
|
this[kOptions] = mockOptions;
|
|
@@ -14622,8 +14622,8 @@ var require_snapshot_utils = __commonJS({
|
|
|
14622
14622
|
match: new Set(matchHeaders.map((header) => caseSensitive ? header : header.toLowerCase()))
|
|
14623
14623
|
};
|
|
14624
14624
|
}
|
|
14625
|
-
var
|
|
14626
|
-
var hashId =
|
|
14625
|
+
var crypto3 = runtimeFeatures.has("crypto") ? __require("node:crypto") : null;
|
|
14626
|
+
var hashId = crypto3?.hash ? (value) => crypto3.hash("sha256", value, "base64url") : (value) => Buffer.from(value).toString("base64url");
|
|
14627
14627
|
function isUndiciHeaders(headers) {
|
|
14628
14628
|
return Array.isArray(headers) && (headers.length & 1) === 0;
|
|
14629
14629
|
}
|
|
@@ -15074,7 +15074,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
15074
15074
|
var require_snapshot_agent = __commonJS({
|
|
15075
15075
|
"node_modules/undici/lib/mock/snapshot-agent.js"(exports, module) {
|
|
15076
15076
|
"use strict";
|
|
15077
|
-
var
|
|
15077
|
+
var Agent2 = require_agent();
|
|
15078
15078
|
var MockAgent = require_mock_agent();
|
|
15079
15079
|
var { SnapshotRecorder } = require_snapshot_recorder();
|
|
15080
15080
|
var WrapHandler = require_wrap_handler();
|
|
@@ -15125,7 +15125,7 @@ var require_snapshot_agent = __commonJS({
|
|
|
15125
15125
|
});
|
|
15126
15126
|
this[kSnapshotLoaded] = false;
|
|
15127
15127
|
if (this[kSnapshotMode] === "record" || this[kSnapshotMode] === "update" || this[kSnapshotMode] === "playback" && opts.excludeUrls && opts.excludeUrls.length > 0) {
|
|
15128
|
-
this[kRealAgent] = new
|
|
15128
|
+
this[kRealAgent] = new Agent2(opts);
|
|
15129
15129
|
}
|
|
15130
15130
|
if ((this[kSnapshotMode] === "playback" || this[kSnapshotMode] === "update") && this[kSnapshotPath]) {
|
|
15131
15131
|
this.loadSnapshots().catch(() => {
|
|
@@ -15181,8 +15181,8 @@ var require_snapshot_agent = __commonJS({
|
|
|
15181
15181
|
onRequestStart(controller, context) {
|
|
15182
15182
|
return handler.onRequestStart(controller, { ...context, history: this.history });
|
|
15183
15183
|
},
|
|
15184
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
15185
|
-
return handler.onRequestUpgrade(controller, statusCode, headers,
|
|
15184
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
15185
|
+
return handler.onRequestUpgrade(controller, statusCode, headers, socket);
|
|
15186
15186
|
},
|
|
15187
15187
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
15188
15188
|
responseData.statusCode = statusCode;
|
|
@@ -15364,9 +15364,9 @@ var require_global2 = __commonJS({
|
|
|
15364
15364
|
var globalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.2");
|
|
15365
15365
|
var legacyGlobalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
|
|
15366
15366
|
var { InvalidArgumentError } = require_errors();
|
|
15367
|
-
var
|
|
15367
|
+
var Agent2 = require_agent();
|
|
15368
15368
|
if (getGlobalDispatcher() === void 0) {
|
|
15369
|
-
setGlobalDispatcher2(new
|
|
15369
|
+
setGlobalDispatcher2(new Agent2());
|
|
15370
15370
|
}
|
|
15371
15371
|
function setGlobalDispatcher2(agent) {
|
|
15372
15372
|
if (!agent || typeof agent.dispatch !== "function") {
|
|
@@ -15535,8 +15535,8 @@ var require_redirect_handler = __commonJS({
|
|
|
15535
15535
|
onRequestStart(controller, context) {
|
|
15536
15536
|
this.handler.onRequestStart?.(controller, { ...context, history: this.history });
|
|
15537
15537
|
}
|
|
15538
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
15539
|
-
this.handler.onRequestUpgrade?.(controller, statusCode, headers,
|
|
15538
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
15539
|
+
this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket);
|
|
15540
15540
|
}
|
|
15541
15541
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
15542
15542
|
if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) {
|
|
@@ -17490,8 +17490,8 @@ var require_cache_handler = __commonJS({
|
|
|
17490
17490
|
this.#history = context?.history;
|
|
17491
17491
|
this.#handler.onRequestStart?.(controller, context);
|
|
17492
17492
|
}
|
|
17493
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
17494
|
-
this.#handler.onRequestUpgrade?.(controller, statusCode, headers,
|
|
17493
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
17494
|
+
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket);
|
|
17495
17495
|
}
|
|
17496
17496
|
/**
|
|
17497
17497
|
* @param {import('../../types/dispatcher.d.ts').default.DispatchController} controller
|
|
@@ -18056,7 +18056,7 @@ var require_cache_handler = __commonJS({
|
|
|
18056
18056
|
var require_memory_cache_store = __commonJS({
|
|
18057
18057
|
"node_modules/undici/lib/cache/memory-cache-store.js"(exports, module) {
|
|
18058
18058
|
"use strict";
|
|
18059
|
-
var { Writable } = __require("node:stream");
|
|
18059
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
18060
18060
|
var { EventEmitter } = __require("node:events");
|
|
18061
18061
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
18062
18062
|
var MemoryCacheStore = class extends EventEmitter {
|
|
@@ -18146,7 +18146,7 @@ var require_memory_cache_store = __commonJS({
|
|
|
18146
18146
|
const topLevelKey = `${key.origin}:${key.path}`;
|
|
18147
18147
|
const store = this;
|
|
18148
18148
|
const entry = { ...key, ...val, body: [], size: 0 };
|
|
18149
|
-
return new
|
|
18149
|
+
return new Writable2({
|
|
18150
18150
|
write(chunk, encoding, callback) {
|
|
18151
18151
|
if (typeof chunk === "string") {
|
|
18152
18152
|
chunk = Buffer.from(chunk, encoding);
|
|
@@ -18297,8 +18297,8 @@ var require_cache_revalidation_handler = __commonJS({
|
|
|
18297
18297
|
this.#successful = false;
|
|
18298
18298
|
this.#context = context;
|
|
18299
18299
|
}
|
|
18300
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
18301
|
-
this.#handler.onRequestUpgrade?.(controller, statusCode, headers,
|
|
18300
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
18301
|
+
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket);
|
|
18302
18302
|
}
|
|
18303
18303
|
onResponseStart(controller, statusCode, headers, statusMessage) {
|
|
18304
18304
|
assert(this.#callback != null);
|
|
@@ -19215,8 +19215,8 @@ var require_decompress = __commonJS({
|
|
|
19215
19215
|
this.#controller.target = controller;
|
|
19216
19216
|
return super.onRequestStart(this.#controller, context);
|
|
19217
19217
|
}
|
|
19218
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
19219
|
-
return super.onRequestUpgrade(this.#controller, statusCode, headers,
|
|
19218
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
19219
|
+
return super.onRequestUpgrade(this.#controller, statusCode, headers, socket);
|
|
19220
19220
|
}
|
|
19221
19221
|
/**
|
|
19222
19222
|
* @param {Controller} controller
|
|
@@ -19480,8 +19480,8 @@ var require_deduplication_handler = __commonJS({
|
|
|
19480
19480
|
* @param {import('../../types/header.d.ts').IncomingHttpHeaders} headers
|
|
19481
19481
|
* @param {Socket} socket
|
|
19482
19482
|
*/
|
|
19483
|
-
onRequestUpgrade(controller, statusCode, headers,
|
|
19484
|
-
this.#primaryHandler.onRequestUpgrade?.(controller, statusCode, headers,
|
|
19483
|
+
onRequestUpgrade(controller, statusCode, headers, socket) {
|
|
19484
|
+
this.#primaryHandler.onRequestUpgrade?.(controller, statusCode, headers, socket);
|
|
19485
19485
|
}
|
|
19486
19486
|
/**
|
|
19487
19487
|
* @param {import('../../types/dispatcher.d.ts').default.DispatchController} controller
|
|
@@ -19814,7 +19814,7 @@ var require_deduplicate = __commonJS({
|
|
|
19814
19814
|
var require_sqlite_cache_store = __commonJS({
|
|
19815
19815
|
"node_modules/undici/lib/cache/sqlite-cache-store.js"(exports, module) {
|
|
19816
19816
|
"use strict";
|
|
19817
|
-
var { Writable } = __require("node:stream");
|
|
19817
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
19818
19818
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
19819
19819
|
var DatabaseSync;
|
|
19820
19820
|
var VERSION = 4;
|
|
@@ -20058,7 +20058,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
20058
20058
|
let size = 0;
|
|
20059
20059
|
const body = [];
|
|
20060
20060
|
const store = this;
|
|
20061
|
-
return new
|
|
20061
|
+
return new Writable2({
|
|
20062
20062
|
decodeStrings: true,
|
|
20063
20063
|
write(chunk, encoding, callback) {
|
|
20064
20064
|
size += chunk.byteLength;
|
|
@@ -21131,39 +21131,39 @@ var require_request2 = __commonJS({
|
|
|
21131
21131
|
#headers;
|
|
21132
21132
|
#state;
|
|
21133
21133
|
// https://fetch.spec.whatwg.org/#dom-request
|
|
21134
|
-
constructor(
|
|
21134
|
+
constructor(input, init = void 0) {
|
|
21135
21135
|
webidl.util.markAsUncloneable(this);
|
|
21136
|
-
if (
|
|
21136
|
+
if (input === kConstruct) {
|
|
21137
21137
|
return;
|
|
21138
21138
|
}
|
|
21139
21139
|
const prefix = "Request constructor";
|
|
21140
21140
|
webidl.argumentLengthCheck(arguments, 1, prefix);
|
|
21141
|
-
|
|
21141
|
+
input = webidl.converters.RequestInfo(input);
|
|
21142
21142
|
init = webidl.converters.RequestInit(init);
|
|
21143
21143
|
let request = null;
|
|
21144
21144
|
let fallbackMode = null;
|
|
21145
21145
|
const baseUrl = environmentSettingsObject.settingsObject.baseUrl;
|
|
21146
21146
|
let signal = null;
|
|
21147
|
-
if (typeof
|
|
21147
|
+
if (typeof input === "string") {
|
|
21148
21148
|
this.#dispatcher = init.dispatcher;
|
|
21149
21149
|
let parsedURL;
|
|
21150
21150
|
try {
|
|
21151
|
-
parsedURL = new URL(
|
|
21151
|
+
parsedURL = new URL(input, baseUrl);
|
|
21152
21152
|
} catch (err) {
|
|
21153
|
-
throw new TypeError("Failed to parse URL from " +
|
|
21153
|
+
throw new TypeError("Failed to parse URL from " + input, { cause: err });
|
|
21154
21154
|
}
|
|
21155
21155
|
if (parsedURL.username || parsedURL.password) {
|
|
21156
21156
|
throw new TypeError(
|
|
21157
|
-
"Request cannot be constructed from a URL that includes credentials: " +
|
|
21157
|
+
"Request cannot be constructed from a URL that includes credentials: " + input
|
|
21158
21158
|
);
|
|
21159
21159
|
}
|
|
21160
21160
|
request = makeRequest({ urlList: [parsedURL] });
|
|
21161
21161
|
fallbackMode = "cors";
|
|
21162
21162
|
} else {
|
|
21163
|
-
assert(webidl.is.Request(
|
|
21164
|
-
request =
|
|
21165
|
-
signal =
|
|
21166
|
-
this.#dispatcher = init.dispatcher ||
|
|
21163
|
+
assert(webidl.is.Request(input));
|
|
21164
|
+
request = input.#state;
|
|
21165
|
+
signal = input.#signal;
|
|
21166
|
+
this.#dispatcher = init.dispatcher || input.#dispatcher;
|
|
21167
21167
|
}
|
|
21168
21168
|
const origin = environmentSettingsObject.settingsObject.origin;
|
|
21169
21169
|
let window = "client";
|
|
@@ -21355,7 +21355,7 @@ var require_request2 = __commonJS({
|
|
|
21355
21355
|
fillHeaders(this.#headers, headers);
|
|
21356
21356
|
}
|
|
21357
21357
|
}
|
|
21358
|
-
const inputBody = webidl.is.Request(
|
|
21358
|
+
const inputBody = webidl.is.Request(input) ? input.#state.body : null;
|
|
21359
21359
|
if ((init.body != null || inputBody != null) && (request.method === "GET" || request.method === "HEAD")) {
|
|
21360
21360
|
throw new TypeError("Request with GET/HEAD method cannot have body.");
|
|
21361
21361
|
}
|
|
@@ -21384,7 +21384,7 @@ var require_request2 = __commonJS({
|
|
|
21384
21384
|
}
|
|
21385
21385
|
let finalBody = inputOrInitBody;
|
|
21386
21386
|
if (initBody == null && inputBody != null) {
|
|
21387
|
-
if (bodyUnusable(
|
|
21387
|
+
if (bodyUnusable(input.#state)) {
|
|
21388
21388
|
throw new TypeError(
|
|
21389
21389
|
"Cannot construct a Request with a Request object that has already been used."
|
|
21390
21390
|
);
|
|
@@ -21821,10 +21821,10 @@ var require_subresource_integrity = __commonJS({
|
|
|
21821
21821
|
var { runtimeFeatures } = require_runtime_features();
|
|
21822
21822
|
var { asciiLowercase } = require_infra();
|
|
21823
21823
|
var validSRIHashAlgorithmTokenSet = /* @__PURE__ */ new Map([["sha256", 0], ["sha384", 1], ["sha512", 2]]);
|
|
21824
|
-
var
|
|
21824
|
+
var crypto3;
|
|
21825
21825
|
if (runtimeFeatures.has("crypto")) {
|
|
21826
|
-
|
|
21827
|
-
const cryptoHashes =
|
|
21826
|
+
crypto3 = __require("node:crypto");
|
|
21827
|
+
const cryptoHashes = crypto3.getHashes();
|
|
21828
21828
|
if (cryptoHashes.length === 0) {
|
|
21829
21829
|
validSRIHashAlgorithmTokenSet.clear();
|
|
21830
21830
|
}
|
|
@@ -21912,7 +21912,7 @@ var require_subresource_integrity = __commonJS({
|
|
|
21912
21912
|
return result;
|
|
21913
21913
|
}
|
|
21914
21914
|
var applyAlgorithmToBytes = (algorithm, bytes) => {
|
|
21915
|
-
return
|
|
21915
|
+
return crypto3.hash(algorithm, bytes, "base64");
|
|
21916
21916
|
};
|
|
21917
21917
|
function caseSensitiveMatch(actualValue, expectedValue) {
|
|
21918
21918
|
let actualValueLength = actualValue.length;
|
|
@@ -22057,12 +22057,12 @@ var require_fetch = __commonJS({
|
|
|
22057
22057
|
function handleFetchDone(response) {
|
|
22058
22058
|
finalizeAndReportTiming(response, "fetch");
|
|
22059
22059
|
}
|
|
22060
|
-
function fetch(
|
|
22060
|
+
function fetch(input, init = void 0) {
|
|
22061
22061
|
webidl.argumentLengthCheck(arguments, 1, "globalThis.fetch");
|
|
22062
22062
|
let p = createDeferredPromise();
|
|
22063
22063
|
let requestObject;
|
|
22064
22064
|
try {
|
|
22065
|
-
requestObject = new Request(
|
|
22065
|
+
requestObject = new Request(input, init);
|
|
22066
22066
|
} catch (e) {
|
|
22067
22067
|
p.reject(e);
|
|
22068
22068
|
return p.promise;
|
|
@@ -22808,9 +22808,9 @@ var require_fetch = __commonJS({
|
|
|
22808
22808
|
})();
|
|
22809
22809
|
}
|
|
22810
22810
|
try {
|
|
22811
|
-
const { body, status, statusText, headersList, socket
|
|
22812
|
-
if (
|
|
22813
|
-
response = makeResponse({ status, statusText, headersList, socket
|
|
22811
|
+
const { body, status, statusText, headersList, socket } = await dispatch({ body: requestBody });
|
|
22812
|
+
if (socket) {
|
|
22813
|
+
response = makeResponse({ status, statusText, headersList, socket });
|
|
22814
22814
|
} else {
|
|
22815
22815
|
const iterator = body[Symbol.asyncIterator]();
|
|
22816
22816
|
fetchParams.controller.next = () => iterator.next();
|
|
@@ -23032,8 +23032,8 @@ var require_fetch = __commonJS({
|
|
|
23032
23032
|
fetchParams.controller.terminate(error);
|
|
23033
23033
|
reject(error);
|
|
23034
23034
|
},
|
|
23035
|
-
onRequestUpgrade(_controller, status, headers,
|
|
23036
|
-
if (
|
|
23035
|
+
onRequestUpgrade(_controller, status, headers, socket) {
|
|
23036
|
+
if (socket.session != null && status !== 200 || socket.session == null && status !== 101) {
|
|
23037
23037
|
return false;
|
|
23038
23038
|
}
|
|
23039
23039
|
const headersList = new HeadersList();
|
|
@@ -23054,12 +23054,12 @@ var require_fetch = __commonJS({
|
|
|
23054
23054
|
status,
|
|
23055
23055
|
statusText: STATUS_CODES[status],
|
|
23056
23056
|
headersList,
|
|
23057
|
-
socket
|
|
23057
|
+
socket
|
|
23058
23058
|
});
|
|
23059
23059
|
return true;
|
|
23060
23060
|
},
|
|
23061
|
-
onUpgrade(status, rawHeaders,
|
|
23062
|
-
if (
|
|
23061
|
+
onUpgrade(status, rawHeaders, socket) {
|
|
23062
|
+
if (socket.session != null && status !== 200 || socket.session == null && status !== 101) {
|
|
23063
23063
|
return false;
|
|
23064
23064
|
}
|
|
23065
23065
|
const headersList = new HeadersList();
|
|
@@ -23078,7 +23078,7 @@ var require_fetch = __commonJS({
|
|
|
23078
23078
|
status,
|
|
23079
23079
|
statusText: STATUS_CODES[status],
|
|
23080
23080
|
headersList,
|
|
23081
|
-
socket
|
|
23081
|
+
socket
|
|
23082
23082
|
});
|
|
23083
23083
|
return true;
|
|
23084
23084
|
}
|
|
@@ -24900,7 +24900,7 @@ var require_connection = __commonJS({
|
|
|
24900
24900
|
var { WebsocketFrameSend } = require_frame();
|
|
24901
24901
|
var assert = __require("node:assert");
|
|
24902
24902
|
var { runtimeFeatures } = require_runtime_features();
|
|
24903
|
-
var
|
|
24903
|
+
var crypto3 = runtimeFeatures.has("crypto") ? __require("node:crypto") : null;
|
|
24904
24904
|
var warningEmitted = false;
|
|
24905
24905
|
function establishWebSocketConnection(url, protocols, client, handler, options) {
|
|
24906
24906
|
const requestURL = url;
|
|
@@ -24920,7 +24920,7 @@ var require_connection = __commonJS({
|
|
|
24920
24920
|
const headersList = getHeadersList(new Headers(options.headers));
|
|
24921
24921
|
request.headersList = headersList;
|
|
24922
24922
|
}
|
|
24923
|
-
const keyValue =
|
|
24923
|
+
const keyValue = crypto3.randomBytes(16).toString("base64");
|
|
24924
24924
|
request.headersList.append("sec-websocket-key", keyValue, true);
|
|
24925
24925
|
request.headersList.append("sec-websocket-version", "13", true);
|
|
24926
24926
|
for (const protocol of protocols) {
|
|
@@ -24960,7 +24960,7 @@ var require_connection = __commonJS({
|
|
|
24960
24960
|
return;
|
|
24961
24961
|
}
|
|
24962
24962
|
const secWSAccept = response.headersList.get("Sec-WebSocket-Accept");
|
|
24963
|
-
const digest =
|
|
24963
|
+
const digest = crypto3.hash("sha1", keyValue + uid, "base64");
|
|
24964
24964
|
if (secWSAccept !== digest) {
|
|
24965
24965
|
failHandshake(handler, response, 1002, "Incorrect hash received in Sec-WebSocket-Accept header.");
|
|
24966
24966
|
return;
|
|
@@ -25135,7 +25135,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
25135
25135
|
var require_receiver = __commonJS({
|
|
25136
25136
|
"node_modules/undici/lib/web/websocket/receiver.js"(exports, module) {
|
|
25137
25137
|
"use strict";
|
|
25138
|
-
var { Writable } = __require("node:stream");
|
|
25138
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
25139
25139
|
var assert = __require("node:assert");
|
|
25140
25140
|
var { parserStates, opcodes, states, emptyBuffer, sentCloseFrameState } = require_constants5();
|
|
25141
25141
|
var {
|
|
@@ -25151,7 +25151,7 @@ var require_receiver = __commonJS({
|
|
|
25151
25151
|
var { WebsocketFrameSend } = require_frame();
|
|
25152
25152
|
var { PerMessageDeflate } = require_permessage_deflate();
|
|
25153
25153
|
var { MessageSizeExceededError } = require_errors();
|
|
25154
|
-
var ByteParser = class extends
|
|
25154
|
+
var ByteParser = class extends Writable2 {
|
|
25155
25155
|
#buffers = [];
|
|
25156
25156
|
#fragmentsBytes = 0;
|
|
25157
25157
|
#byteOffset = 0;
|
|
@@ -25517,8 +25517,8 @@ var require_sender = __commonJS({
|
|
|
25517
25517
|
#running = false;
|
|
25518
25518
|
/** @type {import('node:net').Socket} */
|
|
25519
25519
|
#socket;
|
|
25520
|
-
constructor(
|
|
25521
|
-
this.#socket =
|
|
25520
|
+
constructor(socket) {
|
|
25521
|
+
this.#socket = socket;
|
|
25522
25522
|
}
|
|
25523
25523
|
add(item, cb, hint) {
|
|
25524
25524
|
if (hint !== sendHints.blob) {
|
|
@@ -25614,16 +25614,16 @@ var require_websocket = __commonJS({
|
|
|
25614
25614
|
var { SendQueue } = require_sender();
|
|
25615
25615
|
var { WebsocketFrameSend } = require_frame();
|
|
25616
25616
|
var { channels } = require_diagnostics();
|
|
25617
|
-
function getSocketAddress(
|
|
25618
|
-
if (typeof
|
|
25619
|
-
return
|
|
25617
|
+
function getSocketAddress(socket) {
|
|
25618
|
+
if (typeof socket?.address === "function") {
|
|
25619
|
+
return socket.address();
|
|
25620
25620
|
}
|
|
25621
|
-
if (typeof
|
|
25622
|
-
return
|
|
25621
|
+
if (typeof socket?.session?.socket?.address === "function") {
|
|
25622
|
+
return socket.session.socket.address();
|
|
25623
25623
|
}
|
|
25624
25624
|
return null;
|
|
25625
25625
|
}
|
|
25626
|
-
var
|
|
25626
|
+
var WebSocket2 = class _WebSocket extends EventTarget {
|
|
25627
25627
|
#events = {
|
|
25628
25628
|
open: null,
|
|
25629
25629
|
error: null,
|
|
@@ -25991,13 +25991,13 @@ var require_websocket = __commonJS({
|
|
|
25991
25991
|
}
|
|
25992
25992
|
}
|
|
25993
25993
|
};
|
|
25994
|
-
var { ping } =
|
|
25995
|
-
Reflect.deleteProperty(
|
|
25996
|
-
|
|
25997
|
-
|
|
25998
|
-
|
|
25999
|
-
|
|
26000
|
-
Object.defineProperties(
|
|
25994
|
+
var { ping } = WebSocket2;
|
|
25995
|
+
Reflect.deleteProperty(WebSocket2, "ping");
|
|
25996
|
+
WebSocket2.CONNECTING = WebSocket2.prototype.CONNECTING = states.CONNECTING;
|
|
25997
|
+
WebSocket2.OPEN = WebSocket2.prototype.OPEN = states.OPEN;
|
|
25998
|
+
WebSocket2.CLOSING = WebSocket2.prototype.CLOSING = states.CLOSING;
|
|
25999
|
+
WebSocket2.CLOSED = WebSocket2.prototype.CLOSED = states.CLOSED;
|
|
26000
|
+
Object.defineProperties(WebSocket2.prototype, {
|
|
26001
26001
|
CONNECTING: staticPropertyDescriptors,
|
|
26002
26002
|
OPEN: staticPropertyDescriptors,
|
|
26003
26003
|
CLOSING: staticPropertyDescriptors,
|
|
@@ -26021,7 +26021,7 @@ var require_websocket = __commonJS({
|
|
|
26021
26021
|
configurable: true
|
|
26022
26022
|
}
|
|
26023
26023
|
});
|
|
26024
|
-
Object.defineProperties(
|
|
26024
|
+
Object.defineProperties(WebSocket2, {
|
|
26025
26025
|
CONNECTING: staticPropertyDescriptors,
|
|
26026
26026
|
OPEN: staticPropertyDescriptors,
|
|
26027
26027
|
CLOSING: staticPropertyDescriptors,
|
|
@@ -26070,7 +26070,7 @@ var require_websocket = __commonJS({
|
|
|
26070
26070
|
return webidl.converters.USVString(V);
|
|
26071
26071
|
};
|
|
26072
26072
|
module.exports = {
|
|
26073
|
-
WebSocket,
|
|
26073
|
+
WebSocket: WebSocket2,
|
|
26074
26074
|
ping
|
|
26075
26075
|
};
|
|
26076
26076
|
}
|
|
@@ -27223,7 +27223,7 @@ var require_undici = __commonJS({
|
|
|
27223
27223
|
var Pool = require_pool();
|
|
27224
27224
|
var BalancedPool = require_balanced_pool();
|
|
27225
27225
|
var RoundRobinPool = require_round_robin_pool();
|
|
27226
|
-
var
|
|
27226
|
+
var Agent2 = require_agent();
|
|
27227
27227
|
var ProxyAgent = require_proxy_agent();
|
|
27228
27228
|
var Socks5ProxyAgent = require_socks5_proxy_agent();
|
|
27229
27229
|
var EnvHttpProxyAgent2 = require_env_http_proxy_agent();
|
|
@@ -27250,7 +27250,7 @@ var require_undici = __commonJS({
|
|
|
27250
27250
|
module.exports.Pool = Pool;
|
|
27251
27251
|
module.exports.BalancedPool = BalancedPool;
|
|
27252
27252
|
module.exports.RoundRobinPool = RoundRobinPool;
|
|
27253
|
-
module.exports.Agent =
|
|
27253
|
+
module.exports.Agent = Agent2;
|
|
27254
27254
|
module.exports.ProxyAgent = ProxyAgent;
|
|
27255
27255
|
module.exports.Socks5ProxyAgent = Socks5ProxyAgent;
|
|
27256
27256
|
module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent2;
|
|
@@ -27371,8 +27371,8 @@ ${captureLines}` : capture.stack;
|
|
|
27371
27371
|
module.exports.parseMIMEType = parseMIMEType;
|
|
27372
27372
|
module.exports.serializeAMimeType = serializeAMimeType;
|
|
27373
27373
|
var { CloseEvent, ErrorEvent, MessageEvent } = require_events();
|
|
27374
|
-
var { WebSocket, ping } = require_websocket();
|
|
27375
|
-
module.exports.WebSocket =
|
|
27374
|
+
var { WebSocket: WebSocket2, ping } = require_websocket();
|
|
27375
|
+
module.exports.WebSocket = WebSocket2;
|
|
27376
27376
|
module.exports.CloseEvent = CloseEvent;
|
|
27377
27377
|
module.exports.ErrorEvent = ErrorEvent;
|
|
27378
27378
|
module.exports.MessageEvent = MessageEvent;
|
|
@@ -27410,17 +27410,29 @@ ${captureLines}` : capture.stack;
|
|
|
27410
27410
|
});
|
|
27411
27411
|
|
|
27412
27412
|
// src/codex-proxy.ts
|
|
27413
|
-
import net2 from "node:net";
|
|
27414
|
-
import fs6 from "node:fs";
|
|
27415
27413
|
import { createInterface } from "node:readline";
|
|
27416
27414
|
|
|
27417
|
-
// src/codex-
|
|
27418
|
-
import
|
|
27415
|
+
// src/codex-execution.ts
|
|
27416
|
+
import crypto2 from "node:crypto";
|
|
27419
27417
|
import fs5 from "node:fs";
|
|
27420
|
-
import
|
|
27421
|
-
import
|
|
27418
|
+
import path6 from "node:path";
|
|
27419
|
+
import { spawn } from "node:child_process";
|
|
27422
27420
|
import { fileURLToPath } from "node:url";
|
|
27423
27421
|
|
|
27422
|
+
// ../cli/src/lib/shared/conversation.ts
|
|
27423
|
+
function bounded(work, ms, reason) {
|
|
27424
|
+
return new Promise((resolve, reject) => {
|
|
27425
|
+
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
27426
|
+
work.then((value) => {
|
|
27427
|
+
clearTimeout(timer);
|
|
27428
|
+
resolve(value);
|
|
27429
|
+
}, (error) => {
|
|
27430
|
+
clearTimeout(timer);
|
|
27431
|
+
reject(error);
|
|
27432
|
+
});
|
|
27433
|
+
});
|
|
27434
|
+
}
|
|
27435
|
+
|
|
27424
27436
|
// ../cli/src/lib/lock.ts
|
|
27425
27437
|
import { randomUUID } from "node:crypto";
|
|
27426
27438
|
import fs2 from "node:fs";
|
|
@@ -27620,8 +27632,8 @@ function tryLock(dir) {
|
|
|
27620
27632
|
}
|
|
27621
27633
|
if (entries.length) {
|
|
27622
27634
|
if (entries.length !== 1 || !/^\d+-[a-f0-9-]{36}$/.test(entries[0])) return void 0;
|
|
27623
|
-
const
|
|
27624
|
-
if (pidAlive(
|
|
27635
|
+
const owner = Number(entries[0].split("-")[0]);
|
|
27636
|
+
if (pidAlive(owner)) return void 0;
|
|
27625
27637
|
}
|
|
27626
27638
|
if (!removeClaim(dir, entries[0])) return void 0;
|
|
27627
27639
|
}
|
|
@@ -27630,17 +27642,131 @@ function tryLock(dir) {
|
|
|
27630
27642
|
}
|
|
27631
27643
|
}
|
|
27632
27644
|
|
|
27633
|
-
// src/
|
|
27634
|
-
|
|
27645
|
+
// ../cli/src/lib/agent/wire/json.ts
|
|
27646
|
+
function obj(value) {
|
|
27647
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27648
|
+
}
|
|
27649
|
+
function str(value) {
|
|
27650
|
+
return typeof value === "string" ? value : "";
|
|
27651
|
+
}
|
|
27652
|
+
|
|
27653
|
+
// ../cli/src/lib/agent/wire/rpc.ts
|
|
27654
|
+
var RpcError = class extends Error {
|
|
27655
|
+
constructor(message, code) {
|
|
27656
|
+
super(message);
|
|
27657
|
+
this.code = code;
|
|
27658
|
+
this.name = "RpcError";
|
|
27659
|
+
}
|
|
27660
|
+
code;
|
|
27661
|
+
};
|
|
27662
|
+
function connect(stdout, stdin, onCall, dialect = {}) {
|
|
27663
|
+
let buf = "";
|
|
27664
|
+
let nextId = 1;
|
|
27665
|
+
let gone;
|
|
27666
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
27667
|
+
const send = (msg) => {
|
|
27668
|
+
if (gone) return;
|
|
27669
|
+
try {
|
|
27670
|
+
stdin.write(`${JSON.stringify(dialect.jsonrpc ? { jsonrpc: "2.0", ...msg } : msg)}
|
|
27671
|
+
`);
|
|
27672
|
+
} catch {
|
|
27673
|
+
}
|
|
27674
|
+
};
|
|
27675
|
+
const closed = (why) => {
|
|
27676
|
+
if (gone) return;
|
|
27677
|
+
gone = why;
|
|
27678
|
+
for (const { fail } of waiting.values()) fail(new Error(why));
|
|
27679
|
+
waiting.clear();
|
|
27680
|
+
};
|
|
27681
|
+
stdout.on("data", (chunk) => {
|
|
27682
|
+
buf += chunk.toString();
|
|
27683
|
+
const lines = buf.split("\n");
|
|
27684
|
+
buf = lines.pop() ?? "";
|
|
27685
|
+
for (const line of lines) {
|
|
27686
|
+
if (!line.trim()) continue;
|
|
27687
|
+
let msg;
|
|
27688
|
+
try {
|
|
27689
|
+
msg = JSON.parse(line);
|
|
27690
|
+
} catch {
|
|
27691
|
+
continue;
|
|
27692
|
+
}
|
|
27693
|
+
if (msg.method) {
|
|
27694
|
+
onCall(msg);
|
|
27695
|
+
continue;
|
|
27696
|
+
}
|
|
27697
|
+
if (msg.id === void 0) continue;
|
|
27698
|
+
const pending = waiting.get(String(msg.id));
|
|
27699
|
+
if (!pending) continue;
|
|
27700
|
+
waiting.delete(String(msg.id));
|
|
27701
|
+
if (msg.error) {
|
|
27702
|
+
const said = [str(msg.error.message), str(obj(msg.error.data).message)].filter(Boolean).join(": ");
|
|
27703
|
+
pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code));
|
|
27704
|
+
} else pending.ok(obj(msg.result));
|
|
27705
|
+
}
|
|
27706
|
+
});
|
|
27707
|
+
stdout.on("close", () => closed("the agent closed the connection"));
|
|
27708
|
+
stdout.on("error", (err) => closed(String(err)));
|
|
27709
|
+
stdin.on("error", (err) => closed(String(err)));
|
|
27710
|
+
return {
|
|
27711
|
+
/** Ask the agent something. Rejects with the agent's own words when it says no. */
|
|
27712
|
+
call(method, params) {
|
|
27713
|
+
if (gone) return Promise.reject(new Error(gone));
|
|
27714
|
+
const id = dialect.stringIds ? String(nextId++) : nextId++;
|
|
27715
|
+
return new Promise((ok, fail) => {
|
|
27716
|
+
waiting.set(String(id), { ok, fail });
|
|
27717
|
+
send({ id, method, params });
|
|
27718
|
+
});
|
|
27719
|
+
},
|
|
27720
|
+
notify(method, params = {}) {
|
|
27721
|
+
send({ method, params });
|
|
27722
|
+
},
|
|
27723
|
+
/** Answer something the agent asked us. */
|
|
27724
|
+
reply(id, result) {
|
|
27725
|
+
send({ id, result });
|
|
27726
|
+
},
|
|
27727
|
+
/** Say we can't. Sent for anything we never offered to do, so the agent gets an answer
|
|
27728
|
+
* rather than waiting on one forever. */
|
|
27729
|
+
refuse(id, message) {
|
|
27730
|
+
send({ id, error: { code: -32601, message } });
|
|
27731
|
+
}
|
|
27732
|
+
};
|
|
27733
|
+
}
|
|
27734
|
+
|
|
27735
|
+
// src/codex-config.ts
|
|
27635
27736
|
var import_smol_toml = __toESM(require_dist(), 1);
|
|
27737
|
+
function mcpEnvironment(config, defaults) {
|
|
27738
|
+
const servers = obj(config.mcp_servers);
|
|
27739
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(defaults), ...Object.keys(servers)]);
|
|
27740
|
+
for (const key of Object.keys(config)) {
|
|
27741
|
+
const name = /^mcp_servers\.([^.]+)\./.exec(key)?.[1];
|
|
27742
|
+
if (name) names.add(name);
|
|
27743
|
+
}
|
|
27744
|
+
for (const name of names) {
|
|
27745
|
+
const key = `mcp_servers.${name}.env`;
|
|
27746
|
+
const explicit = Object.fromEntries(Object.entries(config).filter(([k]) => k.startsWith(key + ".")).map(([k, value]) => [k.slice(key.length + 1), value]));
|
|
27747
|
+
config[key] = { ...obj(obj(defaults[name]).env), ...obj(obj(servers[name]).env), ...obj(config[key]), ...explicit, ...obj(config["shell_environment_policy.set"]) };
|
|
27748
|
+
}
|
|
27749
|
+
}
|
|
27636
27750
|
|
|
27637
|
-
//
|
|
27638
|
-
|
|
27639
|
-
|
|
27640
|
-
|
|
27641
|
-
|
|
27642
|
-
|
|
27643
|
-
|
|
27751
|
+
// src/codex-native.ts
|
|
27752
|
+
import crypto from "node:crypto";
|
|
27753
|
+
import fs4 from "node:fs";
|
|
27754
|
+
var import_undici2 = __toESM(require_undici(), 1);
|
|
27755
|
+
import path5 from "node:path";
|
|
27756
|
+
import { PassThrough, Writable } from "node:stream";
|
|
27757
|
+
|
|
27758
|
+
// ../cli/src/lib/agent/connection-process.ts
|
|
27759
|
+
import { spawnSync } from "node:child_process";
|
|
27760
|
+
function connectionIdentity(pid) {
|
|
27761
|
+
const result = process.platform === "win32" ? spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CreationDate.ToUniversalTime().ToString('o')`], { encoding: "utf8", timeout: 2e3, windowsHide: true }) : spawnSync("ps", ["-p", String(pid), "-o", "lstart="], { encoding: "utf8", timeout: 2e3, env: { ...process.env, LC_ALL: "C" } });
|
|
27762
|
+
return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
|
|
27763
|
+
}
|
|
27764
|
+
function connectionStopped(root) {
|
|
27765
|
+
if (!root) return true;
|
|
27766
|
+
if (!pidAlive(root.pid)) return true;
|
|
27767
|
+
const identity = connectionIdentity(root.pid);
|
|
27768
|
+
return !!root.identity && !!identity && identity !== root.identity;
|
|
27769
|
+
}
|
|
27644
27770
|
|
|
27645
27771
|
// src/home.ts
|
|
27646
27772
|
import fs3 from "node:fs";
|
|
@@ -27660,201 +27786,477 @@ function runnerCwd() {
|
|
|
27660
27786
|
return dir;
|
|
27661
27787
|
}
|
|
27662
27788
|
|
|
27663
|
-
// src/
|
|
27664
|
-
|
|
27665
|
-
|
|
27666
|
-
var
|
|
27667
|
-
|
|
27789
|
+
// src/codex-native.ts
|
|
27790
|
+
var CODEX_PROTOCOL = 3;
|
|
27791
|
+
var CODEX_TIMEOUT = 1e4;
|
|
27792
|
+
var nativeDirectory = () => path5.join(runnerCwd(), "codex-native");
|
|
27793
|
+
var codexRecordFile = () => path5.join(nativeDirectory(), "runner.json");
|
|
27794
|
+
var backendFile = (key) => path5.join(nativeDirectory(), `${key}.json`);
|
|
27795
|
+
var leaseFile = (backend, thread) => path5.join(nativeDirectory(), "threads", backend.instance, `${crypto.createHash("sha256").update(thread).digest("hex")}.json`);
|
|
27796
|
+
var liveLease = (lease) => !connectionStopped(lease);
|
|
27797
|
+
var processIdentity = () => ({ pid: process.pid, identity: connectionIdentity(process.pid) });
|
|
27798
|
+
function writePrivate(file, value) {
|
|
27799
|
+
fs4.mkdirSync(path5.dirname(file), { recursive: true, mode: 448 });
|
|
27800
|
+
const temporary = `${file}.${crypto.randomUUID()}.tmp`;
|
|
27801
|
+
fs4.writeFileSync(temporary, JSON.stringify(value), { mode: 384 });
|
|
27802
|
+
fs4.renameSync(temporary, file);
|
|
27803
|
+
}
|
|
27804
|
+
function readPrivate(file) {
|
|
27668
27805
|
try {
|
|
27669
|
-
return fs4.readFileSync(
|
|
27670
|
-
} catch {
|
|
27671
|
-
|
|
27806
|
+
return JSON.parse(fs4.readFileSync(file, "utf8"));
|
|
27807
|
+
} catch (error) {
|
|
27808
|
+
if (error.code === "ENOENT") return;
|
|
27809
|
+
throw error;
|
|
27672
27810
|
}
|
|
27673
27811
|
}
|
|
27674
|
-
|
|
27675
|
-
|
|
27676
|
-
|
|
27677
|
-
|
|
27678
|
-
|
|
27679
|
-
|
|
27680
|
-
|
|
27681
|
-
|
|
27682
|
-
|
|
27812
|
+
async function nativeConnection(backend, onMessage) {
|
|
27813
|
+
const unix = backend.endpoint.startsWith("unix://");
|
|
27814
|
+
const dispatcher = unix ? new import_undici2.Agent({ connect: { socketPath: backend.endpoint.slice(7) } }) : void 0;
|
|
27815
|
+
const ws = new import_undici2.WebSocket(unix ? "ws://localhost" : backend.endpoint, {
|
|
27816
|
+
...dispatcher ? { dispatcher } : {},
|
|
27817
|
+
...backend.token ? { headers: { authorization: `Bearer ${backend.token}` } } : {}
|
|
27818
|
+
});
|
|
27819
|
+
const incoming = new PassThrough();
|
|
27820
|
+
const outgoing = new Writable({ write(chunk, _encoding, done) {
|
|
27821
|
+
try {
|
|
27822
|
+
ws.send(String(chunk).trimEnd());
|
|
27823
|
+
done();
|
|
27824
|
+
} catch (error) {
|
|
27825
|
+
done(error);
|
|
27826
|
+
}
|
|
27827
|
+
} });
|
|
27828
|
+
incoming.on("error", () => {
|
|
27829
|
+
});
|
|
27830
|
+
outgoing.on("error", () => {
|
|
27831
|
+
});
|
|
27832
|
+
ws.addEventListener("message", (event) => incoming.write(String(event.data) + "\n"));
|
|
27833
|
+
ws.addEventListener("close", () => incoming.destroy());
|
|
27834
|
+
ws.addEventListener("error", () => incoming.destroy(Error("Codex native connection failed.")));
|
|
27835
|
+
const close = () => {
|
|
27836
|
+
ws.close();
|
|
27837
|
+
incoming.destroy();
|
|
27838
|
+
outgoing.destroy();
|
|
27839
|
+
void dispatcher?.destroy();
|
|
27840
|
+
};
|
|
27683
27841
|
try {
|
|
27684
|
-
|
|
27685
|
-
|
|
27686
|
-
|
|
27687
|
-
|
|
27842
|
+
await bounded(new Promise((resolve, reject) => {
|
|
27843
|
+
ws.addEventListener("open", () => resolve(), { once: true });
|
|
27844
|
+
ws.addEventListener("error", () => reject(Error("Codex native listener did not answer.")), { once: true });
|
|
27845
|
+
}), CODEX_TIMEOUT, "Codex native connection timed out.");
|
|
27688
27846
|
} catch (error) {
|
|
27689
|
-
|
|
27847
|
+
close();
|
|
27690
27848
|
throw error;
|
|
27691
27849
|
}
|
|
27850
|
+
const rpc = connect(incoming, outgoing, onMessage);
|
|
27851
|
+
return { rpc, incoming, close };
|
|
27692
27852
|
}
|
|
27693
|
-
function
|
|
27694
|
-
|
|
27695
|
-
|
|
27696
|
-
|
|
27697
|
-
|
|
27698
|
-
|
|
27699
|
-
|
|
27700
|
-
|
|
27701
|
-
|
|
27702
|
-
|
|
27703
|
-
|
|
27704
|
-
|
|
27705
|
-
|
|
27706
|
-
|
|
27707
|
-
|
|
27853
|
+
async function initializeNative(connection) {
|
|
27854
|
+
const result = await bounded(connection.rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), CODEX_TIMEOUT, "Codex initialize timed out.");
|
|
27855
|
+
connection.rpc.notify("initialized");
|
|
27856
|
+
return result;
|
|
27857
|
+
}
|
|
27858
|
+
async function backgroundTerminals(rpc, threadId) {
|
|
27859
|
+
const result = [], seen = /* @__PURE__ */ new Set();
|
|
27860
|
+
let cursor = null;
|
|
27861
|
+
do {
|
|
27862
|
+
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
27863
|
+
seen.add(cursor);
|
|
27864
|
+
const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
27865
|
+
for (const value of Array.isArray(page.data) ? page.data : []) result.push({ ...obj(value), threadId });
|
|
27866
|
+
cursor = page.nextCursor;
|
|
27867
|
+
} while (cursor);
|
|
27868
|
+
return result;
|
|
27869
|
+
}
|
|
27870
|
+
|
|
27871
|
+
// src/codex-execution.ts
|
|
27872
|
+
async function codexExecution(backend, config, environment, cwd, send) {
|
|
27873
|
+
const identity = processIdentity();
|
|
27874
|
+
const lease = crypto2.randomUUID();
|
|
27875
|
+
const settings = crypto2.createHash("sha256").update(JSON.stringify([cwd, config])).digest("hex");
|
|
27876
|
+
const threads = /* @__PURE__ */ new Set(), active = /* @__PURE__ */ new Map(), requests = /* @__PURE__ */ new Set();
|
|
27877
|
+
const preparing = /* @__PURE__ */ new Map();
|
|
27878
|
+
const pending = /* @__PURE__ */ new Set();
|
|
27879
|
+
const unloading = /* @__PURE__ */ new Map();
|
|
27880
|
+
let closing;
|
|
27881
|
+
let settled;
|
|
27882
|
+
let keeper = false;
|
|
27883
|
+
const state = () => ({ ...identity, lease, instance: backend.instance, settings, threads: [...threads], ...settled ? { retained: settled } : {} });
|
|
27884
|
+
const owned = (id) => readPrivate(leaseFile(backend, id))?.lease === lease;
|
|
27885
|
+
const remove = (id) => {
|
|
27886
|
+
if (owned(id)) fs5.rmSync(leaseFile(backend, id), { force: true });
|
|
27887
|
+
};
|
|
27888
|
+
const claim = (id, loaded = true, previous) => {
|
|
27889
|
+
if (!id) return;
|
|
27890
|
+
const file = leaseFile(backend, id);
|
|
27891
|
+
const release = tryLock(file + ".lock");
|
|
27892
|
+
if (!release) throw Error("Codex thread ownership is being transferred. Try again.");
|
|
27893
|
+
try {
|
|
27894
|
+
const current = readPrivate(file);
|
|
27895
|
+
if (current && current.lease !== lease && current.lease !== previous?.lease) throw Error("Codex thread is already in use by another run.");
|
|
27896
|
+
if (loaded) threads.add(id);
|
|
27897
|
+
writePrivate(file, { ...state(), ...previous?.retained ? { retained: previous.retained, adopting: previous.lease } : {} });
|
|
27898
|
+
for (const thread of threads) {
|
|
27899
|
+
const owner = readPrivate(leaseFile(backend, thread));
|
|
27900
|
+
if (owner?.lease === lease) writePrivate(leaseFile(backend, thread), { ...owner, threads: [...threads] });
|
|
27901
|
+
}
|
|
27902
|
+
} finally {
|
|
27903
|
+
release();
|
|
27904
|
+
}
|
|
27905
|
+
};
|
|
27906
|
+
const reserve = async (id) => {
|
|
27907
|
+
const previous = readPrivate(leaseFile(backend, id));
|
|
27908
|
+
if (previous && previous.lease !== lease) {
|
|
27909
|
+
if (previous.retained) {
|
|
27910
|
+
if (previous.retained.root !== id) throw Error("Resume the owning Codex thread to adopt its retained work.");
|
|
27911
|
+
if (previous.settings !== settings) throw Error("This Codex version cannot change execution settings while retaining a loaded session. Its services and saved results were preserved; no new work was submitted.");
|
|
27912
|
+
const actual = [];
|
|
27913
|
+
for (const thread of previous.threads) actual.push(...await backgroundTerminals(connection.rpc, thread));
|
|
27914
|
+
const key = (value) => JSON.stringify([value.threadId, value.itemId, value.processId]);
|
|
27915
|
+
if (actual.length !== previous.retained.kept.length || actual.some((value) => !previous.retained.kept.some((item) => key(item) === key(value)))) throw Error("The retained Codex services changed; no new work was submitted.");
|
|
27916
|
+
} else {
|
|
27917
|
+
if (liveLease(previous)) throw Error("Codex thread is already in use by another run.");
|
|
27918
|
+
for (const thread of /* @__PURE__ */ new Set([id, ...previous.threads])) {
|
|
27919
|
+
const snapshot = obj((await connection.rpc.call("thread/read", { threadId: thread })).thread);
|
|
27920
|
+
if (obj(snapshot.status).type === "active" || (await backgroundTerminals(connection.rpc, thread).catch((error) => {
|
|
27921
|
+
if (error instanceof RpcError && /thread not found/i.test(error.message)) return [];
|
|
27922
|
+
throw error;
|
|
27923
|
+
})).length) throw Error("The previous Codex connection exited with work still running. Existing results were preserved; automatic replay was refused.");
|
|
27924
|
+
}
|
|
27925
|
+
}
|
|
27926
|
+
}
|
|
27927
|
+
claim(id, false, previous);
|
|
27928
|
+
preparing.set(id, (preparing.get(id) ?? 0) + 1);
|
|
27929
|
+
return { previous: previous?.retained ? previous : void 0, release() {
|
|
27930
|
+
const remaining = preparing.get(id) - 1;
|
|
27931
|
+
if (remaining) preparing.set(id, remaining);
|
|
27932
|
+
else {
|
|
27933
|
+
preparing.delete(id);
|
|
27934
|
+
if (!threads.has(id)) remove(id);
|
|
27935
|
+
}
|
|
27936
|
+
} };
|
|
27937
|
+
};
|
|
27938
|
+
const notify = (message) => {
|
|
27939
|
+
const params = obj(message.params), thread = obj(params.thread);
|
|
27940
|
+
const id = str(params.threadId) || str(thread.id);
|
|
27941
|
+
if (message.method === "thread/closed") {
|
|
27942
|
+
unloading.get(id)?.();
|
|
27943
|
+
unloading.delete(id);
|
|
27944
|
+
}
|
|
27945
|
+
if (!threads.has(id)) {
|
|
27946
|
+
const parent = str(thread.parentThreadId) || str(thread.forkedFromId);
|
|
27947
|
+
if (parent && threads.has(parent)) {
|
|
27948
|
+
try {
|
|
27949
|
+
claim(id);
|
|
27950
|
+
} catch (error) {
|
|
27951
|
+
send({ method: "error", params: { error: { message: String(error) } } });
|
|
27952
|
+
return;
|
|
27953
|
+
}
|
|
27954
|
+
}
|
|
27955
|
+
}
|
|
27956
|
+
if (!threads.has(id)) {
|
|
27957
|
+
if (message.id !== void 0) connection.rpc.refuse(message.id, "This execution does not own that Codex request.");
|
|
27958
|
+
return;
|
|
27959
|
+
}
|
|
27960
|
+
if (message.method === "turn/started") active.set(id, str(obj(params.turn).id));
|
|
27961
|
+
if (message.method === "turn/completed") active.delete(id);
|
|
27962
|
+
const item = obj(params.item);
|
|
27963
|
+
const children = item.type === "subAgentActivity" && item.kind === "started" ? [item.agentThreadId] : item.type === "collabAgentToolCall" && item.tool === "spawnAgent" && Array.isArray(item.receiverThreadIds) ? item.receiverThreadIds : [];
|
|
27964
|
+
for (const child of children) if (typeof child === "string" && !threads.has(child)) {
|
|
27708
27965
|
try {
|
|
27709
|
-
|
|
27710
|
-
if (answer.instance !== record.instance || answer.pid !== record.pid || answer.protocol !== CODEX_PROTOCOL || answer.generation !== accountGeneration()) throw Error("Codex service identity changed; existing work was preserved.");
|
|
27711
|
-
clearTimeout(timer);
|
|
27712
|
-
socket2.removeListener("data", hello);
|
|
27713
|
-
socket2.removeListener("error", fail);
|
|
27714
|
-
socket2.on("error", () => {
|
|
27715
|
-
});
|
|
27716
|
-
resolve(socket2);
|
|
27966
|
+
claim(child);
|
|
27717
27967
|
} catch (error) {
|
|
27718
|
-
|
|
27968
|
+
send({ method: "error", params: { error: { message: String(error) } } });
|
|
27969
|
+
return;
|
|
27719
27970
|
}
|
|
27720
|
-
});
|
|
27721
|
-
socket2.once("end", () => fail(Error("Codex service refused this Runner.")));
|
|
27722
|
-
});
|
|
27723
|
-
}
|
|
27724
|
-
async function openService() {
|
|
27725
|
-
const until = Date.now() + 1e4;
|
|
27726
|
-
let socket2;
|
|
27727
|
-
for (; ; ) {
|
|
27728
|
-
const release = tryLock(path7.join(runnerCwd(), "codex-service-v2.start.lock"));
|
|
27729
|
-
if (!release) {
|
|
27730
|
-
if (Date.now() >= until) throw Error("Codex service startup is busy.");
|
|
27731
|
-
await wait(50);
|
|
27732
|
-
continue;
|
|
27733
27971
|
}
|
|
27972
|
+
if (message.id !== void 0) requests.add(String(message.id));
|
|
27973
|
+
send(message);
|
|
27974
|
+
};
|
|
27975
|
+
const connection = await nativeConnection(backend, notify);
|
|
27976
|
+
let initialized;
|
|
27977
|
+
try {
|
|
27978
|
+
initialized = await initializeNative(connection);
|
|
27979
|
+
} catch (error) {
|
|
27980
|
+
connection.close();
|
|
27981
|
+
throw error;
|
|
27982
|
+
}
|
|
27983
|
+
const keep = async () => {
|
|
27984
|
+
const entry = process.env.RUNNER_DIST ? path6.join(process.env.RUNNER_DIST, "codex-retained.mjs") : fileURLToPath(new URL("./codex-retained.mjs", import.meta.url));
|
|
27985
|
+
const child = spawn(process.execPath, [entry, backendFile(backend.key), leaseFile(backend, settled.root), lease], {
|
|
27986
|
+
cwd,
|
|
27987
|
+
env: { ...environment, WILDCRANE_CODEX_GENERATION: backend.generation },
|
|
27988
|
+
detached: process.platform !== "win32",
|
|
27989
|
+
stdio: ["ignore", "ignore", "ignore", "ipc"]
|
|
27990
|
+
});
|
|
27991
|
+
child.on("error", () => {
|
|
27992
|
+
});
|
|
27734
27993
|
try {
|
|
27735
|
-
|
|
27736
|
-
|
|
27994
|
+
await bounded(new Promise((resolve, reject) => {
|
|
27995
|
+
child.once("error", reject);
|
|
27996
|
+
child.once("exit", () => reject(Error("Codex retained execution exited before connecting.")));
|
|
27997
|
+
child.on("message", (value) => {
|
|
27998
|
+
if (obj(value).ready === lease) resolve();
|
|
27999
|
+
});
|
|
28000
|
+
}), CODEX_TIMEOUT, "Codex retained execution did not acknowledge ownership.");
|
|
28001
|
+
keeper = true;
|
|
28002
|
+
child.disconnect();
|
|
28003
|
+
child.unref();
|
|
28004
|
+
} catch (error) {
|
|
28005
|
+
child.kill("SIGTERM");
|
|
28006
|
+
throw error;
|
|
28007
|
+
}
|
|
28008
|
+
};
|
|
28009
|
+
const cleanup = async () => {
|
|
28010
|
+
await Promise.allSettled(pending);
|
|
28011
|
+
if (keeper) return;
|
|
28012
|
+
for (const id of requests) connection.rpc.refuse(id, "Execution disconnected.");
|
|
28013
|
+
for (const id of threads) {
|
|
28014
|
+
if (!owned(id)) continue;
|
|
28015
|
+
if (!settled) {
|
|
28016
|
+
if (active.has(id)) await connection.rpc.call("turn/interrupt", { threadId: id, turnId: active.get(id) });
|
|
27737
28017
|
try {
|
|
27738
|
-
|
|
28018
|
+
await connection.rpc.call("thread/backgroundTerminals/clean", { threadId: id });
|
|
27739
28019
|
} catch (error) {
|
|
27740
|
-
if (
|
|
27741
|
-
fs5.rmSync(codexRecordFile(), { force: true });
|
|
28020
|
+
if (!(error instanceof RpcError) || ![-32601].includes(error.code) && !/thread not found/i.test(error.message)) throw error;
|
|
27742
28021
|
}
|
|
27743
28022
|
}
|
|
27744
|
-
|
|
27745
|
-
|
|
27746
|
-
|
|
27747
|
-
|
|
27748
|
-
|
|
27749
|
-
|
|
27750
|
-
|
|
27751
|
-
|
|
27752
|
-
|
|
27753
|
-
|
|
27754
|
-
|
|
27755
|
-
|
|
27756
|
-
|
|
27757
|
-
|
|
27758
|
-
|
|
27759
|
-
|
|
27760
|
-
|
|
27761
|
-
|
|
27762
|
-
|
|
27763
|
-
|
|
27764
|
-
|
|
27765
|
-
|
|
28023
|
+
const unloaded = new Promise((resolve) => unloading.set(id, resolve));
|
|
28024
|
+
const result = await connection.rpc.call("thread/unsubscribe", { threadId: id });
|
|
28025
|
+
if (result.status === "unsubscribed") await unloaded;
|
|
28026
|
+
unloading.delete(id);
|
|
28027
|
+
remove(id);
|
|
28028
|
+
}
|
|
28029
|
+
};
|
|
28030
|
+
const close = () => closing ??= (async () => {
|
|
28031
|
+
try {
|
|
28032
|
+
await bounded(cleanup(), CODEX_TIMEOUT, "Codex thread cleanup timed out; ownership remains unconfirmed.");
|
|
28033
|
+
} catch (error) {
|
|
28034
|
+
for (const id of threads) if (owned(id)) writePrivate(leaseFile(backend, id), { ...state(), uncertain: true });
|
|
28035
|
+
send({ method: "wildcrane/cleanup", params: { status: "unconfirmed", lease } });
|
|
28036
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
28037
|
+
} finally {
|
|
28038
|
+
connection.close();
|
|
28039
|
+
}
|
|
28040
|
+
})();
|
|
28041
|
+
const request = async (message) => {
|
|
28042
|
+
const id = message.id;
|
|
28043
|
+
let source, previous;
|
|
28044
|
+
let releaseSource;
|
|
28045
|
+
try {
|
|
28046
|
+
if (message.method === "wildcrane/release") {
|
|
28047
|
+
void close();
|
|
28048
|
+
return;
|
|
28049
|
+
}
|
|
28050
|
+
if (!message.method) {
|
|
28051
|
+
if (id === void 0 || !requests.delete(String(id))) return;
|
|
28052
|
+
if (message.error) connection.rpc.refuse(id, message.error.message ?? "Interaction refused.");
|
|
28053
|
+
else connection.rpc.reply(id, obj(message.result));
|
|
28054
|
+
return;
|
|
28055
|
+
}
|
|
28056
|
+
if (closing) throw Error("Codex execution is stopping.");
|
|
28057
|
+
if (keeper) throw Error("Codex execution already handed off its retained services.");
|
|
28058
|
+
if (message.method === "initialize") {
|
|
28059
|
+
send({ id, result: { ...initialized, wildcrane: { instance: backend.instance, lease } } });
|
|
28060
|
+
return;
|
|
28061
|
+
}
|
|
28062
|
+
if (message.method === "initialized") return;
|
|
28063
|
+
let params = obj(message.params);
|
|
28064
|
+
if (message.method === "wildcrane/settled") {
|
|
28065
|
+
if (params.instance !== backend.instance || params.lease !== lease || !threads.has(str(params.threadId)) || params.confirmed !== true || !str(params.execution)) throw Error("Codex cleanup ownership is unconfirmed.");
|
|
28066
|
+
const kept = Array.isArray(params.kept) ? params.kept.map(obj) : [];
|
|
28067
|
+
const actual = [];
|
|
28068
|
+
for (const thread2 of threads) {
|
|
28069
|
+
if (active.has(thread2)) throw Error("A Codex turn is still active.");
|
|
28070
|
+
actual.push(...await backgroundTerminals(connection.rpc, thread2));
|
|
28071
|
+
}
|
|
28072
|
+
const key = (value) => JSON.stringify([value.threadId, value.itemId, value.processId]);
|
|
28073
|
+
if (new Set(kept.map(key)).size !== kept.length || actual.length !== kept.length || actual.some((value) => !kept.some((item) => key(item) === key(value)))) throw Error("Codex retained terminal state changed before handoff.");
|
|
28074
|
+
settled = { root: str(params.threadId), execution: str(params.execution), kept };
|
|
28075
|
+
for (const thread2 of threads) writePrivate(leaseFile(backend, thread2), state());
|
|
28076
|
+
if (kept.length) await keep();
|
|
28077
|
+
send({ id, result: { confirmed: true, instance: backend.instance, lease } });
|
|
28078
|
+
return;
|
|
28079
|
+
}
|
|
28080
|
+
if (["thread/start", "thread/resume", "thread/fork"].includes(message.method)) {
|
|
28081
|
+
if (message.method !== "thread/start") {
|
|
28082
|
+
const id2 = str(params.threadId);
|
|
28083
|
+
if (message.method !== "thread/fork" || !readPrivate(leaseFile(backend, id2))?.retained) {
|
|
28084
|
+
source = id2;
|
|
28085
|
+
const reservation = await reserve(source);
|
|
28086
|
+
previous = reservation.previous;
|
|
28087
|
+
releaseSource = reservation.release;
|
|
27766
28088
|
}
|
|
27767
|
-
if (child.exitCode !== null || Date.now() >= until) throw Error("Codex service failed to start; inspect codex-service.log.");
|
|
27768
|
-
await wait(50);
|
|
27769
28089
|
}
|
|
27770
|
-
|
|
27771
|
-
|
|
28090
|
+
const defaults = await connection.rpc.call("config/read", { cwd: params.cwd ?? cwd, includeLayers: false });
|
|
28091
|
+
const overrides = { ...config, ...obj(params.config), thread_unload_delay_secs: 0 };
|
|
28092
|
+
mcpEnvironment(overrides, obj(obj(defaults.config).mcp_servers));
|
|
28093
|
+
params = { ...params, cwd: params.cwd ?? cwd, config: overrides };
|
|
28094
|
+
} else {
|
|
28095
|
+
const thread2 = str(params.threadId);
|
|
28096
|
+
if (!threads.has(thread2) || !owned(thread2)) throw Error("This run does not own that Codex thread.");
|
|
28097
|
+
}
|
|
28098
|
+
if (message.method === "turn/start") settled = void 0;
|
|
28099
|
+
const result = await connection.rpc.call(message.method, params);
|
|
28100
|
+
if (message.method === "thread/resume" && !previous?.retained && str(config.model) && result.model && result.model !== config.model) throw Error("The previous Codex runtime has not unloaded; new execution settings were not applied. No new work was submitted.");
|
|
28101
|
+
const thread = str(obj(result.thread).id);
|
|
28102
|
+
if (thread) claim(thread, true, message.method === "thread/resume" ? previous : void 0);
|
|
28103
|
+
if (previous?.retained && message.method === "thread/resume") {
|
|
28104
|
+
for (const child of previous.threads) if (child !== thread) {
|
|
28105
|
+
claim(child, true, previous);
|
|
28106
|
+
await connection.rpc.call("thread/resume", { threadId: child });
|
|
28107
|
+
writePrivate(leaseFile(backend, child), state());
|
|
28108
|
+
}
|
|
28109
|
+
result.retainedThreads = [...threads].map((id2) => ({ id: id2 }));
|
|
28110
|
+
writePrivate(leaseFile(backend, thread), state());
|
|
28111
|
+
}
|
|
28112
|
+
if (id !== void 0) send({ id, result });
|
|
28113
|
+
} catch (error) {
|
|
28114
|
+
if (source && previous?.retained) for (const thread of previous.threads) {
|
|
28115
|
+
if (owned(thread)) writePrivate(leaseFile(backend, thread), previous);
|
|
28116
|
+
threads.delete(thread);
|
|
28117
|
+
}
|
|
28118
|
+
if (id !== void 0) send({ id, error: { code: error instanceof RpcError ? error.code : -32e3, message: error instanceof Error ? error.message : String(error) } });
|
|
27772
28119
|
} finally {
|
|
27773
|
-
|
|
28120
|
+
releaseSource?.();
|
|
27774
28121
|
}
|
|
28122
|
+
};
|
|
28123
|
+
return { close, closed: connection.incoming, request(message) {
|
|
28124
|
+
const work = request(message);
|
|
28125
|
+
pending.add(work);
|
|
28126
|
+
void work.finally(() => pending.delete(work));
|
|
28127
|
+
} };
|
|
28128
|
+
}
|
|
28129
|
+
|
|
28130
|
+
// src/codex-server.ts
|
|
28131
|
+
import net from "node:net";
|
|
28132
|
+
|
|
28133
|
+
// ../cli/src/lib/agent/stop.ts
|
|
28134
|
+
var WINDOWS = process.platform === "win32";
|
|
28135
|
+
var LIST_PROCS = [
|
|
28136
|
+
"$ErrorActionPreference = 'Stop'",
|
|
28137
|
+
"Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }",
|
|
28138
|
+
"'boot {0}' -f ([DateTimeOffset](Get-CimInstance Win32_OperatingSystem).LastBootUpTime).ToUnixTimeMilliseconds()"
|
|
28139
|
+
].join("; ");
|
|
28140
|
+
|
|
28141
|
+
// src/settings-control.ts
|
|
28142
|
+
import fs6 from "node:fs";
|
|
28143
|
+
import path7 from "node:path";
|
|
28144
|
+
var directory = () => path7.join(runnerHome(), "executors");
|
|
28145
|
+
var epochFile = () => path7.join(runnerHome(), "account-generation");
|
|
28146
|
+
function accountGeneration() {
|
|
28147
|
+
try {
|
|
28148
|
+
return fs6.readFileSync(epochFile(), "utf8");
|
|
28149
|
+
} catch {
|
|
28150
|
+
return "";
|
|
27775
28151
|
}
|
|
27776
28152
|
}
|
|
27777
|
-
|
|
27778
|
-
|
|
27779
|
-
|
|
27780
|
-
|
|
27781
|
-
|
|
27782
|
-
|
|
27783
|
-
|
|
27784
|
-
|
|
27785
|
-
|
|
27786
|
-
|
|
27787
|
-
|
|
27788
|
-
|
|
27789
|
-
|
|
27790
|
-
|
|
27791
|
-
|
|
27792
|
-
|
|
27793
|
-
|
|
27794
|
-
|
|
27795
|
-
|
|
27796
|
-
|
|
27797
|
-
|
|
27798
|
-
|
|
28153
|
+
function executorRecord() {
|
|
28154
|
+
fs6.mkdirSync(directory(), { recursive: true, mode: 448 });
|
|
28155
|
+
const file = path7.join(directory(), `${process.pid}.json`);
|
|
28156
|
+
fs6.writeFileSync(file, "{}", { mode: 384 });
|
|
28157
|
+
return () => fs6.rmSync(file, { force: true });
|
|
28158
|
+
}
|
|
28159
|
+
|
|
28160
|
+
// src/codex-server.ts
|
|
28161
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28162
|
+
async function requestCodexBackend(argv, env) {
|
|
28163
|
+
const until = Date.now() + CODEX_TIMEOUT;
|
|
28164
|
+
for (; ; ) {
|
|
28165
|
+
const record = readPrivate(codexRecordFile());
|
|
28166
|
+
if (record && record.generation === accountGeneration()) {
|
|
28167
|
+
try {
|
|
28168
|
+
return await bounded(new Promise((resolve, reject) => {
|
|
28169
|
+
const socket = net.connect(record.path);
|
|
28170
|
+
let text = "";
|
|
28171
|
+
socket.on("error", reject);
|
|
28172
|
+
socket.once("connect", () => socket.write(JSON.stringify({ token: record.token, protocol: CODEX_PROTOCOL, generation: accountGeneration(), argv, env }) + "\n"));
|
|
28173
|
+
socket.on("data", (chunk) => {
|
|
28174
|
+
text += chunk;
|
|
28175
|
+
if (!text.includes("\n")) return;
|
|
28176
|
+
try {
|
|
28177
|
+
const answer = JSON.parse(text.split("\n")[0]);
|
|
28178
|
+
socket.destroy();
|
|
28179
|
+
answer.error ? reject(Error(answer.error)) : resolve({ backend: answer.backend, config: obj(answer.config) });
|
|
28180
|
+
} catch (error) {
|
|
28181
|
+
reject(error);
|
|
28182
|
+
}
|
|
28183
|
+
});
|
|
28184
|
+
socket.once("end", () => {
|
|
28185
|
+
if (!text.includes("\n")) reject(Error("Codex Runner closed during backend preparation."));
|
|
28186
|
+
});
|
|
28187
|
+
socket.setTimeout(Math.max(1, until - Date.now()), () => {
|
|
28188
|
+
socket.destroy();
|
|
28189
|
+
reject(Error("Codex Runner preparation timed out."));
|
|
28190
|
+
});
|
|
28191
|
+
}), Math.max(1, until - Date.now()), "Codex Runner preparation timed out.");
|
|
28192
|
+
} catch (error) {
|
|
28193
|
+
if (Date.now() >= until || !/ENOENT|ECONNREFUSED|closed during/.test(String(error))) throw error;
|
|
27799
28194
|
}
|
|
27800
|
-
if (!closed && generation === accountGeneration()) console.error("runner: Codex service recovery failed; existing task progress was preserved.");
|
|
27801
|
-
})();
|
|
27802
|
-
});
|
|
27803
|
-
watch();
|
|
27804
|
-
return {
|
|
27805
|
-
env: { WILDCRANE_CODEX_SERVER: codexRecordFile(), WILDCRANE_CODEX_GENERATION: generation, WILDCRANE_CODEX_PROXY: entryOf("codex-proxy.mjs") },
|
|
27806
|
-
async close() {
|
|
27807
|
-
closed = true;
|
|
27808
|
-
socket2.destroy();
|
|
27809
|
-
await recovering;
|
|
27810
|
-
},
|
|
27811
|
-
async shutdown() {
|
|
27812
|
-
closed = true;
|
|
27813
|
-
socket2.write(JSON.stringify({ method: "shutdown" }) + "\n");
|
|
27814
28195
|
}
|
|
27815
|
-
|
|
28196
|
+
if (Date.now() >= until) throw Error("No active Runner could prepare Codex. Existing work was preserved.");
|
|
28197
|
+
await delay(50);
|
|
28198
|
+
}
|
|
27816
28199
|
}
|
|
27817
28200
|
|
|
27818
28201
|
// src/codex-proxy.ts
|
|
27819
|
-
|
|
27820
|
-
|
|
27821
|
-
|
|
27822
|
-
|
|
27823
|
-
|
|
27824
|
-
|
|
27825
|
-
|
|
27826
|
-
|
|
27827
|
-
|
|
27828
|
-
|
|
27829
|
-
|
|
27830
|
-
|
|
27831
|
-
|
|
27832
|
-
|
|
27833
|
-
}
|
|
27834
|
-
|
|
27835
|
-
|
|
27836
|
-
|
|
28202
|
+
async function proxy() {
|
|
28203
|
+
const generation = accountGeneration();
|
|
28204
|
+
if (process.env.WILDCRANE_CODEX_GENERATION !== void 0 && process.env.WILDCRANE_CODEX_GENERATION !== generation) throw Error("Codex task belongs to an expired account session.");
|
|
28205
|
+
const release = executorRecord();
|
|
28206
|
+
const input = createInterface({ input: process.stdin });
|
|
28207
|
+
const queued = [];
|
|
28208
|
+
let execution;
|
|
28209
|
+
let ending = false;
|
|
28210
|
+
const send = (message) => {
|
|
28211
|
+
if (!process.stdout.destroyed) process.stdout.write(JSON.stringify(message) + "\n");
|
|
28212
|
+
};
|
|
28213
|
+
const receive = (line) => {
|
|
28214
|
+
try {
|
|
28215
|
+
execution.request(JSON.parse(line));
|
|
28216
|
+
} catch {
|
|
28217
|
+
send({ method: "error", params: { error: { message: "Invalid Codex request." } } });
|
|
28218
|
+
}
|
|
28219
|
+
};
|
|
28220
|
+
const close = async () => {
|
|
28221
|
+
if (ending) return;
|
|
28222
|
+
ending = true;
|
|
28223
|
+
await execution?.close();
|
|
28224
|
+
input.close();
|
|
28225
|
+
process.stdin.destroy();
|
|
28226
|
+
};
|
|
28227
|
+
process.stdout.on("error", () => {
|
|
28228
|
+
void close();
|
|
28229
|
+
});
|
|
28230
|
+
input.on("line", (line) => execution ? receive(line) : queued.push(line));
|
|
28231
|
+
input.on("close", () => {
|
|
28232
|
+
void close();
|
|
28233
|
+
});
|
|
28234
|
+
for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => {
|
|
28235
|
+
void close();
|
|
28236
|
+
});
|
|
28237
|
+
const timer = setInterval(() => {
|
|
28238
|
+
if (generation !== accountGeneration()) void close();
|
|
28239
|
+
}, 200);
|
|
28240
|
+
timer.unref();
|
|
28241
|
+
try {
|
|
28242
|
+
const argv = process.argv.slice(2);
|
|
28243
|
+
const prepared = await requestCodexBackend(argv, process.env);
|
|
28244
|
+
execution = await codexExecution(prepared.backend, prepared.config, process.env, process.cwd(), send);
|
|
28245
|
+
execution.closed.once("close", () => {
|
|
28246
|
+
void close();
|
|
28247
|
+
});
|
|
28248
|
+
if (ending) await execution.close();
|
|
28249
|
+
else for (const line of queued) receive(line);
|
|
28250
|
+
if (!execution.closed.destroyed) await new Promise((resolve) => execution.closed.once("close", resolve));
|
|
28251
|
+
} finally {
|
|
28252
|
+
clearInterval(timer);
|
|
28253
|
+
await execution?.close();
|
|
28254
|
+
release();
|
|
28255
|
+
input.close();
|
|
28256
|
+
process.stdin.destroy();
|
|
28257
|
+
}
|
|
28258
|
+
}
|
|
28259
|
+
void proxy().catch((error) => {
|
|
28260
|
+
process.stdout.write(JSON.stringify({ method: "error", params: { error: { message: error instanceof Error ? error.message : String(error) } } }) + "\n");
|
|
27837
28261
|
process.exitCode = 1;
|
|
27838
|
-
input.close();
|
|
27839
|
-
process.stdin.destroy();
|
|
27840
28262
|
});
|
|
27841
|
-
socket.on("close", () => {
|
|
27842
|
-
input.close();
|
|
27843
|
-
process.stdin.destroy();
|
|
27844
|
-
void owner.close();
|
|
27845
|
-
});
|
|
27846
|
-
var close = () => {
|
|
27847
|
-
if (closing) return;
|
|
27848
|
-
closing = true;
|
|
27849
|
-
void owner.close();
|
|
27850
|
-
const timer = setTimeout(() => socket.destroy(), 12e3);
|
|
27851
|
-
timer.unref();
|
|
27852
|
-
socket.once("close", () => clearTimeout(timer));
|
|
27853
|
-
if (ready) send(JSON.stringify({ method: "wildcrane/release" }));
|
|
27854
|
-
else socket.destroy();
|
|
27855
|
-
input.close();
|
|
27856
|
-
process.stdin.destroy();
|
|
27857
|
-
};
|
|
27858
|
-
input.on("close", close);
|
|
27859
|
-
process.on("SIGTERM", close);
|
|
27860
|
-
process.on("SIGINT", close);
|