UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1,047 lines (1,046 loc) • 27.8 kB
import { a as __require, o as __toCommonJS, t as __commonJSMin } from "./rolldown-runtime-C_OpTf0N.mjs"; import { n as supports_color_exports, r as require_ms, t as init_supports_color } from "./supports-color-2qbB2Dti.mjs"; //#region node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/common.js var require_common = /* @__PURE__ */ __commonJSMin(((e, t) => { /** * This is the common logic for both the Node.js and web browser * implementations of `debug()`. */ function setup(e) { createDebug.debug = createDebug; createDebug.default = createDebug; createDebug.coerce = coerce; createDebug.disable = disable; createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require_ms(); createDebug.destroy = destroy; Object.keys(e).forEach((t) => { createDebug[t] = e[t]; }); /** * The currently active debug mode names, and names to skip. */ createDebug.names = []; createDebug.skips = []; /** * Map of special "%n" handling functions, for the debug "format" argument. * * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". */ createDebug.formatters = {}; /** * Selects a color for a debug namespace * @param {String} namespace The namespace string for the debug instance to be colored * @return {Number|String} An ANSI color code for the given namespace * @api private */ function selectColor(e) { let t = 0; for (let n = 0; n < e.length; n++) { t = (t << 5) - t + e.charCodeAt(n); t |= 0; } return createDebug.colors[Math.abs(t) % createDebug.colors.length]; } createDebug.selectColor = selectColor; /** * Create a debugger with the given `namespace`. * * @param {String} namespace * @return {Function} * @api public */ function createDebug(e) { let t; let n = null; let r; let i; function debug(...e) { if (!debug.enabled) return; const n = debug; const r = Number(/* @__PURE__ */ new Date()); n.diff = r - (t || r); n.prev = t; n.curr = r; t = r; e[0] = createDebug.coerce(e[0]); if (typeof e[0] !== "string") e.unshift("%O"); let i = 0; e[0] = e[0].replace(/%([a-zA-Z%])/g, (t, r) => { if (t === "%%") return "%"; i++; const a = createDebug.formatters[r]; if (typeof a === "function") { const r = e[i]; t = a.call(n, r); e.splice(i, 1); i--; } return t; }); createDebug.formatArgs.call(n, e); (n.log || createDebug.log).apply(n, e); } debug.namespace = e; debug.useColors = createDebug.useColors(); debug.color = createDebug.selectColor(e); debug.extend = extend; debug.destroy = createDebug.destroy; Object.defineProperty(debug, "enabled", { enumerable: true, configurable: false, get: () => { if (n !== null) return n; if (r !== createDebug.namespaces) { r = createDebug.namespaces; i = createDebug.enabled(e); } return i; }, set: (e) => { n = e; } }); if (typeof createDebug.init === "function") createDebug.init(debug); return debug; } function extend(e, t) { const n = createDebug(this.namespace + (typeof t === "undefined" ? ":" : t) + e); n.log = this.log; return n; } /** * Enables a debug mode by namespaces. This can include modes * separated by a colon and wildcards. * * @param {String} namespaces * @api public */ function enable(e) { createDebug.save(e); createDebug.namespaces = e; createDebug.names = []; createDebug.skips = []; const t = (typeof e === "string" ? e : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean); for (const e of t) if (e[0] === "-") createDebug.skips.push(e.slice(1)); else createDebug.names.push(e); } /** * Checks if the given string matches a namespace template, honoring * asterisks as wildcards. * * @param {String} search * @param {String} template * @return {Boolean} */ function matchesTemplate(e, t) { let n = 0; let r = 0; let i = -1; let a = 0; while (n < e.length) if (r < t.length && (t[r] === e[n] || t[r] === "*")) { if (t[r] === "*") { i = r; a = n; r++; } else { n++; r++; } } else if (i !== -1) { r = i + 1; a++; n = a; } else return false; while (r < t.length && t[r] === "*") r++; return r === t.length; } /** * Disable debug output. * * @return {String} namespaces * @api public */ function disable() { const e = [...createDebug.names, ...createDebug.skips.map((e) => "-" + e)].join(","); createDebug.enable(""); return e; } /** * Returns true if the given mode name is enabled, false otherwise. * * @param {String} name * @return {Boolean} * @api public */ function enabled(e) { for (const t of createDebug.skips) if (matchesTemplate(e, t)) return false; for (const t of createDebug.names) if (matchesTemplate(e, t)) return true; return false; } /** * Coerce `val`. * * @param {Mixed} val * @return {Mixed} * @api private */ function coerce(e) { if (e instanceof Error) return e.stack || e.message; return e; } /** * XXX DO NOT USE. This is a temporary stub function. * XXX It WILL be removed in the next major release. */ function destroy() { console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); } createDebug.enable(createDebug.load()); return createDebug; } t.exports = setup; })); //#endregion //#region node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/browser.js var require_browser = /* @__PURE__ */ __commonJSMin(((e, t) => { /** * This is the web browser implementation of `debug()`. */ e.formatArgs = formatArgs; e.save = save; e.load = load; e.useColors = useColors; e.storage = localstorage(); e.destroy = (() => { let e = false; return () => { if (!e) { e = true; console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); } }; })(); /** * Colors. */ e.colors = [ "#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33" ]; /** * Currently only WebKit-based Web Inspectors, Firefox >= v31, * and the Firebug extension (any Firefox version) are known * to support "%c" CSS customizations. * * TODO: add a `localStorage` variable to explicitly enable/disable colors */ function useColors() { if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true; if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false; let e; return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (e = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(e[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); } /** * Colorize log arguments if enabled. * * @api public */ function formatArgs(e) { e[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + e[0] + (this.useColors ? "%c " : " ") + "+" + t.exports.humanize(this.diff); if (!this.useColors) return; const n = "color: " + this.color; e.splice(1, 0, n, "color: inherit"); let r = 0; let i = 0; e[0].replace(/%[a-zA-Z%]/g, (e) => { if (e === "%%") return; r++; if (e === "%c") i = r; }); e.splice(i, 0, n); } /** * Invokes `console.debug()` when available. * No-op when `console.debug` is not a "function". * If `console.debug` is not available, falls back * to `console.log`. * * @api public */ e.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. * * @param {String} namespaces * @api private */ function save(t) { try { if (t) e.storage.setItem("debug", t); else e.storage.removeItem("debug"); } catch (e) {} } /** * Load `namespaces`. * * @return {String} returns the previously persisted debug modes * @api private */ function load() { let t; try { t = e.storage.getItem("debug") || e.storage.getItem("DEBUG"); } catch (e) {} if (!t && typeof process !== "undefined" && "env" in process) t = process.env.DEBUG; return t; } /** * Localstorage attempts to return the localstorage. * * This is necessary because safari throws * when a user disables cookies/localstorage * and you attempt to access it. * * @return {LocalStorage} * @api private */ function localstorage() { try { return localStorage; } catch (e) {} } t.exports = require_common()(e); const { formatters: n } = t.exports; /** * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. */ n.j = function(e) { try { return JSON.stringify(e); } catch (e) { return "[UnexpectedJSONParseError]: " + e.message; } }; })); //#endregion //#region node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/node.js var require_node = /* @__PURE__ */ __commonJSMin(((e, t) => { /** * Module dependencies. */ const n = __require("tty"); const r = __require("util"); /** * This is the Node.js implementation of `debug()`. */ e.init = init; e.log = log; e.formatArgs = formatArgs; e.save = save; e.load = load; e.useColors = useColors; e.destroy = r.deprecate(() => {}, "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); /** * Colors. */ e.colors = [ 6, 2, 3, 4, 5, 1 ]; try { const t = (init_supports_color(), __toCommonJS(supports_color_exports)); if (t && (t.stderr || t).level >= 2) e.colors = [ 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221 ]; } catch (e) {} /** * Build up the default `inspectOpts` object from the environment variables. * * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js */ e.inspectOpts = Object.keys(process.env).filter((e) => { return /^debug_/i.test(e); }).reduce((e, t) => { const n = t.substring(6).toLowerCase().replace(/_([a-z])/g, (e, t) => { return t.toUpperCase(); }); let r = process.env[t]; if (/^(yes|on|true|enabled)$/i.test(r)) r = true; else if (/^(no|off|false|disabled)$/i.test(r)) r = false; else if (r === "null") r = null; else r = Number(r); e[n] = r; return e; }, {}); /** * Is stdout a TTY? Colored output is enabled when `true`. */ function useColors() { return "colors" in e.inspectOpts ? Boolean(e.inspectOpts.colors) : n.isatty(process.stderr.fd); } /** * Adds ANSI color escape codes if enabled. * * @api public */ function formatArgs(e) { const { namespace: n, useColors: r } = this; if (r) { const r = this.color; const i = "\x1B[3" + (r < 8 ? r : "8;5;" + r); const a = ` ${i};1m${n} \u001B[0m`; e[0] = a + e[0].split("\n").join("\n" + a); e.push(i + "m+" + t.exports.humanize(this.diff) + "\x1B[0m"); } else e[0] = getDate() + n + " " + e[0]; } function getDate() { if (e.inspectOpts.hideDate) return ""; return (/* @__PURE__ */ new Date()).toISOString() + " "; } /** * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr. */ function log(...t) { return process.stderr.write(r.formatWithOptions(e.inspectOpts, ...t) + "\n"); } /** * Save `namespaces`. * * @param {String} namespaces * @api private */ function save(e) { if (e) process.env.DEBUG = e; else delete process.env.DEBUG; } /** * Load `namespaces`. * * @return {String} returns the previously persisted debug modes * @api private */ function load() { return process.env.DEBUG; } /** * Init logic for `debug` instances. * * Create a new `inspectOpts` object in case `useColors` is set * differently for a particular `debug` instance. */ function init(t) { t.inspectOpts = {}; const n = Object.keys(e.inspectOpts); for (let r = 0; r < n.length; r++) t.inspectOpts[n[r]] = e.inspectOpts[n[r]]; } t.exports = require_common()(e); const { formatters: i } = t.exports; /** * Map %o to `util.inspect()`, all on a single line. */ i.o = function(e) { this.inspectOpts.colors = this.useColors; return r.inspect(e, this.inspectOpts).split("\n").map((e) => e.trim()).join(" "); }; /** * Map %O to `util.inspect()`, allowing multiple lines if needed. */ i.O = function(e) { this.inspectOpts.colors = this.useColors; return r.inspect(e, this.inspectOpts); }; })); //#endregion //#region node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/index.js var require_src = /* @__PURE__ */ __commonJSMin(((e, t) => { /** * Detect Electron renderer / nwjs process, which is node, but we should * treat as a browser. */ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) t.exports = require_browser(); else t.exports = require_node(); })); //#endregion //#region node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/helpers.js var require_helpers = /* @__PURE__ */ __commonJSMin(((e, t, n) => { var r = n && n.__createBinding || (Object.create ? (function(e, t, n, r) { if (r === void 0) r = n; var i = Object.getOwnPropertyDescriptor(t, n); if (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) i = { enumerable: true, get: function() { return t[n]; } }; Object.defineProperty(e, r, i); }) : (function(e, t, n, r) { if (r === void 0) r = n; e[r] = t[n]; })); var i = n && n.__setModuleDefault || (Object.create ? (function(e, t) { Object.defineProperty(e, "default", { enumerable: true, value: t }); }) : function(e, t) { e["default"] = t; }); var a = n && n.__importStar || function(e) { if (e && e.__esModule) return e; var t = {}; if (e != null) { for (var n in e) if (n !== "default" && Object.prototype.hasOwnProperty.call(e, n)) r(t, e, n); } i(t, e); return t; }; Object.defineProperty(e, "__esModule", { value: true }); e.req = e.json = e.toBuffer = void 0; const o = a(__require("http")); const s = a(__require("https")); async function toBuffer(e) { let t = 0; const n = []; for await (const r of e) { t += r.length; n.push(r); } return Buffer.concat(n, t); } e.toBuffer = toBuffer; async function json(e) { const t = (await toBuffer(e)).toString("utf8"); try { return JSON.parse(t); } catch (e) { const n = e; n.message += ` (input: ${t})`; throw n; } } e.json = json; function req(e, t = {}) { const n = ((typeof e === "string" ? e : e.href).startsWith("https:") ? s : o).request(e, t); const r = new Promise((e, t) => { n.once("response", e).once("error", t).end(); }); n.then = r.then.bind(r); return n; } e.req = req; })); //#endregion //#region node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/index.js var require_dist$1 = /* @__PURE__ */ __commonJSMin(((e, t, n) => { var r = n && n.__createBinding || (Object.create ? (function(e, t, n, r) { if (r === void 0) r = n; var i = Object.getOwnPropertyDescriptor(t, n); if (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) i = { enumerable: true, get: function() { return t[n]; } }; Object.defineProperty(e, r, i); }) : (function(e, t, n, r) { if (r === void 0) r = n; e[r] = t[n]; })); var i = n && n.__setModuleDefault || (Object.create ? (function(e, t) { Object.defineProperty(e, "default", { enumerable: true, value: t }); }) : function(e, t) { e["default"] = t; }); var a = n && n.__importStar || function(e) { if (e && e.__esModule) return e; var t = {}; if (e != null) { for (var n in e) if (n !== "default" && Object.prototype.hasOwnProperty.call(e, n)) r(t, e, n); } i(t, e); return t; }; var o = n && n.__exportStar || function(e, t) { for (var n in e) if (n !== "default" && !Object.prototype.hasOwnProperty.call(t, n)) r(t, e, n); }; Object.defineProperty(e, "__esModule", { value: true }); e.Agent = void 0; const s = a(__require("net")); const c = a(__require("http")); const l = __require("https"); o(require_helpers(), e); const u = Symbol("AgentBaseInternalState"); var Agent = class extends c.Agent { constructor(e) { super(e); this[u] = {}; } /** * Determine whether this is an `http` or `https` request. */ isSecureEndpoint(e) { if (e) { if (typeof e.secureEndpoint === "boolean") return e.secureEndpoint; if (typeof e.protocol === "string") return e.protocol === "https:"; } const { stack: t } = /* @__PURE__ */ new Error(); if (typeof t !== "string") return false; return t.split("\n").some((e) => e.indexOf("(https.js:") !== -1 || e.indexOf("node:https:") !== -1); } incrementSockets(e) { if (this.maxSockets === Infinity && this.maxTotalSockets === Infinity) return null; if (!this.sockets[e]) this.sockets[e] = []; const t = new s.Socket({ writable: false }); this.sockets[e].push(t); this.totalSocketCount++; return t; } decrementSockets(e, t) { if (!this.sockets[e] || t === null) return; const n = this.sockets[e]; const r = n.indexOf(t); if (r !== -1) { n.splice(r, 1); this.totalSocketCount--; if (n.length === 0) delete this.sockets[e]; } } getName(e) { if (this.isSecureEndpoint(e)) return l.Agent.prototype.getName.call(this, e); return super.getName(e); } createSocket(e, t, n) { const r = { ...t, secureEndpoint: this.isSecureEndpoint(t) }; const i = this.getName(r); const a = this.incrementSockets(i); Promise.resolve().then(() => this.connect(e, r)).then((o) => { this.decrementSockets(i, a); if (o instanceof c.Agent) try { return o.addRequest(e, r); } catch (e) { return n(e); } this[u].currentSocket = o; super.createSocket(e, t, n); }, (e) => { this.decrementSockets(i, a); n(e); }); } createConnection() { const e = this[u].currentSocket; this[u].currentSocket = void 0; if (!e) throw new Error("No socket was returned in the `connect()` function"); return e; } get defaultPort() { return this[u].defaultPort ?? (this.protocol === "https:" ? 443 : 80); } set defaultPort(e) { if (this[u]) this[u].defaultPort = e; } get protocol() { return this[u].protocol ?? (this.isSecureEndpoint() ? "https:" : "http:"); } set protocol(e) { if (this[u]) this[u].protocol = e; } }; e.Agent = Agent; })); //#endregion //#region node_modules/.pnpm/https-proxy-agent@7.0.6_supports-color@10.2.2/node_modules/https-proxy-agent/dist/parse-proxy-response.js var require_parse_proxy_response = /* @__PURE__ */ __commonJSMin(((e, t, n) => { var r = n && n.__importDefault || function(e) { return e && e.__esModule ? e : { "default": e }; }; Object.defineProperty(e, "__esModule", { value: true }); e.parseProxyResponse = void 0; const i = (0, r(require_src()).default)("https-proxy-agent:parse-proxy-response"); function parseProxyResponse(e) { return new Promise((t, n) => { let r = 0; const a = []; function read() { const t = e.read(); if (t) ondata(t); else e.once("readable", read); } function cleanup() { e.removeListener("end", onend); e.removeListener("error", onerror); e.removeListener("readable", read); } function onend() { cleanup(); i("onend"); n(/* @__PURE__ */ new Error("Proxy connection ended before receiving CONNECT response")); } function onerror(e) { cleanup(); i("onerror %o", e); n(e); } function ondata(o) { a.push(o); r += o.length; const s = Buffer.concat(a, r); const c = s.indexOf("\r\n\r\n"); if (c === -1) { i("have not received end of HTTP headers yet..."); read(); return; } const l = s.slice(0, c).toString("ascii").split("\r\n"); const u = l.shift(); if (!u) { e.destroy(); return n(/* @__PURE__ */ new Error("No header received from proxy CONNECT response")); } const d = u.split(" "); const f = +d[1]; const p = d.slice(2).join(" "); const m = {}; for (const t of l) { if (!t) continue; const r = t.indexOf(":"); if (r === -1) { e.destroy(); return n(/* @__PURE__ */ new Error(`Invalid header from proxy CONNECT response: "${t}"`)); } const i = t.slice(0, r).toLowerCase(); const a = t.slice(r + 1).trimStart(); const o = m[i]; if (typeof o === "string") m[i] = [o, a]; else if (Array.isArray(o)) o.push(a); else m[i] = a; } i("got proxy server response: %o %o", u, m); cleanup(); t({ connect: { statusCode: f, statusText: p, headers: m }, buffered: s }); } e.on("error", onerror); e.on("end", onend); read(); }); } e.parseProxyResponse = parseProxyResponse; })); //#endregion //#region node_modules/.pnpm/https-proxy-agent@7.0.6_supports-color@10.2.2/node_modules/https-proxy-agent/dist/index.js var require_dist = /* @__PURE__ */ __commonJSMin(((e, t, n) => { var r = n && n.__createBinding || (Object.create ? (function(e, t, n, r) { if (r === void 0) r = n; var i = Object.getOwnPropertyDescriptor(t, n); if (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) i = { enumerable: true, get: function() { return t[n]; } }; Object.defineProperty(e, r, i); }) : (function(e, t, n, r) { if (r === void 0) r = n; e[r] = t[n]; })); var i = n && n.__setModuleDefault || (Object.create ? (function(e, t) { Object.defineProperty(e, "default", { enumerable: true, value: t }); }) : function(e, t) { e["default"] = t; }); var a = n && n.__importStar || function(e) { if (e && e.__esModule) return e; var t = {}; if (e != null) { for (var n in e) if (n !== "default" && Object.prototype.hasOwnProperty.call(e, n)) r(t, e, n); } i(t, e); return t; }; var o = n && n.__importDefault || function(e) { return e && e.__esModule ? e : { "default": e }; }; Object.defineProperty(e, "__esModule", { value: true }); e.HttpsProxyAgent = void 0; const s = a(__require("net")); const c = a(__require("tls")); const l = o(__require("assert")); const u = o(require_src()); const d = require_dist$1(); const f = __require("url"); const p = require_parse_proxy_response(); const m = (0, u.default)("https-proxy-agent"); const setServernameFromNonIpHost = (e) => { if (e.servername === void 0 && e.host && !s.isIP(e.host)) return { ...e, servername: e.host }; return e; }; /** * The `HttpsProxyAgent` implements an HTTP Agent subclass that connects to * the specified "HTTP(s) proxy server" in order to proxy HTTPS requests. * * Outgoing HTTP requests are first tunneled through the proxy server using the * `CONNECT` HTTP request method to establish a connection to the proxy server, * and then the proxy server connects to the destination target and issues the * HTTP request from the proxy server. * * `https:` requests have their socket connection upgraded to TLS once * the connection to the proxy server has been established. */ var HttpsProxyAgent = class extends d.Agent { constructor(e, t) { super(t); this.options = { path: void 0 }; this.proxy = typeof e === "string" ? new f.URL(e) : e; this.proxyHeaders = t?.headers ?? {}; m("Creating new HttpsProxyAgent instance: %o", this.proxy.href); const n = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, ""); const r = this.proxy.port ? parseInt(this.proxy.port, 10) : this.proxy.protocol === "https:" ? 443 : 80; this.connectOpts = { ALPNProtocols: ["http/1.1"], ...t ? omit(t, "headers") : null, host: n, port: r }; } /** * Called when the node-core HTTP client library is creating a * new HTTP request. */ async connect(e, t) { const { proxy: n } = this; if (!t.host) throw new TypeError("No \"host\" provided"); let r; if (n.protocol === "https:") { m("Creating `tls.Socket`: %o", this.connectOpts); r = c.connect(setServernameFromNonIpHost(this.connectOpts)); } else { m("Creating `net.Socket`: %o", this.connectOpts); r = s.connect(this.connectOpts); } const i = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders }; const a = s.isIPv6(t.host) ? `[${t.host}]` : t.host; let o = `CONNECT ${a}:${t.port} HTTP/1.1\r\n`; if (n.username || n.password) { const e = `${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`; i["Proxy-Authorization"] = `Basic ${Buffer.from(e).toString("base64")}`; } i.Host = `${a}:${t.port}`; if (!i["Proxy-Connection"]) i["Proxy-Connection"] = this.keepAlive ? "Keep-Alive" : "close"; for (const e of Object.keys(i)) o += `${e}: ${i[e]}\r\n`; const u = (0, p.parseProxyResponse)(r); r.write(`${o}\r\n`); const { connect: d, buffered: f } = await u; e.emit("proxyConnect", d); this.emit("proxyConnect", d, e); if (d.statusCode === 200) { e.once("socket", resume); if (t.secureEndpoint) { m("Upgrading socket connection to TLS"); return c.connect({ ...omit(setServernameFromNonIpHost(t), "host", "path", "port"), socket: r }); } return r; } r.destroy(); const h = new s.Socket({ writable: false }); h.readable = true; e.once("socket", (e) => { m("Replaying proxy buffer for failed request"); (0, l.default)(e.listenerCount("data") > 0); e.push(f); e.push(null); }); return h; } }; HttpsProxyAgent.protocols = ["http", "https"]; e.HttpsProxyAgent = HttpsProxyAgent; function resume(e) { e.resume(); } function omit(e, ...t) { const n = {}; let r; for (r in e) if (!t.includes(r)) n[r] = e[r]; return n; } })); //#endregion export default require_dist(); export {};