UNPKG

create-eliza

Version:

Initialize an Eliza project

1,471 lines (1,446 loc) 211 kB
import { createRequire } from 'module'; const require = createRequire(import.meta.url); import { require_src } from "./chunk-JWMTR3QA.js"; import { require_get_intrinsic, require_hasown, require_mime_types, require_shams, require_type } from "./chunk-JOY6AARI.js"; import { require_prompts } from "./chunk-OGSHIQ3J.js"; import { Command, require_lib } from "./chunk-CKY7YPIS.js"; import { __commonJS, __export, __require, __toESM } from "./chunk-WCMDOJQK.js"; // ../../node_modules/delayed-stream/lib/delayed_stream.js var require_delayed_stream = __commonJS({ "../../node_modules/delayed-stream/lib/delayed_stream.js"(exports, module) { var Stream = __require("stream").Stream; var util3 = __require("util"); module.exports = DelayedStream; function DelayedStream() { this.source = null; this.dataSize = 0; this.maxDataSize = 1024 * 1024; this.pauseStream = true; this._maxDataSizeExceeded = false; this._released = false; this._bufferedEvents = []; } util3.inherits(DelayedStream, Stream); DelayedStream.create = function(source, options) { var delayedStream = new this(); options = options || {}; for (var option in options) { delayedStream[option] = options[option]; } delayedStream.source = source; var realEmit = source.emit; source.emit = function() { delayedStream._handleEmit(arguments); return realEmit.apply(source, arguments); }; source.on("error", function() { }); if (delayedStream.pauseStream) { source.pause(); } return delayedStream; }; Object.defineProperty(DelayedStream.prototype, "readable", { configurable: true, enumerable: true, get: function() { return this.source.readable; } }); DelayedStream.prototype.setEncoding = function() { return this.source.setEncoding.apply(this.source, arguments); }; DelayedStream.prototype.resume = function() { if (!this._released) { this.release(); } this.source.resume(); }; DelayedStream.prototype.pause = function() { this.source.pause(); }; DelayedStream.prototype.release = function() { this._released = true; this._bufferedEvents.forEach(function(args) { this.emit.apply(this, args); }.bind(this)); this._bufferedEvents = []; }; DelayedStream.prototype.pipe = function() { var r = Stream.prototype.pipe.apply(this, arguments); this.resume(); return r; }; DelayedStream.prototype._handleEmit = function(args) { if (this._released) { this.emit.apply(this, args); return; } if (args[0] === "data") { this.dataSize += args[1].length; this._checkIfMaxDataSizeExceeded(); } this._bufferedEvents.push(args); }; DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() { if (this._maxDataSizeExceeded) { return; } if (this.dataSize <= this.maxDataSize) { return; } this._maxDataSizeExceeded = true; var message = "DelayedStream#maxDataSize of " + this.maxDataSize + " bytes exceeded."; this.emit("error", new Error(message)); }; } }); // ../../node_modules/combined-stream/lib/combined_stream.js var require_combined_stream = __commonJS({ "../../node_modules/combined-stream/lib/combined_stream.js"(exports, module) { var util3 = __require("util"); var Stream = __require("stream").Stream; var DelayedStream = require_delayed_stream(); module.exports = CombinedStream; function CombinedStream() { this.writable = false; this.readable = true; this.dataSize = 0; this.maxDataSize = 2 * 1024 * 1024; this.pauseStreams = true; this._released = false; this._streams = []; this._currentStream = null; this._insideLoop = false; this._pendingNext = false; } util3.inherits(CombinedStream, Stream); CombinedStream.create = function(options) { var combinedStream = new this(); options = options || {}; for (var option in options) { combinedStream[option] = options[option]; } return combinedStream; }; CombinedStream.isStreamLike = function(stream4) { return typeof stream4 !== "function" && typeof stream4 !== "string" && typeof stream4 !== "boolean" && typeof stream4 !== "number" && !Buffer.isBuffer(stream4); }; CombinedStream.prototype.append = function(stream4) { var isStreamLike = CombinedStream.isStreamLike(stream4); if (isStreamLike) { if (!(stream4 instanceof DelayedStream)) { var newStream = DelayedStream.create(stream4, { maxDataSize: Infinity, pauseStream: this.pauseStreams }); stream4.on("data", this._checkDataSize.bind(this)); stream4 = newStream; } this._handleErrors(stream4); if (this.pauseStreams) { stream4.pause(); } } this._streams.push(stream4); return this; }; CombinedStream.prototype.pipe = function(dest, options) { Stream.prototype.pipe.call(this, dest, options); this.resume(); return dest; }; CombinedStream.prototype._getNext = function() { this._currentStream = null; if (this._insideLoop) { this._pendingNext = true; return; } this._insideLoop = true; try { do { this._pendingNext = false; this._realGetNext(); } while (this._pendingNext); } finally { this._insideLoop = false; } }; CombinedStream.prototype._realGetNext = function() { var stream4 = this._streams.shift(); if (typeof stream4 == "undefined") { this.end(); return; } if (typeof stream4 !== "function") { this._pipeNext(stream4); return; } var getStream = stream4; getStream(function(stream5) { var isStreamLike = CombinedStream.isStreamLike(stream5); if (isStreamLike) { stream5.on("data", this._checkDataSize.bind(this)); this._handleErrors(stream5); } this._pipeNext(stream5); }.bind(this)); }; CombinedStream.prototype._pipeNext = function(stream4) { this._currentStream = stream4; var isStreamLike = CombinedStream.isStreamLike(stream4); if (isStreamLike) { stream4.on("end", this._getNext.bind(this)); stream4.pipe(this, { end: false }); return; } var value = stream4; this.write(value); this._getNext(); }; CombinedStream.prototype._handleErrors = function(stream4) { var self2 = this; stream4.on("error", function(err) { self2._emitError(err); }); }; CombinedStream.prototype.write = function(data) { this.emit("data", data); }; CombinedStream.prototype.pause = function() { if (!this.pauseStreams) { return; } if (this.pauseStreams && this._currentStream && typeof this._currentStream.pause == "function") this._currentStream.pause(); this.emit("pause"); }; CombinedStream.prototype.resume = function() { if (!this._released) { this._released = true; this.writable = true; this._getNext(); } if (this.pauseStreams && this._currentStream && typeof this._currentStream.resume == "function") this._currentStream.resume(); this.emit("resume"); }; CombinedStream.prototype.end = function() { this._reset(); this.emit("end"); }; CombinedStream.prototype.destroy = function() { this._reset(); this.emit("close"); }; CombinedStream.prototype._reset = function() { this.writable = false; this._streams = []; this._currentStream = null; }; CombinedStream.prototype._checkDataSize = function() { this._updateDataSize(); if (this.dataSize <= this.maxDataSize) { return; } var message = "DelayedStream#maxDataSize of " + this.maxDataSize + " bytes exceeded."; this._emitError(new Error(message)); }; CombinedStream.prototype._updateDataSize = function() { this.dataSize = 0; var self2 = this; this._streams.forEach(function(stream4) { if (!stream4.dataSize) { return; } self2.dataSize += stream4.dataSize; }); if (this._currentStream && this._currentStream.dataSize) { this.dataSize += this._currentStream.dataSize; } }; CombinedStream.prototype._emitError = function(err) { this._reset(); this.emit("error", err); }; } }); // ../../node_modules/asynckit/lib/defer.js var require_defer = __commonJS({ "../../node_modules/asynckit/lib/defer.js"(exports, module) { module.exports = defer; function defer(fn) { var nextTick = typeof setImmediate == "function" ? setImmediate : typeof process == "object" && typeof process.nextTick == "function" ? process.nextTick : null; if (nextTick) { nextTick(fn); } else { setTimeout(fn, 0); } } } }); // ../../node_modules/asynckit/lib/async.js var require_async = __commonJS({ "../../node_modules/asynckit/lib/async.js"(exports, module) { var defer = require_defer(); module.exports = async; function async(callback) { var isAsync = false; defer(function() { isAsync = true; }); return function async_callback(err, result) { if (isAsync) { callback(err, result); } else { defer(function nextTick_callback() { callback(err, result); }); } }; } } }); // ../../node_modules/asynckit/lib/abort.js var require_abort = __commonJS({ "../../node_modules/asynckit/lib/abort.js"(exports, module) { module.exports = abort; function abort(state) { Object.keys(state.jobs).forEach(clean.bind(state)); state.jobs = {}; } function clean(key) { if (typeof this.jobs[key] == "function") { this.jobs[key](); } } } }); // ../../node_modules/asynckit/lib/iterate.js var require_iterate = __commonJS({ "../../node_modules/asynckit/lib/iterate.js"(exports, module) { var async = require_async(); var abort = require_abort(); module.exports = iterate; function iterate(list, iterator, state, callback) { var key = state["keyedList"] ? state["keyedList"][state.index] : state.index; state.jobs[key] = runJob(iterator, key, list[key], function(error, output) { if (!(key in state.jobs)) { return; } delete state.jobs[key]; if (error) { abort(state); } else { state.results[key] = output; } callback(error, state.results); }); } function runJob(iterator, key, item, callback) { var aborter; if (iterator.length == 2) { aborter = iterator(item, async(callback)); } else { aborter = iterator(item, key, async(callback)); } return aborter; } } }); // ../../node_modules/asynckit/lib/state.js var require_state = __commonJS({ "../../node_modules/asynckit/lib/state.js"(exports, module) { module.exports = state; function state(list, sortMethod) { var isNamedList = !Array.isArray(list), initState = { index: 0, keyedList: isNamedList || sortMethod ? Object.keys(list) : null, jobs: {}, results: isNamedList ? {} : [], size: isNamedList ? Object.keys(list).length : list.length }; if (sortMethod) { initState.keyedList.sort(isNamedList ? sortMethod : function(a, b) { return sortMethod(list[a], list[b]); }); } return initState; } } }); // ../../node_modules/asynckit/lib/terminator.js var require_terminator = __commonJS({ "../../node_modules/asynckit/lib/terminator.js"(exports, module) { var abort = require_abort(); var async = require_async(); module.exports = terminator; function terminator(callback) { if (!Object.keys(this.jobs).length) { return; } this.index = this.size; abort(this); async(callback)(null, this.results); } } }); // ../../node_modules/asynckit/parallel.js var require_parallel = __commonJS({ "../../node_modules/asynckit/parallel.js"(exports, module) { var iterate = require_iterate(); var initState = require_state(); var terminator = require_terminator(); module.exports = parallel; function parallel(list, iterator, callback) { var state = initState(list); while (state.index < (state["keyedList"] || list).length) { iterate(list, iterator, state, function(error, result) { if (error) { callback(error, result); return; } if (Object.keys(state.jobs).length === 0) { callback(null, state.results); return; } }); state.index++; } return terminator.bind(state, callback); } } }); // ../../node_modules/asynckit/serialOrdered.js var require_serialOrdered = __commonJS({ "../../node_modules/asynckit/serialOrdered.js"(exports, module) { var iterate = require_iterate(); var initState = require_state(); var terminator = require_terminator(); module.exports = serialOrdered; module.exports.ascending = ascending; module.exports.descending = descending; function serialOrdered(list, iterator, sortMethod, callback) { var state = initState(list, sortMethod); iterate(list, iterator, state, function iteratorHandler(error, result) { if (error) { callback(error, result); return; } state.index++; if (state.index < (state["keyedList"] || list).length) { iterate(list, iterator, state, iteratorHandler); return; } callback(null, state.results); }); return terminator.bind(state, callback); } function ascending(a, b) { return a < b ? -1 : a > b ? 1 : 0; } function descending(a, b) { return -1 * ascending(a, b); } } }); // ../../node_modules/asynckit/serial.js var require_serial = __commonJS({ "../../node_modules/asynckit/serial.js"(exports, module) { var serialOrdered = require_serialOrdered(); module.exports = serial; function serial(list, iterator, callback) { return serialOrdered(list, iterator, null, callback); } } }); // ../../node_modules/asynckit/index.js var require_asynckit = __commonJS({ "../../node_modules/asynckit/index.js"(exports, module) { module.exports = { parallel: require_parallel(), serial: require_serial(), serialOrdered: require_serialOrdered() }; } }); // ../../node_modules/has-tostringtag/shams.js var require_shams2 = __commonJS({ "../../node_modules/has-tostringtag/shams.js"(exports, module) { "use strict"; var hasSymbols = require_shams(); module.exports = function hasToStringTagShams() { return hasSymbols() && !!Symbol.toStringTag; }; } }); // ../../node_modules/es-set-tostringtag/index.js var require_es_set_tostringtag = __commonJS({ "../../node_modules/es-set-tostringtag/index.js"(exports, module) { "use strict"; var GetIntrinsic = require_get_intrinsic(); var $defineProperty = GetIntrinsic("%Object.defineProperty%", true); var hasToStringTag = require_shams2()(); var hasOwn = require_hasown(); var $TypeError = require_type(); var toStringTag = hasToStringTag ? Symbol.toStringTag : null; module.exports = function setToStringTag(object, value) { var overrideIfSet = arguments.length > 2 && !!arguments[2] && arguments[2].force; var nonConfigurable = arguments.length > 2 && !!arguments[2] && arguments[2].nonConfigurable; if (typeof overrideIfSet !== "undefined" && typeof overrideIfSet !== "boolean" || typeof nonConfigurable !== "undefined" && typeof nonConfigurable !== "boolean") { throw new $TypeError("if provided, the `overrideIfSet` and `nonConfigurable` options must be booleans"); } if (toStringTag && (overrideIfSet || !hasOwn(object, toStringTag))) { if ($defineProperty) { $defineProperty(object, toStringTag, { configurable: !nonConfigurable, enumerable: false, value, writable: false }); } else { object[toStringTag] = value; } } }; } }); // ../../node_modules/form-data/lib/populate.js var require_populate = __commonJS({ "../../node_modules/form-data/lib/populate.js"(exports, module) { module.exports = function(dst, src) { Object.keys(src).forEach(function(prop) { dst[prop] = dst[prop] || src[prop]; }); return dst; }; } }); // ../../node_modules/form-data/lib/form_data.js var require_form_data = __commonJS({ "../../node_modules/form-data/lib/form_data.js"(exports, module) { var CombinedStream = require_combined_stream(); var util3 = __require("util"); var path3 = __require("path"); var http2 = __require("http"); var https2 = __require("https"); var parseUrl = __require("url").parse; var fs5 = __require("fs"); var Stream = __require("stream").Stream; var mime = require_mime_types(); var asynckit = require_asynckit(); var setToStringTag = require_es_set_tostringtag(); var populate = require_populate(); module.exports = FormData3; util3.inherits(FormData3, CombinedStream); function FormData3(options) { if (!(this instanceof FormData3)) { return new FormData3(options); } this._overheadLength = 0; this._valueLength = 0; this._valuesToMeasure = []; CombinedStream.call(this); options = options || {}; for (var option in options) { this[option] = options[option]; } } FormData3.LINE_BREAK = "\r\n"; FormData3.DEFAULT_CONTENT_TYPE = "application/octet-stream"; FormData3.prototype.append = function(field, value, options) { options = options || {}; if (typeof options == "string") { options = { filename: options }; } var append2 = CombinedStream.prototype.append.bind(this); if (typeof value == "number") { value = "" + value; } if (Array.isArray(value)) { this._error(new Error("Arrays are not supported.")); return; } var header = this._multiPartHeader(field, value, options); var footer = this._multiPartFooter(); append2(header); append2(value); append2(footer); this._trackLength(header, value, options); }; FormData3.prototype._trackLength = function(header, value, options) { var valueLength = 0; if (options.knownLength != null) { valueLength += +options.knownLength; } else if (Buffer.isBuffer(value)) { valueLength = value.length; } else if (typeof value === "string") { valueLength = Buffer.byteLength(value); } this._valueLength += valueLength; this._overheadLength += Buffer.byteLength(header) + FormData3.LINE_BREAK.length; if (!value || !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) && !(value instanceof Stream)) { return; } if (!options.knownLength) { this._valuesToMeasure.push(value); } }; FormData3.prototype._lengthRetriever = function(value, callback) { if (Object.prototype.hasOwnProperty.call(value, "fd")) { if (value.end != void 0 && value.end != Infinity && value.start != void 0) { callback(null, value.end + 1 - (value.start ? value.start : 0)); } else { fs5.stat(value.path, function(err, stat) { var fileSize; if (err) { callback(err); return; } fileSize = stat.size - (value.start ? value.start : 0); callback(null, fileSize); }); } } else if (Object.prototype.hasOwnProperty.call(value, "httpVersion")) { callback(null, +value.headers["content-length"]); } else if (Object.prototype.hasOwnProperty.call(value, "httpModule")) { value.on("response", function(response) { value.pause(); callback(null, +response.headers["content-length"]); }); value.resume(); } else { callback("Unknown stream"); } }; FormData3.prototype._multiPartHeader = function(field, value, options) { if (typeof options.header == "string") { return options.header; } var contentDisposition = this._getContentDisposition(value, options); var contentType = this._getContentType(value, options); var contents = ""; var headers2 = { // add custom disposition as third element or keep it two elements if not "Content-Disposition": ["form-data", 'name="' + field + '"'].concat(contentDisposition || []), // if no content type. allow it to be empty array "Content-Type": [].concat(contentType || []) }; if (typeof options.header == "object") { populate(headers2, options.header); } var header; for (var prop in headers2) { if (Object.prototype.hasOwnProperty.call(headers2, prop)) { header = headers2[prop]; if (header == null) { continue; } if (!Array.isArray(header)) { header = [header]; } if (header.length) { contents += prop + ": " + header.join("; ") + FormData3.LINE_BREAK; } } } return "--" + this.getBoundary() + FormData3.LINE_BREAK + contents + FormData3.LINE_BREAK; }; FormData3.prototype._getContentDisposition = function(value, options) { var filename, contentDisposition; if (typeof options.filepath === "string") { filename = path3.normalize(options.filepath).replace(/\\/g, "/"); } else if (options.filename || value.name || value.path) { filename = path3.basename(options.filename || value.name || value.path); } else if (value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) { filename = path3.basename(value.client._httpMessage.path || ""); } if (filename) { contentDisposition = 'filename="' + filename + '"'; } return contentDisposition; }; FormData3.prototype._getContentType = function(value, options) { var contentType = options.contentType; if (!contentType && value.name) { contentType = mime.lookup(value.name); } if (!contentType && value.path) { contentType = mime.lookup(value.path); } if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) { contentType = value.headers["content-type"]; } if (!contentType && (options.filepath || options.filename)) { contentType = mime.lookup(options.filepath || options.filename); } if (!contentType && typeof value == "object") { contentType = FormData3.DEFAULT_CONTENT_TYPE; } return contentType; }; FormData3.prototype._multiPartFooter = function() { return function(next) { var footer = FormData3.LINE_BREAK; var lastPart = this._streams.length === 0; if (lastPart) { footer += this._lastBoundary(); } next(footer); }.bind(this); }; FormData3.prototype._lastBoundary = function() { return "--" + this.getBoundary() + "--" + FormData3.LINE_BREAK; }; FormData3.prototype.getHeaders = function(userHeaders) { var header; var formHeaders = { "content-type": "multipart/form-data; boundary=" + this.getBoundary() }; for (header in userHeaders) { if (Object.prototype.hasOwnProperty.call(userHeaders, header)) { formHeaders[header.toLowerCase()] = userHeaders[header]; } } return formHeaders; }; FormData3.prototype.setBoundary = function(boundary) { this._boundary = boundary; }; FormData3.prototype.getBoundary = function() { if (!this._boundary) { this._generateBoundary(); } return this._boundary; }; FormData3.prototype.getBuffer = function() { var dataBuffer = new Buffer.alloc(0); var boundary = this.getBoundary(); for (var i = 0, len = this._streams.length; i < len; i++) { if (typeof this._streams[i] !== "function") { if (Buffer.isBuffer(this._streams[i])) { dataBuffer = Buffer.concat([dataBuffer, this._streams[i]]); } else { dataBuffer = Buffer.concat([dataBuffer, Buffer.from(this._streams[i])]); } if (typeof this._streams[i] !== "string" || this._streams[i].substring(2, boundary.length + 2) !== boundary) { dataBuffer = Buffer.concat([dataBuffer, Buffer.from(FormData3.LINE_BREAK)]); } } } return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]); }; FormData3.prototype._generateBoundary = function() { var boundary = "--------------------------"; for (var i = 0; i < 24; i++) { boundary += Math.floor(Math.random() * 10).toString(16); } this._boundary = boundary; }; FormData3.prototype.getLengthSync = function() { var knownLength = this._overheadLength + this._valueLength; if (this._streams.length) { knownLength += this._lastBoundary().length; } if (!this.hasKnownLength()) { this._error(new Error("Cannot calculate proper length in synchronous way.")); } return knownLength; }; FormData3.prototype.hasKnownLength = function() { var hasKnownLength = true; if (this._valuesToMeasure.length) { hasKnownLength = false; } return hasKnownLength; }; FormData3.prototype.getLength = function(cb) { var knownLength = this._overheadLength + this._valueLength; if (this._streams.length) { knownLength += this._lastBoundary().length; } if (!this._valuesToMeasure.length) { process.nextTick(cb.bind(this, null, knownLength)); return; } asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) { if (err) { cb(err); return; } values.forEach(function(length) { knownLength += length; }); cb(null, knownLength); }); }; FormData3.prototype.submit = function(params, cb) { var request, options, defaults2 = { method: "post" }; if (typeof params == "string") { params = parseUrl(params); options = populate({ port: params.port, path: params.pathname, host: params.hostname, protocol: params.protocol }, defaults2); } else { options = populate(params, defaults2); if (!options.port) { options.port = options.protocol == "https:" ? 443 : 80; } } options.headers = this.getHeaders(params.headers); if (options.protocol == "https:") { request = https2.request(options); } else { request = http2.request(options); } this.getLength(function(err, length) { if (err && err !== "Unknown stream") { this._error(err); return; } if (length) { request.setHeader("Content-Length", length); } this.pipe(request); if (cb) { var onResponse; var callback = function(error, responce) { request.removeListener("error", callback); request.removeListener("response", onResponse); return cb.call(this, error, responce); }; onResponse = callback.bind(this, null); request.on("error", callback); request.on("response", onResponse); } }.bind(this)); return request; }; FormData3.prototype._error = function(err) { if (!this.error) { this.error = err; this.pause(); this.emit("error", err); } }; FormData3.prototype.toString = function() { return "[object FormData]"; }; setToStringTag(FormData3, "FormData"); } }); // ../../node_modules/proxy-from-env/index.js var require_proxy_from_env = __commonJS({ "../../node_modules/proxy-from-env/index.js"(exports) { "use strict"; var parseUrl = __require("url").parse; var DEFAULT_PORTS = { ftp: 21, gopher: 70, http: 80, https: 443, ws: 80, wss: 443 }; var stringEndsWith = String.prototype.endsWith || function(s) { return s.length <= this.length && this.indexOf(s, this.length - s.length) !== -1; }; function getProxyForUrl(url2) { var parsedUrl = typeof url2 === "string" ? parseUrl(url2) : url2 || {}; var proto = parsedUrl.protocol; var hostname = parsedUrl.host; var port = parsedUrl.port; if (typeof hostname !== "string" || !hostname || typeof proto !== "string") { return ""; } proto = proto.split(":", 1)[0]; hostname = hostname.replace(/:\d*$/, ""); port = parseInt(port) || DEFAULT_PORTS[proto] || 0; if (!shouldProxy(hostname, port)) { return ""; } var proxy = getEnv("npm_config_" + proto + "_proxy") || getEnv(proto + "_proxy") || getEnv("npm_config_proxy") || getEnv("all_proxy"); if (proxy && proxy.indexOf("://") === -1) { proxy = proto + "://" + proxy; } return proxy; } function shouldProxy(hostname, port) { var NO_PROXY = (getEnv("npm_config_no_proxy") || getEnv("no_proxy")).toLowerCase(); if (!NO_PROXY) { return true; } if (NO_PROXY === "*") { return false; } return NO_PROXY.split(/[,\s]/).every(function(proxy) { if (!proxy) { return true; } var parsedProxy = proxy.match(/^(.+):(\d+)$/); var parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy; var parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0; if (parsedProxyPort && parsedProxyPort !== port) { return true; } if (!/^[.*]/.test(parsedProxyHostname)) { return hostname !== parsedProxyHostname; } if (parsedProxyHostname.charAt(0) === "*") { parsedProxyHostname = parsedProxyHostname.slice(1); } return !stringEndsWith.call(hostname, parsedProxyHostname); }); } function getEnv(key) { return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || ""; } exports.getProxyForUrl = getProxyForUrl; } }); // ../../node_modules/follow-redirects/debug.js var require_debug = __commonJS({ "../../node_modules/follow-redirects/debug.js"(exports, module) { var debug; module.exports = function() { if (!debug) { try { debug = require_src()("follow-redirects"); } catch (error) { } if (typeof debug !== "function") { debug = function() { }; } } debug.apply(null, arguments); }; } }); // ../../node_modules/follow-redirects/index.js var require_follow_redirects = __commonJS({ "../../node_modules/follow-redirects/index.js"(exports, module) { var url2 = __require("url"); var URL2 = url2.URL; var http2 = __require("http"); var https2 = __require("https"); var Writable = __require("stream").Writable; var assert = __require("assert"); var debug = require_debug(); (function detectUnsupportedEnvironment() { var looksLikeNode = typeof process !== "undefined"; var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined"; var looksLikeV8 = isFunction2(Error.captureStackTrace); if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) { console.warn("The follow-redirects package should be excluded from browser builds."); } })(); var useNativeURL = false; try { assert(new URL2("")); } catch (error) { useNativeURL = error.code === "ERR_INVALID_URL"; } var preservedUrlFields = [ "auth", "host", "hostname", "href", "path", "pathname", "port", "protocol", "query", "search", "hash" ]; var events = ["abort", "aborted", "connect", "error", "socket", "timeout"]; var eventHandlers = /* @__PURE__ */ Object.create(null); events.forEach(function(event) { eventHandlers[event] = function(arg1, arg2, arg3) { this._redirectable.emit(event, arg1, arg2, arg3); }; }); var InvalidUrlError = createErrorType( "ERR_INVALID_URL", "Invalid URL", TypeError ); var RedirectionError = createErrorType( "ERR_FR_REDIRECTION_FAILURE", "Redirected request failed" ); var TooManyRedirectsError = createErrorType( "ERR_FR_TOO_MANY_REDIRECTS", "Maximum number of redirects exceeded", RedirectionError ); var MaxBodyLengthExceededError = createErrorType( "ERR_FR_MAX_BODY_LENGTH_EXCEEDED", "Request body larger than maxBodyLength limit" ); var WriteAfterEndError = createErrorType( "ERR_STREAM_WRITE_AFTER_END", "write after end" ); var destroy = Writable.prototype.destroy || noop2; function RedirectableRequest(options, responseCallback) { Writable.call(this); this._sanitizeOptions(options); this._options = options; this._ended = false; this._ending = false; this._redirectCount = 0; this._redirects = []; this._requestBodyLength = 0; this._requestBodyBuffers = []; if (responseCallback) { this.on("response", responseCallback); } var self2 = this; this._onNativeResponse = function(response) { try { self2._processResponse(response); } catch (cause) { self2.emit("error", cause instanceof RedirectionError ? cause : new RedirectionError({ cause })); } }; this._performRequest(); } RedirectableRequest.prototype = Object.create(Writable.prototype); RedirectableRequest.prototype.abort = function() { destroyRequest(this._currentRequest); this._currentRequest.abort(); this.emit("abort"); }; RedirectableRequest.prototype.destroy = function(error) { destroyRequest(this._currentRequest, error); destroy.call(this, error); return this; }; RedirectableRequest.prototype.write = function(data, encoding, callback) { if (this._ending) { throw new WriteAfterEndError(); } if (!isString2(data) && !isBuffer2(data)) { throw new TypeError("data should be a string, Buffer or Uint8Array"); } if (isFunction2(encoding)) { callback = encoding; encoding = null; } if (data.length === 0) { if (callback) { callback(); } return; } if (this._requestBodyLength + data.length <= this._options.maxBodyLength) { this._requestBodyLength += data.length; this._requestBodyBuffers.push({ data, encoding }); this._currentRequest.write(data, encoding, callback); } else { this.emit("error", new MaxBodyLengthExceededError()); this.abort(); } }; RedirectableRequest.prototype.end = function(data, encoding, callback) { if (isFunction2(data)) { callback = data; data = encoding = null; } else if (isFunction2(encoding)) { callback = encoding; encoding = null; } if (!data) { this._ended = this._ending = true; this._currentRequest.end(null, null, callback); } else { var self2 = this; var currentRequest = this._currentRequest; this.write(data, encoding, function() { self2._ended = true; currentRequest.end(null, null, callback); }); this._ending = true; } }; RedirectableRequest.prototype.setHeader = function(name, value) { this._options.headers[name] = value; this._currentRequest.setHeader(name, value); }; RedirectableRequest.prototype.removeHeader = function(name) { delete this._options.headers[name]; this._currentRequest.removeHeader(name); }; RedirectableRequest.prototype.setTimeout = function(msecs, callback) { var self2 = this; function destroyOnTimeout(socket) { socket.setTimeout(msecs); socket.removeListener("timeout", socket.destroy); socket.addListener("timeout", socket.destroy); } function startTimer(socket) { if (self2._timeout) { clearTimeout(self2._timeout); } self2._timeout = setTimeout(function() { self2.emit("timeout"); clearTimer(); }, msecs); destroyOnTimeout(socket); } function clearTimer() { if (self2._timeout) { clearTimeout(self2._timeout); self2._timeout = null; } self2.removeListener("abort", clearTimer); self2.removeListener("error", clearTimer); self2.removeListener("response", clearTimer); self2.removeListener("close", clearTimer); if (callback) { self2.removeListener("timeout", callback); } if (!self2.socket) { self2._currentRequest.removeListener("socket", startTimer); } } if (callback) { this.on("timeout", callback); } if (this.socket) { startTimer(this.socket); } else { this._currentRequest.once("socket", startTimer); } this.on("socket", destroyOnTimeout); this.on("abort", clearTimer); this.on("error", clearTimer); this.on("response", clearTimer); this.on("close", clearTimer); return this; }; [ "flushHeaders", "getHeader", "setNoDelay", "setSocketKeepAlive" ].forEach(function(method) { RedirectableRequest.prototype[method] = function(a, b) { return this._currentRequest[method](a, b); }; }); ["aborted", "connection", "socket"].forEach(function(property) { Object.defineProperty(RedirectableRequest.prototype, property, { get: function() { return this._currentRequest[property]; } }); }); RedirectableRequest.prototype._sanitizeOptions = function(options) { if (!options.headers) { options.headers = {}; } if (options.host) { if (!options.hostname) { options.hostname = options.host; } delete options.host; } if (!options.pathname && options.path) { var searchPos = options.path.indexOf("?"); if (searchPos < 0) { options.pathname = options.path; } else { options.pathname = options.path.substring(0, searchPos); options.search = options.path.substring(searchPos); } } }; RedirectableRequest.prototype._performRequest = function() { var protocol = this._options.protocol; var nativeProtocol = this._options.nativeProtocols[protocol]; if (!nativeProtocol) { throw new TypeError("Unsupported protocol " + protocol); } if (this._options.agents) { var scheme = protocol.slice(0, -1); this._options.agent = this._options.agents[scheme]; } var request = this._currentRequest = nativeProtocol.request(this._options, this._onNativeResponse); request._redirectable = this; for (var event of events) { request.on(event, eventHandlers[event]); } this._currentUrl = /^\//.test(this._options.path) ? url2.format(this._options) : ( // When making a request to a proxy, […] // a client MUST send the target URI in absolute-form […]. this._options.path ); if (this._isRedirect) { var i = 0; var self2 = this; var buffers = this._requestBodyBuffers; (function writeNext(error) { if (request === self2._currentRequest) { if (error) { self2.emit("error", error); } else if (i < buffers.length) { var buffer = buffers[i++]; if (!request.finished) { request.write(buffer.data, buffer.encoding, writeNext); } } else if (self2._ended) { request.end(); } } })(); } }; RedirectableRequest.prototype._processResponse = function(response) { var statusCode = response.statusCode; if (this._options.trackRedirects) { this._redirects.push({ url: this._currentUrl, headers: response.headers, statusCode }); } var location = response.headers.location; if (!location || this._options.followRedirects === false || statusCode < 300 || statusCode >= 400) { response.responseUrl = this._currentUrl; response.redirects = this._redirects; this.emit("response", response); this._requestBodyBuffers = []; return; } destroyRequest(this._currentRequest); response.destroy(); if (++this._redirectCount > this._options.maxRedirects) { throw new TooManyRedirectsError(); } var requestHeaders; var beforeRedirect = this._options.beforeRedirect; if (beforeRedirect) { requestHeaders = Object.assign({ // The Host header was set by nativeProtocol.request Host: response.req.getHeader("host") }, this._options.headers); } var method = this._options.method; if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" || // RFC7231§6.4.4: The 303 (See Other) status code indicates that // the server is redirecting the user agent to a different resource […] // A user agent can perform a retrieval request targeting that URI // (a GET or HEAD request if using HTTP) […] statusCode === 303 && !/^(?:GET|HEAD)$/.test(this._options.method)) { this._options.method = "GET"; this._requestBodyBuffers = []; removeMatchingHeaders(/^content-/i, this._options.headers); } var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers); var currentUrlParts = parseUrl(this._currentUrl); var currentHost = currentHostHeader || currentUrlParts.host; var currentUrl = /^\w+:/.test(location) ? this._currentUrl : url2.format(Object.assign(currentUrlParts, { host: currentHost })); var redirectUrl = resolveUrl(location, currentUrl); debug("redirecting to", redirectUrl.href); this._isRedirect = true; spreadUrlObject(redirectUrl, this._options); if (redirectUrl.protocol !== currentUrlParts.protocol && redirectUrl.protocol !== "https:" || redirectUrl.host !== currentHost && !isSubdomain(redirectUrl.host, currentHost)) { removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers); } if (isFunction2(beforeRedirect)) { var responseDetails = { headers: response.headers, statusCode }; var requestDetails = { url: currentUrl, method, headers: requestHeaders }; beforeRedirect(this._options, responseDetails, requestDetails); this._sanitizeOptions(this._options); } this._performRequest(); }; function wrap(protocols) { var exports2 = { maxRedirects: 21, maxBodyLength: 10 * 1024 * 1024 }; var nativeProtocols = {}; Object.keys(protocols).forEach(function(scheme) { var protocol = scheme + ":"; var nativeProtocol = nativeProtocols[protocol] = protocols[scheme]; var wrappedProtocol = exports2[scheme] = Object.create(nativeProtocol); function request(input, options, callback) { if (isURL(input)) { input = spreadUrlObject(input); } else if (isString2(input)) { input = spreadUrlObject(parseUrl(input)); } else { callback = options; options = validateUrl(input); input = { protocol }; } if (isFunction2(options)) { callback = options; options = null; } options = Object.assign({ maxRedirects: exports2.maxRedirects, maxBodyLength: exports2.maxBodyLength }, input, options); options.nativeProtocols = nativeProtocols; if (!isString2(options.host) && !isString2(options.hostname)) { options.hostname = "::1"; } assert.equal(options.protocol, protocol, "protocol mismatch"); debug("options", options); return new RedirectableRequest(options, callback); } function get(input, options, callback) { var wrappedRequest = wrappedProtocol.request(input, options, callback); wrappedRequest.end(); return wrappedRequest; } Object.defineProperties(wrappedProtocol, { request: { value: request, configurable: true, enumerable: true, writable: true }, get: { value: get, configurable: true, enumerable: true, writable: true } }); }); return exports2; } function noop2() { } function parseUrl(input) { var parsed; if (useNativeURL) { parsed = new URL2(input); } else { parsed = validateUrl(url2.parse(input)); if (!isString2(parsed.protocol)) { throw new InvalidUrlError({ input }); } } return parsed; } function resolveUrl(relative, base) { return useNativeURL ? new URL2(relative, base) : parseUrl(url2.resolve(base, relative)); } function validateUrl(input) { if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) { throw new InvalidUrlError({ input: input.href || input }); } if (/^\[/.test(input.host) && !/^\[[:0-9a-f]+\](:\d+)?$/i.test(input.host)) { throw new InvalidUrlError({ input: input.href || input }); } return input; } function spreadUrlObject(urlObject, target) { var spread3 = target || {}; for (var key of preservedUrlFields) { spread3[key] = urlObject[key]; } if (spread3.hostname.startsWith("[")) { spread3.hostname = spread3.hostname.slice(1, -1); } if (spread3.port !== "") { spread3.port = Number(spread3.port); } spread3.path = spread3.search ? spread3.pathname + spread3.search : spread3.pathname; return spread3; } function removeMatchingHeaders(regex, headers2) { var lastValue; for (var header in headers2) { if (regex.test(header)) { lastValue = headers2[header]; delete headers2[header]; } } return lastValue === null || typeof lastValue === "undefined" ? void 0 : String(lastValue).trim(); } function createErrorType(code, message, baseClass) { function CustomError(properties) { if (isFunction2(Error.captureStackTrace)) { Error.captureStackTrace(this, this.constructor); } Object.assign(this, properties || {}); this.code = code; this.message = this.cause ? message + ": " + this.cause.message : message; } CustomError.prototype = new (baseClass || Error)(); Object.defineProperties(CustomError.prototype, { constructor: { value: CustomError, enumerable: false }, name: { value: "Error [" + code + "]", enumerable: false } }); return CustomError; } function destroyRequest(request, error) { for (var event of events) { request.removeListener(event, eventHandlers[event]); } request.on("error", noop2); request.destroy(error); } function isSubdomain(subdomain, domain) { assert(isString2(subdomain) && isString2(domain)); var dot = subdomain.length - domain.length - 1; return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain); } function isString2(value) { return typeof value === "string" || value instanceof String; } function isFunction2(value) { return typeof value === "function"; } function isBuffer2(value) { return typeof value === "object" && "length" in value; } function isURL(value) { return URL2 && value instanceof URL2; } module.exports = wrap({ http: http2, https: https2 }); module.exports.wrap = wrap; } }); // src/commands/tee/phala.ts import fs4 from "node:fs"; import os2 from "node:os"; // src/tee/phala/index.ts import * as crypto4 from "node:crypto"; import fs2 from "node:fs"; // ../../node_modules/@noble/hashes/esm/cryptoNode.js import * as nc from "node:crypto"; var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0; // ../../node_modules/@noble/hashes/esm/utils.js function randomBytes(bytesLength = 32) { if (crypto && typeof crypto.getRandomValues === "function") { return crypto.getRandomValues(new Uint8Array(byt