meshy-node 0.2.6 → 0.2.7
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 -3
- package/dashboard/assets/DashboardPage-ChA_y3oq.js +120 -0
- package/dashboard/assets/{DashboardShared-B08ZGEU3.js → DashboardShared-B4AJ8Ukj.js} +1 -1
- package/dashboard/assets/{DiffTab-D6XXV_vj.js → DiffTab-DgOYOCn1.js} +1 -1
- package/dashboard/assets/{FilesTab-DUebfVJo.js → FilesTab-Csi7UE5G.js} +1 -1
- package/dashboard/assets/{PreviewTab-CfNP0Ll3.js → PreviewTab-DT95fOD3.js} +1 -1
- package/dashboard/assets/{SharedConversationPage-D2ncPenP.js → SharedConversationPage-D5DMTSIy.js} +3 -3
- package/dashboard/assets/{file-C-p99c1E.js → file-BUN3RpOS.js} +1 -1
- package/dashboard/assets/{folder-C0oopt2q.js → folder-C28inzgP.js} +1 -1
- package/dashboard/assets/{index-B7PaE6U7.js → index-COwXI8L0.js} +2 -2
- package/dashboard/assets/{index-CxJE8HAC.css → index-tpSDJYRT.css} +1 -1
- package/dashboard/index.html +2 -2
- package/main.cjs +1896 -597
- package/package.json +1 -1
- package/runtime-metadata.json +5 -5
- package/dashboard/assets/DashboardPage-DeFE8aKR.js +0 -120
package/main.cjs
CHANGED
|
@@ -4303,12 +4303,12 @@ var require_supports_color = __commonJS({
|
|
|
4303
4303
|
"use strict";
|
|
4304
4304
|
var os6 = require("os");
|
|
4305
4305
|
var tty = require("tty");
|
|
4306
|
-
var
|
|
4306
|
+
var hasFlag2 = require_has_flag();
|
|
4307
4307
|
var { env } = process;
|
|
4308
4308
|
var forceColor;
|
|
4309
|
-
if (
|
|
4309
|
+
if (hasFlag2("no-color") || hasFlag2("no-colors") || hasFlag2("color=false") || hasFlag2("color=never")) {
|
|
4310
4310
|
forceColor = 0;
|
|
4311
|
-
} else if (
|
|
4311
|
+
} else if (hasFlag2("color") || hasFlag2("colors") || hasFlag2("color=true") || hasFlag2("color=always")) {
|
|
4312
4312
|
forceColor = 1;
|
|
4313
4313
|
}
|
|
4314
4314
|
if ("FORCE_COLOR" in env) {
|
|
@@ -4335,10 +4335,10 @@ var require_supports_color = __commonJS({
|
|
|
4335
4335
|
if (forceColor === 0) {
|
|
4336
4336
|
return 0;
|
|
4337
4337
|
}
|
|
4338
|
-
if (
|
|
4338
|
+
if (hasFlag2("color=16m") || hasFlag2("color=full") || hasFlag2("color=truecolor")) {
|
|
4339
4339
|
return 3;
|
|
4340
4340
|
}
|
|
4341
|
-
if (
|
|
4341
|
+
if (hasFlag2("color=256")) {
|
|
4342
4342
|
return 2;
|
|
4343
4343
|
}
|
|
4344
4344
|
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
@@ -4646,8 +4646,8 @@ var require_helpers = __commonJS({
|
|
|
4646
4646
|
function req(url, opts = {}) {
|
|
4647
4647
|
const href = typeof url === "string" ? url : url.href;
|
|
4648
4648
|
const req2 = (href.startsWith("https:") ? https2 : http3).request(url, opts);
|
|
4649
|
-
const promise = new Promise((
|
|
4650
|
-
req2.once("response",
|
|
4649
|
+
const promise = new Promise((resolve14, reject) => {
|
|
4650
|
+
req2.once("response", resolve14).once("error", reject).end();
|
|
4651
4651
|
});
|
|
4652
4652
|
req2.then = promise.then.bind(promise);
|
|
4653
4653
|
return req2;
|
|
@@ -4824,7 +4824,7 @@ var require_parse_proxy_response = __commonJS({
|
|
|
4824
4824
|
var debug_1 = __importDefault(require_src());
|
|
4825
4825
|
var debug = (0, debug_1.default)("https-proxy-agent:parse-proxy-response");
|
|
4826
4826
|
function parseProxyResponse(socket) {
|
|
4827
|
-
return new Promise((
|
|
4827
|
+
return new Promise((resolve14, reject) => {
|
|
4828
4828
|
let buffersLength = 0;
|
|
4829
4829
|
const buffers = [];
|
|
4830
4830
|
function read() {
|
|
@@ -4890,7 +4890,7 @@ var require_parse_proxy_response = __commonJS({
|
|
|
4890
4890
|
}
|
|
4891
4891
|
debug("got proxy server response: %o %o", firstLine, headers);
|
|
4892
4892
|
cleanup();
|
|
4893
|
-
|
|
4893
|
+
resolve14({
|
|
4894
4894
|
connect: {
|
|
4895
4895
|
statusCode,
|
|
4896
4896
|
statusText,
|
|
@@ -6629,8 +6629,8 @@ var require_node2 = __commonJS({
|
|
|
6629
6629
|
}
|
|
6630
6630
|
break;
|
|
6631
6631
|
case "FILE":
|
|
6632
|
-
var
|
|
6633
|
-
stream2 = new
|
|
6632
|
+
var fs20 = require("fs");
|
|
6633
|
+
stream2 = new fs20.SyncWriteStream(fd2, { autoClose: false });
|
|
6634
6634
|
stream2._type = "fs";
|
|
6635
6635
|
break;
|
|
6636
6636
|
case "PIPE":
|
|
@@ -10283,10 +10283,10 @@ var require_raw_body = __commonJS({
|
|
|
10283
10283
|
if (done) {
|
|
10284
10284
|
return readStream(stream, encoding, length, limit, wrap(done));
|
|
10285
10285
|
}
|
|
10286
|
-
return new Promise(function executor(
|
|
10286
|
+
return new Promise(function executor(resolve14, reject) {
|
|
10287
10287
|
readStream(stream, encoding, length, limit, function onRead(err, buf) {
|
|
10288
10288
|
if (err) return reject(err);
|
|
10289
|
-
|
|
10289
|
+
resolve14(buf);
|
|
10290
10290
|
});
|
|
10291
10291
|
});
|
|
10292
10292
|
}
|
|
@@ -19420,11 +19420,11 @@ var require_mime_types = __commonJS({
|
|
|
19420
19420
|
}
|
|
19421
19421
|
return exts[0];
|
|
19422
19422
|
}
|
|
19423
|
-
function lookup(
|
|
19424
|
-
if (!
|
|
19423
|
+
function lookup(path21) {
|
|
19424
|
+
if (!path21 || typeof path21 !== "string") {
|
|
19425
19425
|
return false;
|
|
19426
19426
|
}
|
|
19427
|
-
var extension2 = extname3("x." +
|
|
19427
|
+
var extension2 = extname3("x." + path21).toLowerCase().substr(1);
|
|
19428
19428
|
if (!extension2) {
|
|
19429
19429
|
return false;
|
|
19430
19430
|
}
|
|
@@ -22791,7 +22791,7 @@ var require_finalhandler = __commonJS({
|
|
|
22791
22791
|
} else {
|
|
22792
22792
|
headers = getErrorHeaders(err);
|
|
22793
22793
|
}
|
|
22794
|
-
msg =
|
|
22794
|
+
msg = getErrorMessage3(err, status, env);
|
|
22795
22795
|
} else {
|
|
22796
22796
|
status = 404;
|
|
22797
22797
|
msg = "Cannot " + req.method + " " + encodeUrl(getResourceName(req));
|
|
@@ -22822,7 +22822,7 @@ var require_finalhandler = __commonJS({
|
|
|
22822
22822
|
}
|
|
22823
22823
|
return headers;
|
|
22824
22824
|
}
|
|
22825
|
-
function
|
|
22825
|
+
function getErrorMessage3(err, status, env) {
|
|
22826
22826
|
var msg;
|
|
22827
22827
|
if (env !== "production") {
|
|
22828
22828
|
msg = err.stack;
|
|
@@ -22942,7 +22942,7 @@ var require_path_to_regexp = __commonJS({
|
|
|
22942
22942
|
"use strict";
|
|
22943
22943
|
module2.exports = pathToRegexp;
|
|
22944
22944
|
var MATCHING_GROUP_REGEXP = /\\.|\((?:\?<(.*?)>)?(?!\?)/g;
|
|
22945
|
-
function pathToRegexp(
|
|
22945
|
+
function pathToRegexp(path21, keys, options) {
|
|
22946
22946
|
options = options || {};
|
|
22947
22947
|
keys = keys || [];
|
|
22948
22948
|
var strict = options.strict;
|
|
@@ -22956,8 +22956,8 @@ var require_path_to_regexp = __commonJS({
|
|
|
22956
22956
|
var pos = 0;
|
|
22957
22957
|
var backtrack = "";
|
|
22958
22958
|
var m;
|
|
22959
|
-
if (
|
|
22960
|
-
while (m = MATCHING_GROUP_REGEXP.exec(
|
|
22959
|
+
if (path21 instanceof RegExp) {
|
|
22960
|
+
while (m = MATCHING_GROUP_REGEXP.exec(path21.source)) {
|
|
22961
22961
|
if (m[0][0] === "\\") continue;
|
|
22962
22962
|
keys.push({
|
|
22963
22963
|
name: m[1] || name2++,
|
|
@@ -22965,18 +22965,18 @@ var require_path_to_regexp = __commonJS({
|
|
|
22965
22965
|
offset: m.index
|
|
22966
22966
|
});
|
|
22967
22967
|
}
|
|
22968
|
-
return
|
|
22968
|
+
return path21;
|
|
22969
22969
|
}
|
|
22970
|
-
if (Array.isArray(
|
|
22971
|
-
|
|
22970
|
+
if (Array.isArray(path21)) {
|
|
22971
|
+
path21 = path21.map(function(value) {
|
|
22972
22972
|
return pathToRegexp(value, keys, options).source;
|
|
22973
22973
|
});
|
|
22974
|
-
return new RegExp(
|
|
22974
|
+
return new RegExp(path21.join("|"), flags);
|
|
22975
22975
|
}
|
|
22976
|
-
if (typeof
|
|
22976
|
+
if (typeof path21 !== "string") {
|
|
22977
22977
|
throw new TypeError("path must be a string, array of strings, or regular expression");
|
|
22978
22978
|
}
|
|
22979
|
-
|
|
22979
|
+
path21 = path21.replace(
|
|
22980
22980
|
/\\.|(\/)?(\.)?:(\w+)(\(.*?\))?(\*)?(\?)?|[.*]|\/\(/g,
|
|
22981
22981
|
function(match, slash, format, key, capture, star, optional, offset) {
|
|
22982
22982
|
if (match[0] === "\\") {
|
|
@@ -22993,7 +22993,7 @@ var require_path_to_regexp = __commonJS({
|
|
|
22993
22993
|
if (slash || format) {
|
|
22994
22994
|
backtrack = "";
|
|
22995
22995
|
} else {
|
|
22996
|
-
backtrack +=
|
|
22996
|
+
backtrack += path21.slice(pos, offset);
|
|
22997
22997
|
}
|
|
22998
22998
|
pos = offset + match.length;
|
|
22999
22999
|
if (match === "*") {
|
|
@@ -23023,7 +23023,7 @@ var require_path_to_regexp = __commonJS({
|
|
|
23023
23023
|
return result;
|
|
23024
23024
|
}
|
|
23025
23025
|
);
|
|
23026
|
-
while (m = MATCHING_GROUP_REGEXP.exec(
|
|
23026
|
+
while (m = MATCHING_GROUP_REGEXP.exec(path21)) {
|
|
23027
23027
|
if (m[0][0] === "\\") continue;
|
|
23028
23028
|
if (keysOffset + i === keys.length || keys[keysOffset + i].offset > m.index) {
|
|
23029
23029
|
keys.splice(keysOffset + i, 0, {
|
|
@@ -23035,13 +23035,13 @@ var require_path_to_regexp = __commonJS({
|
|
|
23035
23035
|
}
|
|
23036
23036
|
i++;
|
|
23037
23037
|
}
|
|
23038
|
-
|
|
23038
|
+
path21 += strict ? "" : path21[path21.length - 1] === "/" ? "?" : "/?";
|
|
23039
23039
|
if (end) {
|
|
23040
|
-
|
|
23041
|
-
} else if (
|
|
23042
|
-
|
|
23040
|
+
path21 += "$";
|
|
23041
|
+
} else if (path21[path21.length - 1] !== "/") {
|
|
23042
|
+
path21 += lookahead ? "(?=/|$)" : "(?:/|$)";
|
|
23043
23043
|
}
|
|
23044
|
-
return new RegExp("^" +
|
|
23044
|
+
return new RegExp("^" + path21, flags);
|
|
23045
23045
|
}
|
|
23046
23046
|
}
|
|
23047
23047
|
});
|
|
@@ -23054,19 +23054,19 @@ var require_layer = __commonJS({
|
|
|
23054
23054
|
var debug = require_src2()("express:router:layer");
|
|
23055
23055
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
23056
23056
|
module2.exports = Layer;
|
|
23057
|
-
function Layer(
|
|
23057
|
+
function Layer(path21, options, fn) {
|
|
23058
23058
|
if (!(this instanceof Layer)) {
|
|
23059
|
-
return new Layer(
|
|
23059
|
+
return new Layer(path21, options, fn);
|
|
23060
23060
|
}
|
|
23061
|
-
debug("new %o",
|
|
23061
|
+
debug("new %o", path21);
|
|
23062
23062
|
var opts = options || {};
|
|
23063
23063
|
this.handle = fn;
|
|
23064
23064
|
this.name = fn.name || "<anonymous>";
|
|
23065
23065
|
this.params = void 0;
|
|
23066
23066
|
this.path = void 0;
|
|
23067
|
-
this.regexp = pathRegexp(
|
|
23068
|
-
this.regexp.fast_star =
|
|
23069
|
-
this.regexp.fast_slash =
|
|
23067
|
+
this.regexp = pathRegexp(path21, this.keys = [], opts);
|
|
23068
|
+
this.regexp.fast_star = path21 === "*";
|
|
23069
|
+
this.regexp.fast_slash = path21 === "/" && opts.end === false;
|
|
23070
23070
|
}
|
|
23071
23071
|
Layer.prototype.handle_error = function handle_error(error, req, res, next) {
|
|
23072
23072
|
var fn = this.handle;
|
|
@@ -23090,20 +23090,20 @@ var require_layer = __commonJS({
|
|
|
23090
23090
|
next(err);
|
|
23091
23091
|
}
|
|
23092
23092
|
};
|
|
23093
|
-
Layer.prototype.match = function match(
|
|
23093
|
+
Layer.prototype.match = function match(path21) {
|
|
23094
23094
|
var match2;
|
|
23095
|
-
if (
|
|
23095
|
+
if (path21 != null) {
|
|
23096
23096
|
if (this.regexp.fast_slash) {
|
|
23097
23097
|
this.params = {};
|
|
23098
23098
|
this.path = "";
|
|
23099
23099
|
return true;
|
|
23100
23100
|
}
|
|
23101
23101
|
if (this.regexp.fast_star) {
|
|
23102
|
-
this.params = { "0": decode_param(
|
|
23103
|
-
this.path =
|
|
23102
|
+
this.params = { "0": decode_param(path21) };
|
|
23103
|
+
this.path = path21;
|
|
23104
23104
|
return true;
|
|
23105
23105
|
}
|
|
23106
|
-
match2 = this.regexp.exec(
|
|
23106
|
+
match2 = this.regexp.exec(path21);
|
|
23107
23107
|
}
|
|
23108
23108
|
if (!match2) {
|
|
23109
23109
|
this.params = void 0;
|
|
@@ -23196,10 +23196,10 @@ var require_route = __commonJS({
|
|
|
23196
23196
|
var slice = Array.prototype.slice;
|
|
23197
23197
|
var toString = Object.prototype.toString;
|
|
23198
23198
|
module2.exports = Route;
|
|
23199
|
-
function Route(
|
|
23200
|
-
this.path =
|
|
23199
|
+
function Route(path21) {
|
|
23200
|
+
this.path = path21;
|
|
23201
23201
|
this.stack = [];
|
|
23202
|
-
debug("new %o",
|
|
23202
|
+
debug("new %o", path21);
|
|
23203
23203
|
this.methods = {};
|
|
23204
23204
|
}
|
|
23205
23205
|
Route.prototype._handles_method = function _handles_method(method) {
|
|
@@ -23412,8 +23412,8 @@ var require_router = __commonJS({
|
|
|
23412
23412
|
if (++sync > 100) {
|
|
23413
23413
|
return setImmediate(next, err);
|
|
23414
23414
|
}
|
|
23415
|
-
var
|
|
23416
|
-
if (
|
|
23415
|
+
var path21 = getPathname(req);
|
|
23416
|
+
if (path21 == null) {
|
|
23417
23417
|
return done(layerError);
|
|
23418
23418
|
}
|
|
23419
23419
|
var layer;
|
|
@@ -23421,7 +23421,7 @@ var require_router = __commonJS({
|
|
|
23421
23421
|
var route;
|
|
23422
23422
|
while (match !== true && idx < stack.length) {
|
|
23423
23423
|
layer = stack[idx++];
|
|
23424
|
-
match = matchLayer(layer,
|
|
23424
|
+
match = matchLayer(layer, path21);
|
|
23425
23425
|
route = layer.route;
|
|
23426
23426
|
if (typeof match !== "boolean") {
|
|
23427
23427
|
layerError = layerError || match;
|
|
@@ -23459,18 +23459,18 @@ var require_router = __commonJS({
|
|
|
23459
23459
|
} else if (route) {
|
|
23460
23460
|
layer.handle_request(req, res, next);
|
|
23461
23461
|
} else {
|
|
23462
|
-
trim_prefix(layer, layerError, layerPath,
|
|
23462
|
+
trim_prefix(layer, layerError, layerPath, path21);
|
|
23463
23463
|
}
|
|
23464
23464
|
sync = 0;
|
|
23465
23465
|
});
|
|
23466
23466
|
}
|
|
23467
|
-
function trim_prefix(layer, layerError, layerPath,
|
|
23467
|
+
function trim_prefix(layer, layerError, layerPath, path21) {
|
|
23468
23468
|
if (layerPath.length !== 0) {
|
|
23469
|
-
if (layerPath !==
|
|
23469
|
+
if (layerPath !== path21.slice(0, layerPath.length)) {
|
|
23470
23470
|
next(layerError);
|
|
23471
23471
|
return;
|
|
23472
23472
|
}
|
|
23473
|
-
var c =
|
|
23473
|
+
var c = path21[layerPath.length];
|
|
23474
23474
|
if (c && c !== "/" && c !== ".") return next(layerError);
|
|
23475
23475
|
debug("trim prefix (%s) from url %s", layerPath, req.url);
|
|
23476
23476
|
removed = layerPath;
|
|
@@ -23548,7 +23548,7 @@ var require_router = __commonJS({
|
|
|
23548
23548
|
};
|
|
23549
23549
|
proto.use = function use(fn) {
|
|
23550
23550
|
var offset = 0;
|
|
23551
|
-
var
|
|
23551
|
+
var path21 = "/";
|
|
23552
23552
|
if (typeof fn !== "function") {
|
|
23553
23553
|
var arg = fn;
|
|
23554
23554
|
while (Array.isArray(arg) && arg.length !== 0) {
|
|
@@ -23556,7 +23556,7 @@ var require_router = __commonJS({
|
|
|
23556
23556
|
}
|
|
23557
23557
|
if (typeof arg !== "function") {
|
|
23558
23558
|
offset = 1;
|
|
23559
|
-
|
|
23559
|
+
path21 = fn;
|
|
23560
23560
|
}
|
|
23561
23561
|
}
|
|
23562
23562
|
var callbacks = flatten(slice.call(arguments, offset));
|
|
@@ -23568,8 +23568,8 @@ var require_router = __commonJS({
|
|
|
23568
23568
|
if (typeof fn !== "function") {
|
|
23569
23569
|
throw new TypeError("Router.use() requires a middleware function but got a " + gettype(fn));
|
|
23570
23570
|
}
|
|
23571
|
-
debug("use %o %s",
|
|
23572
|
-
var layer = new Layer(
|
|
23571
|
+
debug("use %o %s", path21, fn.name || "<anonymous>");
|
|
23572
|
+
var layer = new Layer(path21, {
|
|
23573
23573
|
sensitive: this.caseSensitive,
|
|
23574
23574
|
strict: false,
|
|
23575
23575
|
end: false
|
|
@@ -23579,9 +23579,9 @@ var require_router = __commonJS({
|
|
|
23579
23579
|
}
|
|
23580
23580
|
return this;
|
|
23581
23581
|
};
|
|
23582
|
-
proto.route = function route(
|
|
23583
|
-
var route2 = new Route(
|
|
23584
|
-
var layer = new Layer(
|
|
23582
|
+
proto.route = function route(path21) {
|
|
23583
|
+
var route2 = new Route(path21);
|
|
23584
|
+
var layer = new Layer(path21, {
|
|
23585
23585
|
sensitive: this.caseSensitive,
|
|
23586
23586
|
strict: this.strict,
|
|
23587
23587
|
end: true
|
|
@@ -23591,8 +23591,8 @@ var require_router = __commonJS({
|
|
|
23591
23591
|
return route2;
|
|
23592
23592
|
};
|
|
23593
23593
|
methods.concat("all").forEach(function(method) {
|
|
23594
|
-
proto[method] = function(
|
|
23595
|
-
var route = this.route(
|
|
23594
|
+
proto[method] = function(path21) {
|
|
23595
|
+
var route = this.route(path21);
|
|
23596
23596
|
route[method].apply(route, slice.call(arguments, 1));
|
|
23597
23597
|
return this;
|
|
23598
23598
|
};
|
|
@@ -23628,9 +23628,9 @@ var require_router = __commonJS({
|
|
|
23628
23628
|
}
|
|
23629
23629
|
return toString.call(obj).replace(objectRegExp, "$1");
|
|
23630
23630
|
}
|
|
23631
|
-
function matchLayer(layer,
|
|
23631
|
+
function matchLayer(layer, path21) {
|
|
23632
23632
|
try {
|
|
23633
|
-
return layer.match(
|
|
23633
|
+
return layer.match(path21);
|
|
23634
23634
|
} catch (err) {
|
|
23635
23635
|
return err;
|
|
23636
23636
|
}
|
|
@@ -23748,13 +23748,13 @@ var require_view = __commonJS({
|
|
|
23748
23748
|
"../../node_modules/.pnpm/express@4.22.1/node_modules/express/lib/view.js"(exports2, module2) {
|
|
23749
23749
|
"use strict";
|
|
23750
23750
|
var debug = require_src2()("express:view");
|
|
23751
|
-
var
|
|
23752
|
-
var
|
|
23753
|
-
var
|
|
23754
|
-
var basename3 =
|
|
23755
|
-
var extname3 =
|
|
23756
|
-
var
|
|
23757
|
-
var
|
|
23751
|
+
var path21 = require("path");
|
|
23752
|
+
var fs20 = require("fs");
|
|
23753
|
+
var dirname7 = path21.dirname;
|
|
23754
|
+
var basename3 = path21.basename;
|
|
23755
|
+
var extname3 = path21.extname;
|
|
23756
|
+
var join16 = path21.join;
|
|
23757
|
+
var resolve14 = path21.resolve;
|
|
23758
23758
|
module2.exports = View;
|
|
23759
23759
|
function View(name2, options) {
|
|
23760
23760
|
var opts = options || {};
|
|
@@ -23783,39 +23783,39 @@ var require_view = __commonJS({
|
|
|
23783
23783
|
this.path = this.lookup(fileName);
|
|
23784
23784
|
}
|
|
23785
23785
|
View.prototype.lookup = function lookup(name2) {
|
|
23786
|
-
var
|
|
23786
|
+
var path22;
|
|
23787
23787
|
var roots = [].concat(this.root);
|
|
23788
23788
|
debug('lookup "%s"', name2);
|
|
23789
|
-
for (var i = 0; i < roots.length && !
|
|
23789
|
+
for (var i = 0; i < roots.length && !path22; i++) {
|
|
23790
23790
|
var root = roots[i];
|
|
23791
|
-
var loc =
|
|
23792
|
-
var dir =
|
|
23791
|
+
var loc = resolve14(root, name2);
|
|
23792
|
+
var dir = dirname7(loc);
|
|
23793
23793
|
var file = basename3(loc);
|
|
23794
|
-
|
|
23794
|
+
path22 = this.resolve(dir, file);
|
|
23795
23795
|
}
|
|
23796
|
-
return
|
|
23796
|
+
return path22;
|
|
23797
23797
|
};
|
|
23798
23798
|
View.prototype.render = function render(options, callback) {
|
|
23799
23799
|
debug('render "%s"', this.path);
|
|
23800
23800
|
this.engine(this.path, options, callback);
|
|
23801
23801
|
};
|
|
23802
|
-
View.prototype.resolve = function
|
|
23802
|
+
View.prototype.resolve = function resolve15(dir, file) {
|
|
23803
23803
|
var ext = this.ext;
|
|
23804
|
-
var
|
|
23805
|
-
var stat = tryStat(
|
|
23804
|
+
var path22 = join16(dir, file);
|
|
23805
|
+
var stat = tryStat(path22);
|
|
23806
23806
|
if (stat && stat.isFile()) {
|
|
23807
|
-
return
|
|
23807
|
+
return path22;
|
|
23808
23808
|
}
|
|
23809
|
-
|
|
23810
|
-
stat = tryStat(
|
|
23809
|
+
path22 = join16(dir, basename3(file, ext), "index" + ext);
|
|
23810
|
+
stat = tryStat(path22);
|
|
23811
23811
|
if (stat && stat.isFile()) {
|
|
23812
|
-
return
|
|
23812
|
+
return path22;
|
|
23813
23813
|
}
|
|
23814
23814
|
};
|
|
23815
|
-
function tryStat(
|
|
23816
|
-
debug('stat "%s"',
|
|
23815
|
+
function tryStat(path22) {
|
|
23816
|
+
debug('stat "%s"', path22);
|
|
23817
23817
|
try {
|
|
23818
|
-
return
|
|
23818
|
+
return fs20.statSync(path22);
|
|
23819
23819
|
} catch (e) {
|
|
23820
23820
|
return void 0;
|
|
23821
23821
|
}
|
|
@@ -24112,8 +24112,8 @@ var require_types = __commonJS({
|
|
|
24112
24112
|
var require_mime = __commonJS({
|
|
24113
24113
|
"../../node_modules/.pnpm/mime@1.6.0/node_modules/mime/mime.js"(exports2, module2) {
|
|
24114
24114
|
"use strict";
|
|
24115
|
-
var
|
|
24116
|
-
var
|
|
24115
|
+
var path21 = require("path");
|
|
24116
|
+
var fs20 = require("fs");
|
|
24117
24117
|
function Mime() {
|
|
24118
24118
|
this.types = /* @__PURE__ */ Object.create(null);
|
|
24119
24119
|
this.extensions = /* @__PURE__ */ Object.create(null);
|
|
@@ -24134,7 +24134,7 @@ var require_mime = __commonJS({
|
|
|
24134
24134
|
};
|
|
24135
24135
|
Mime.prototype.load = function(file) {
|
|
24136
24136
|
this._loading = file;
|
|
24137
|
-
var map = {}, content =
|
|
24137
|
+
var map = {}, content = fs20.readFileSync(file, "ascii"), lines = content.split(/[\r\n]+/);
|
|
24138
24138
|
lines.forEach(function(line) {
|
|
24139
24139
|
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, "").split(/\s+/);
|
|
24140
24140
|
map[fields.shift()] = fields;
|
|
@@ -24142,8 +24142,8 @@ var require_mime = __commonJS({
|
|
|
24142
24142
|
this.define(map);
|
|
24143
24143
|
this._loading = null;
|
|
24144
24144
|
};
|
|
24145
|
-
Mime.prototype.lookup = function(
|
|
24146
|
-
var ext =
|
|
24145
|
+
Mime.prototype.lookup = function(path22, fallback) {
|
|
24146
|
+
var ext = path22.replace(/^.*[\.\/\\]/, "").toLowerCase();
|
|
24147
24147
|
return this.types[ext] || fallback || this.default_type;
|
|
24148
24148
|
};
|
|
24149
24149
|
Mime.prototype.extension = function(mimeType) {
|
|
@@ -24256,33 +24256,33 @@ var require_send = __commonJS({
|
|
|
24256
24256
|
var escapeHtml = require_escape_html();
|
|
24257
24257
|
var etag = require_etag();
|
|
24258
24258
|
var fresh = require_fresh();
|
|
24259
|
-
var
|
|
24259
|
+
var fs20 = require("fs");
|
|
24260
24260
|
var mime = require_mime();
|
|
24261
24261
|
var ms = require_ms();
|
|
24262
24262
|
var onFinished = require_on_finished();
|
|
24263
24263
|
var parseRange = require_range_parser();
|
|
24264
|
-
var
|
|
24264
|
+
var path21 = require("path");
|
|
24265
24265
|
var statuses = require_statuses();
|
|
24266
24266
|
var Stream = require("stream");
|
|
24267
24267
|
var util3 = require("util");
|
|
24268
|
-
var extname3 =
|
|
24269
|
-
var
|
|
24270
|
-
var normalize =
|
|
24271
|
-
var
|
|
24272
|
-
var sep3 =
|
|
24268
|
+
var extname3 = path21.extname;
|
|
24269
|
+
var join16 = path21.join;
|
|
24270
|
+
var normalize = path21.normalize;
|
|
24271
|
+
var resolve14 = path21.resolve;
|
|
24272
|
+
var sep3 = path21.sep;
|
|
24273
24273
|
var BYTES_RANGE_REGEXP = /^ *bytes=/;
|
|
24274
24274
|
var MAX_MAXAGE = 60 * 60 * 24 * 365 * 1e3;
|
|
24275
24275
|
var UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
|
|
24276
24276
|
module2.exports = send;
|
|
24277
24277
|
module2.exports.mime = mime;
|
|
24278
|
-
function send(req,
|
|
24279
|
-
return new SendStream(req,
|
|
24278
|
+
function send(req, path22, options) {
|
|
24279
|
+
return new SendStream(req, path22, options);
|
|
24280
24280
|
}
|
|
24281
|
-
function SendStream(req,
|
|
24281
|
+
function SendStream(req, path22, options) {
|
|
24282
24282
|
Stream.call(this);
|
|
24283
24283
|
var opts = options || {};
|
|
24284
24284
|
this.options = opts;
|
|
24285
|
-
this.path =
|
|
24285
|
+
this.path = path22;
|
|
24286
24286
|
this.req = req;
|
|
24287
24287
|
this._acceptRanges = opts.acceptRanges !== void 0 ? Boolean(opts.acceptRanges) : true;
|
|
24288
24288
|
this._cacheControl = opts.cacheControl !== void 0 ? Boolean(opts.cacheControl) : true;
|
|
@@ -24305,7 +24305,7 @@ var require_send = __commonJS({
|
|
|
24305
24305
|
this._maxage = opts.maxAge || opts.maxage;
|
|
24306
24306
|
this._maxage = typeof this._maxage === "string" ? ms(this._maxage) : Number(this._maxage);
|
|
24307
24307
|
this._maxage = !isNaN(this._maxage) ? Math.min(Math.max(0, this._maxage), MAX_MAXAGE) : 0;
|
|
24308
|
-
this._root = opts.root ?
|
|
24308
|
+
this._root = opts.root ? resolve14(opts.root) : null;
|
|
24309
24309
|
if (!this._root && opts.from) {
|
|
24310
24310
|
this.from(opts.from);
|
|
24311
24311
|
}
|
|
@@ -24328,8 +24328,8 @@ var require_send = __commonJS({
|
|
|
24328
24328
|
this._index = index2;
|
|
24329
24329
|
return this;
|
|
24330
24330
|
}, "send.index: pass index as option");
|
|
24331
|
-
SendStream.prototype.root = function root(
|
|
24332
|
-
this._root =
|
|
24331
|
+
SendStream.prototype.root = function root(path22) {
|
|
24332
|
+
this._root = resolve14(String(path22));
|
|
24333
24333
|
debug("root %s", this._root);
|
|
24334
24334
|
return this;
|
|
24335
24335
|
};
|
|
@@ -24442,10 +24442,10 @@ var require_send = __commonJS({
|
|
|
24442
24442
|
var lastModified = this.res.getHeader("Last-Modified");
|
|
24443
24443
|
return parseHttpDate(lastModified) <= parseHttpDate(ifRange);
|
|
24444
24444
|
};
|
|
24445
|
-
SendStream.prototype.redirect = function redirect(
|
|
24445
|
+
SendStream.prototype.redirect = function redirect(path22) {
|
|
24446
24446
|
var res = this.res;
|
|
24447
24447
|
if (hasListeners(this, "directory")) {
|
|
24448
|
-
this.emit("directory", res,
|
|
24448
|
+
this.emit("directory", res, path22);
|
|
24449
24449
|
return;
|
|
24450
24450
|
}
|
|
24451
24451
|
if (this.hasTrailingSlash()) {
|
|
@@ -24465,42 +24465,42 @@ var require_send = __commonJS({
|
|
|
24465
24465
|
SendStream.prototype.pipe = function pipe(res) {
|
|
24466
24466
|
var root = this._root;
|
|
24467
24467
|
this.res = res;
|
|
24468
|
-
var
|
|
24469
|
-
if (
|
|
24468
|
+
var path22 = decode(this.path);
|
|
24469
|
+
if (path22 === -1) {
|
|
24470
24470
|
this.error(400);
|
|
24471
24471
|
return res;
|
|
24472
24472
|
}
|
|
24473
|
-
if (~
|
|
24473
|
+
if (~path22.indexOf("\0")) {
|
|
24474
24474
|
this.error(400);
|
|
24475
24475
|
return res;
|
|
24476
24476
|
}
|
|
24477
24477
|
var parts;
|
|
24478
24478
|
if (root !== null) {
|
|
24479
|
-
if (
|
|
24480
|
-
|
|
24479
|
+
if (path22) {
|
|
24480
|
+
path22 = normalize("." + sep3 + path22);
|
|
24481
24481
|
}
|
|
24482
|
-
if (UP_PATH_REGEXP.test(
|
|
24483
|
-
debug('malicious path "%s"',
|
|
24482
|
+
if (UP_PATH_REGEXP.test(path22)) {
|
|
24483
|
+
debug('malicious path "%s"', path22);
|
|
24484
24484
|
this.error(403);
|
|
24485
24485
|
return res;
|
|
24486
24486
|
}
|
|
24487
|
-
parts =
|
|
24488
|
-
|
|
24487
|
+
parts = path22.split(sep3);
|
|
24488
|
+
path22 = normalize(join16(root, path22));
|
|
24489
24489
|
} else {
|
|
24490
|
-
if (UP_PATH_REGEXP.test(
|
|
24491
|
-
debug('malicious path "%s"',
|
|
24490
|
+
if (UP_PATH_REGEXP.test(path22)) {
|
|
24491
|
+
debug('malicious path "%s"', path22);
|
|
24492
24492
|
this.error(403);
|
|
24493
24493
|
return res;
|
|
24494
24494
|
}
|
|
24495
|
-
parts = normalize(
|
|
24496
|
-
|
|
24495
|
+
parts = normalize(path22).split(sep3);
|
|
24496
|
+
path22 = resolve14(path22);
|
|
24497
24497
|
}
|
|
24498
24498
|
if (containsDotFile(parts)) {
|
|
24499
24499
|
var access = this._dotfiles;
|
|
24500
24500
|
if (access === void 0) {
|
|
24501
24501
|
access = parts[parts.length - 1][0] === "." ? this._hidden ? "allow" : "ignore" : "allow";
|
|
24502
24502
|
}
|
|
24503
|
-
debug('%s dotfile "%s"', access,
|
|
24503
|
+
debug('%s dotfile "%s"', access, path22);
|
|
24504
24504
|
switch (access) {
|
|
24505
24505
|
case "allow":
|
|
24506
24506
|
break;
|
|
@@ -24514,13 +24514,13 @@ var require_send = __commonJS({
|
|
|
24514
24514
|
}
|
|
24515
24515
|
}
|
|
24516
24516
|
if (this._index.length && this.hasTrailingSlash()) {
|
|
24517
|
-
this.sendIndex(
|
|
24517
|
+
this.sendIndex(path22);
|
|
24518
24518
|
return res;
|
|
24519
24519
|
}
|
|
24520
|
-
this.sendFile(
|
|
24520
|
+
this.sendFile(path22);
|
|
24521
24521
|
return res;
|
|
24522
24522
|
};
|
|
24523
|
-
SendStream.prototype.send = function send2(
|
|
24523
|
+
SendStream.prototype.send = function send2(path22, stat) {
|
|
24524
24524
|
var len = stat.size;
|
|
24525
24525
|
var options = this.options;
|
|
24526
24526
|
var opts = {};
|
|
@@ -24532,9 +24532,9 @@ var require_send = __commonJS({
|
|
|
24532
24532
|
this.headersAlreadySent();
|
|
24533
24533
|
return;
|
|
24534
24534
|
}
|
|
24535
|
-
debug('pipe "%s"',
|
|
24536
|
-
this.setHeader(
|
|
24537
|
-
this.type(
|
|
24535
|
+
debug('pipe "%s"', path22);
|
|
24536
|
+
this.setHeader(path22, stat);
|
|
24537
|
+
this.type(path22);
|
|
24538
24538
|
if (this.isConditionalGET()) {
|
|
24539
24539
|
if (this.isPreconditionFailure()) {
|
|
24540
24540
|
this.error(412);
|
|
@@ -24583,28 +24583,28 @@ var require_send = __commonJS({
|
|
|
24583
24583
|
res.end();
|
|
24584
24584
|
return;
|
|
24585
24585
|
}
|
|
24586
|
-
this.stream(
|
|
24586
|
+
this.stream(path22, opts);
|
|
24587
24587
|
};
|
|
24588
|
-
SendStream.prototype.sendFile = function sendFile(
|
|
24588
|
+
SendStream.prototype.sendFile = function sendFile(path22) {
|
|
24589
24589
|
var i = 0;
|
|
24590
24590
|
var self2 = this;
|
|
24591
|
-
debug('stat "%s"',
|
|
24592
|
-
|
|
24593
|
-
if (err && err.code === "ENOENT" && !extname3(
|
|
24591
|
+
debug('stat "%s"', path22);
|
|
24592
|
+
fs20.stat(path22, function onstat(err, stat) {
|
|
24593
|
+
if (err && err.code === "ENOENT" && !extname3(path22) && path22[path22.length - 1] !== sep3) {
|
|
24594
24594
|
return next(err);
|
|
24595
24595
|
}
|
|
24596
24596
|
if (err) return self2.onStatError(err);
|
|
24597
|
-
if (stat.isDirectory()) return self2.redirect(
|
|
24598
|
-
self2.emit("file",
|
|
24599
|
-
self2.send(
|
|
24597
|
+
if (stat.isDirectory()) return self2.redirect(path22);
|
|
24598
|
+
self2.emit("file", path22, stat);
|
|
24599
|
+
self2.send(path22, stat);
|
|
24600
24600
|
});
|
|
24601
24601
|
function next(err) {
|
|
24602
24602
|
if (self2._extensions.length <= i) {
|
|
24603
24603
|
return err ? self2.onStatError(err) : self2.error(404);
|
|
24604
24604
|
}
|
|
24605
|
-
var p =
|
|
24605
|
+
var p = path22 + "." + self2._extensions[i++];
|
|
24606
24606
|
debug('stat "%s"', p);
|
|
24607
|
-
|
|
24607
|
+
fs20.stat(p, function(err2, stat) {
|
|
24608
24608
|
if (err2) return next(err2);
|
|
24609
24609
|
if (stat.isDirectory()) return next();
|
|
24610
24610
|
self2.emit("file", p, stat);
|
|
@@ -24612,7 +24612,7 @@ var require_send = __commonJS({
|
|
|
24612
24612
|
});
|
|
24613
24613
|
}
|
|
24614
24614
|
};
|
|
24615
|
-
SendStream.prototype.sendIndex = function sendIndex(
|
|
24615
|
+
SendStream.prototype.sendIndex = function sendIndex(path22) {
|
|
24616
24616
|
var i = -1;
|
|
24617
24617
|
var self2 = this;
|
|
24618
24618
|
function next(err) {
|
|
@@ -24620,9 +24620,9 @@ var require_send = __commonJS({
|
|
|
24620
24620
|
if (err) return self2.onStatError(err);
|
|
24621
24621
|
return self2.error(404);
|
|
24622
24622
|
}
|
|
24623
|
-
var p =
|
|
24623
|
+
var p = join16(path22, self2._index[i]);
|
|
24624
24624
|
debug('stat "%s"', p);
|
|
24625
|
-
|
|
24625
|
+
fs20.stat(p, function(err2, stat) {
|
|
24626
24626
|
if (err2) return next(err2);
|
|
24627
24627
|
if (stat.isDirectory()) return next();
|
|
24628
24628
|
self2.emit("file", p, stat);
|
|
@@ -24631,10 +24631,10 @@ var require_send = __commonJS({
|
|
|
24631
24631
|
}
|
|
24632
24632
|
next();
|
|
24633
24633
|
};
|
|
24634
|
-
SendStream.prototype.stream = function stream(
|
|
24634
|
+
SendStream.prototype.stream = function stream(path22, options) {
|
|
24635
24635
|
var self2 = this;
|
|
24636
24636
|
var res = this.res;
|
|
24637
|
-
var stream2 =
|
|
24637
|
+
var stream2 = fs20.createReadStream(path22, options);
|
|
24638
24638
|
this.emit("stream", stream2);
|
|
24639
24639
|
stream2.pipe(res);
|
|
24640
24640
|
function cleanup() {
|
|
@@ -24649,10 +24649,10 @@ var require_send = __commonJS({
|
|
|
24649
24649
|
self2.emit("end");
|
|
24650
24650
|
});
|
|
24651
24651
|
};
|
|
24652
|
-
SendStream.prototype.type = function type(
|
|
24652
|
+
SendStream.prototype.type = function type(path22) {
|
|
24653
24653
|
var res = this.res;
|
|
24654
24654
|
if (res.getHeader("Content-Type")) return;
|
|
24655
|
-
var type2 = mime.lookup(
|
|
24655
|
+
var type2 = mime.lookup(path22);
|
|
24656
24656
|
if (!type2) {
|
|
24657
24657
|
debug("no content-type");
|
|
24658
24658
|
return;
|
|
@@ -24661,9 +24661,9 @@ var require_send = __commonJS({
|
|
|
24661
24661
|
debug("content-type %s", type2);
|
|
24662
24662
|
res.setHeader("Content-Type", type2 + (charset ? "; charset=" + charset : ""));
|
|
24663
24663
|
};
|
|
24664
|
-
SendStream.prototype.setHeader = function setHeader(
|
|
24664
|
+
SendStream.prototype.setHeader = function setHeader(path22, stat) {
|
|
24665
24665
|
var res = this.res;
|
|
24666
|
-
this.emit("headers", res,
|
|
24666
|
+
this.emit("headers", res, path22, stat);
|
|
24667
24667
|
if (this._acceptRanges && !res.getHeader("Accept-Ranges")) {
|
|
24668
24668
|
debug("accept ranges");
|
|
24669
24669
|
res.setHeader("Accept-Ranges", "bytes");
|
|
@@ -24722,9 +24722,9 @@ var require_send = __commonJS({
|
|
|
24722
24722
|
}
|
|
24723
24723
|
return err instanceof Error ? createError(status, err, { expose: false }) : createError(status, err);
|
|
24724
24724
|
}
|
|
24725
|
-
function decode(
|
|
24725
|
+
function decode(path22) {
|
|
24726
24726
|
try {
|
|
24727
|
-
return decodeURIComponent(
|
|
24727
|
+
return decodeURIComponent(path22);
|
|
24728
24728
|
} catch (err) {
|
|
24729
24729
|
return -1;
|
|
24730
24730
|
}
|
|
@@ -25634,10 +25634,10 @@ var require_utils2 = __commonJS({
|
|
|
25634
25634
|
var querystring = require("querystring");
|
|
25635
25635
|
exports2.etag = createETagGenerator({ weak: false });
|
|
25636
25636
|
exports2.wetag = createETagGenerator({ weak: true });
|
|
25637
|
-
exports2.isAbsolute = function(
|
|
25638
|
-
if ("/" ===
|
|
25639
|
-
if (":" ===
|
|
25640
|
-
if ("\\\\" ===
|
|
25637
|
+
exports2.isAbsolute = function(path21) {
|
|
25638
|
+
if ("/" === path21[0]) return true;
|
|
25639
|
+
if (":" === path21[1] && ("\\" === path21[2] || "/" === path21[2])) return true;
|
|
25640
|
+
if ("\\\\" === path21.substring(0, 2)) return true;
|
|
25641
25641
|
};
|
|
25642
25642
|
exports2.flatten = deprecate.function(
|
|
25643
25643
|
flatten,
|
|
@@ -25773,7 +25773,7 @@ var require_application = __commonJS({
|
|
|
25773
25773
|
var deprecate = require_depd()("express");
|
|
25774
25774
|
var flatten = require_array_flatten();
|
|
25775
25775
|
var merge = require_utils_merge();
|
|
25776
|
-
var
|
|
25776
|
+
var resolve14 = require("path").resolve;
|
|
25777
25777
|
var setPrototypeOf = require_setprototypeof();
|
|
25778
25778
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
25779
25779
|
var slice = Array.prototype.slice;
|
|
@@ -25812,7 +25812,7 @@ var require_application = __commonJS({
|
|
|
25812
25812
|
this.mountpath = "/";
|
|
25813
25813
|
this.locals.settings = this.settings;
|
|
25814
25814
|
this.set("view", View);
|
|
25815
|
-
this.set("views",
|
|
25815
|
+
this.set("views", resolve14("views"));
|
|
25816
25816
|
this.set("jsonp callback name", "callback");
|
|
25817
25817
|
if (env === "production") {
|
|
25818
25818
|
this.enable("view cache");
|
|
@@ -25848,7 +25848,7 @@ var require_application = __commonJS({
|
|
|
25848
25848
|
};
|
|
25849
25849
|
app.use = function use(fn) {
|
|
25850
25850
|
var offset = 0;
|
|
25851
|
-
var
|
|
25851
|
+
var path21 = "/";
|
|
25852
25852
|
if (typeof fn !== "function") {
|
|
25853
25853
|
var arg = fn;
|
|
25854
25854
|
while (Array.isArray(arg) && arg.length !== 0) {
|
|
@@ -25856,7 +25856,7 @@ var require_application = __commonJS({
|
|
|
25856
25856
|
}
|
|
25857
25857
|
if (typeof arg !== "function") {
|
|
25858
25858
|
offset = 1;
|
|
25859
|
-
|
|
25859
|
+
path21 = fn;
|
|
25860
25860
|
}
|
|
25861
25861
|
}
|
|
25862
25862
|
var fns = flatten(slice.call(arguments, offset));
|
|
@@ -25867,12 +25867,12 @@ var require_application = __commonJS({
|
|
|
25867
25867
|
var router = this._router;
|
|
25868
25868
|
fns.forEach(function(fn2) {
|
|
25869
25869
|
if (!fn2 || !fn2.handle || !fn2.set) {
|
|
25870
|
-
return router.use(
|
|
25870
|
+
return router.use(path21, fn2);
|
|
25871
25871
|
}
|
|
25872
|
-
debug(".use app under %s",
|
|
25873
|
-
fn2.mountpath =
|
|
25872
|
+
debug(".use app under %s", path21);
|
|
25873
|
+
fn2.mountpath = path21;
|
|
25874
25874
|
fn2.parent = this;
|
|
25875
|
-
router.use(
|
|
25875
|
+
router.use(path21, function mounted_app(req, res, next) {
|
|
25876
25876
|
var orig = req.app;
|
|
25877
25877
|
fn2.handle(req, res, function(err) {
|
|
25878
25878
|
setPrototypeOf(req, orig.request);
|
|
@@ -25884,9 +25884,9 @@ var require_application = __commonJS({
|
|
|
25884
25884
|
}, this);
|
|
25885
25885
|
return this;
|
|
25886
25886
|
};
|
|
25887
|
-
app.route = function route(
|
|
25887
|
+
app.route = function route(path21) {
|
|
25888
25888
|
this.lazyrouter();
|
|
25889
|
-
return this._router.route(
|
|
25889
|
+
return this._router.route(path21);
|
|
25890
25890
|
};
|
|
25891
25891
|
app.engine = function engine(ext, fn) {
|
|
25892
25892
|
if (typeof fn !== "function") {
|
|
@@ -25937,7 +25937,7 @@ var require_application = __commonJS({
|
|
|
25937
25937
|
}
|
|
25938
25938
|
return this;
|
|
25939
25939
|
};
|
|
25940
|
-
app.path = function
|
|
25940
|
+
app.path = function path21() {
|
|
25941
25941
|
return this.parent ? this.parent.path() + this.mountpath : "";
|
|
25942
25942
|
};
|
|
25943
25943
|
app.enabled = function enabled2(setting) {
|
|
@@ -25953,19 +25953,19 @@ var require_application = __commonJS({
|
|
|
25953
25953
|
return this.set(setting, false);
|
|
25954
25954
|
};
|
|
25955
25955
|
methods.forEach(function(method) {
|
|
25956
|
-
app[method] = function(
|
|
25956
|
+
app[method] = function(path21) {
|
|
25957
25957
|
if (method === "get" && arguments.length === 1) {
|
|
25958
|
-
return this.set(
|
|
25958
|
+
return this.set(path21);
|
|
25959
25959
|
}
|
|
25960
25960
|
this.lazyrouter();
|
|
25961
|
-
var route = this._router.route(
|
|
25961
|
+
var route = this._router.route(path21);
|
|
25962
25962
|
route[method].apply(route, slice.call(arguments, 1));
|
|
25963
25963
|
return this;
|
|
25964
25964
|
};
|
|
25965
25965
|
});
|
|
25966
|
-
app.all = function all(
|
|
25966
|
+
app.all = function all(path21) {
|
|
25967
25967
|
this.lazyrouter();
|
|
25968
|
-
var route = this._router.route(
|
|
25968
|
+
var route = this._router.route(path21);
|
|
25969
25969
|
var args = slice.call(arguments, 1);
|
|
25970
25970
|
for (var i = 0; i < methods.length; i++) {
|
|
25971
25971
|
route[methods[i]].apply(route, args);
|
|
@@ -26724,7 +26724,7 @@ var require_request = __commonJS({
|
|
|
26724
26724
|
var subdomains2 = !isIP(hostname3) ? hostname3.split(".").reverse() : [hostname3];
|
|
26725
26725
|
return subdomains2.slice(offset);
|
|
26726
26726
|
});
|
|
26727
|
-
defineGetter(req, "path", function
|
|
26727
|
+
defineGetter(req, "path", function path21() {
|
|
26728
26728
|
return parse(this).pathname;
|
|
26729
26729
|
});
|
|
26730
26730
|
defineGetter(req, "hostname", function hostname3() {
|
|
@@ -27047,7 +27047,7 @@ var require_response = __commonJS({
|
|
|
27047
27047
|
var http3 = require("http");
|
|
27048
27048
|
var isAbsolute4 = require_utils2().isAbsolute;
|
|
27049
27049
|
var onFinished = require_on_finished();
|
|
27050
|
-
var
|
|
27050
|
+
var path21 = require("path");
|
|
27051
27051
|
var statuses = require_statuses();
|
|
27052
27052
|
var merge = require_utils_merge();
|
|
27053
27053
|
var sign = require_cookie_signature().sign;
|
|
@@ -27056,9 +27056,9 @@ var require_response = __commonJS({
|
|
|
27056
27056
|
var setCharset = require_utils2().setCharset;
|
|
27057
27057
|
var cookie = require_cookie();
|
|
27058
27058
|
var send = require_send();
|
|
27059
|
-
var extname3 =
|
|
27059
|
+
var extname3 = path21.extname;
|
|
27060
27060
|
var mime = send.mime;
|
|
27061
|
-
var
|
|
27061
|
+
var resolve14 = path21.resolve;
|
|
27062
27062
|
var vary = require_vary();
|
|
27063
27063
|
var res = Object.create(http3.ServerResponse.prototype);
|
|
27064
27064
|
module2.exports = res;
|
|
@@ -27235,26 +27235,26 @@ var require_response = __commonJS({
|
|
|
27235
27235
|
this.type("txt");
|
|
27236
27236
|
return this.send(body);
|
|
27237
27237
|
};
|
|
27238
|
-
res.sendFile = function sendFile(
|
|
27238
|
+
res.sendFile = function sendFile(path22, options, callback) {
|
|
27239
27239
|
var done = callback;
|
|
27240
27240
|
var req = this.req;
|
|
27241
27241
|
var res2 = this;
|
|
27242
27242
|
var next = req.next;
|
|
27243
27243
|
var opts = options || {};
|
|
27244
|
-
if (!
|
|
27244
|
+
if (!path22) {
|
|
27245
27245
|
throw new TypeError("path argument is required to res.sendFile");
|
|
27246
27246
|
}
|
|
27247
|
-
if (typeof
|
|
27247
|
+
if (typeof path22 !== "string") {
|
|
27248
27248
|
throw new TypeError("path must be a string to res.sendFile");
|
|
27249
27249
|
}
|
|
27250
27250
|
if (typeof options === "function") {
|
|
27251
27251
|
done = options;
|
|
27252
27252
|
opts = {};
|
|
27253
27253
|
}
|
|
27254
|
-
if (!opts.root && !isAbsolute4(
|
|
27254
|
+
if (!opts.root && !isAbsolute4(path22)) {
|
|
27255
27255
|
throw new TypeError("path must be absolute or specify root to res.sendFile");
|
|
27256
27256
|
}
|
|
27257
|
-
var pathname = encodeURI(
|
|
27257
|
+
var pathname = encodeURI(path22);
|
|
27258
27258
|
var file = send(req, pathname, opts);
|
|
27259
27259
|
sendfile(res2, file, opts, function(err) {
|
|
27260
27260
|
if (done) return done(err);
|
|
@@ -27264,7 +27264,7 @@ var require_response = __commonJS({
|
|
|
27264
27264
|
}
|
|
27265
27265
|
});
|
|
27266
27266
|
};
|
|
27267
|
-
res.sendfile = function(
|
|
27267
|
+
res.sendfile = function(path22, options, callback) {
|
|
27268
27268
|
var done = callback;
|
|
27269
27269
|
var req = this.req;
|
|
27270
27270
|
var res2 = this;
|
|
@@ -27274,7 +27274,7 @@ var require_response = __commonJS({
|
|
|
27274
27274
|
done = options;
|
|
27275
27275
|
opts = {};
|
|
27276
27276
|
}
|
|
27277
|
-
var file = send(req,
|
|
27277
|
+
var file = send(req, path22, opts);
|
|
27278
27278
|
sendfile(res2, file, opts, function(err) {
|
|
27279
27279
|
if (done) return done(err);
|
|
27280
27280
|
if (err && err.code === "EISDIR") return next();
|
|
@@ -27287,7 +27287,7 @@ var require_response = __commonJS({
|
|
|
27287
27287
|
res.sendfile,
|
|
27288
27288
|
"res.sendfile: Use res.sendFile instead"
|
|
27289
27289
|
);
|
|
27290
|
-
res.download = function download(
|
|
27290
|
+
res.download = function download(path22, filename, options, callback) {
|
|
27291
27291
|
var done = callback;
|
|
27292
27292
|
var name2 = filename;
|
|
27293
27293
|
var opts = options || null;
|
|
@@ -27304,7 +27304,7 @@ var require_response = __commonJS({
|
|
|
27304
27304
|
opts = filename;
|
|
27305
27305
|
}
|
|
27306
27306
|
var headers = {
|
|
27307
|
-
"Content-Disposition": contentDisposition(name2 ||
|
|
27307
|
+
"Content-Disposition": contentDisposition(name2 || path22)
|
|
27308
27308
|
};
|
|
27309
27309
|
if (opts && opts.headers) {
|
|
27310
27310
|
var keys = Object.keys(opts.headers);
|
|
@@ -27317,7 +27317,7 @@ var require_response = __commonJS({
|
|
|
27317
27317
|
}
|
|
27318
27318
|
opts = Object.create(opts);
|
|
27319
27319
|
opts.headers = headers;
|
|
27320
|
-
var fullPath = !opts.root ?
|
|
27320
|
+
var fullPath = !opts.root ? resolve14(path22) : path22;
|
|
27321
27321
|
return this.sendFile(fullPath, opts, done);
|
|
27322
27322
|
};
|
|
27323
27323
|
res.contentType = res.type = function contentType(type) {
|
|
@@ -27583,7 +27583,7 @@ var require_serve_static = __commonJS({
|
|
|
27583
27583
|
var encodeUrl = require_encodeurl();
|
|
27584
27584
|
var escapeHtml = require_escape_html();
|
|
27585
27585
|
var parseUrl = require_parseurl();
|
|
27586
|
-
var
|
|
27586
|
+
var resolve14 = require("path").resolve;
|
|
27587
27587
|
var send = require_send();
|
|
27588
27588
|
var url = require("url");
|
|
27589
27589
|
module2.exports = serveStatic;
|
|
@@ -27603,7 +27603,7 @@ var require_serve_static = __commonJS({
|
|
|
27603
27603
|
throw new TypeError("option setHeaders must be function");
|
|
27604
27604
|
}
|
|
27605
27605
|
opts.maxage = opts.maxage || opts.maxAge || 0;
|
|
27606
|
-
opts.root =
|
|
27606
|
+
opts.root = resolve14(root);
|
|
27607
27607
|
var onDirectory = redirect ? createRedirectDirectoryListener() : createNotFoundDirectoryListener();
|
|
27608
27608
|
return function serveStatic2(req, res, next) {
|
|
27609
27609
|
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
@@ -27618,11 +27618,11 @@ var require_serve_static = __commonJS({
|
|
|
27618
27618
|
}
|
|
27619
27619
|
var forwardError = !fallthrough;
|
|
27620
27620
|
var originalUrl = parseUrl.original(req);
|
|
27621
|
-
var
|
|
27622
|
-
if (
|
|
27623
|
-
|
|
27621
|
+
var path21 = parseUrl(req).pathname;
|
|
27622
|
+
if (path21 === "/" && originalUrl.pathname.substr(-1) !== "/") {
|
|
27623
|
+
path21 = "";
|
|
27624
27624
|
}
|
|
27625
|
-
var stream = send(req,
|
|
27625
|
+
var stream = send(req, path21, opts);
|
|
27626
27626
|
stream.on("directory", onDirectory);
|
|
27627
27627
|
if (setHeaders) {
|
|
27628
27628
|
stream.on("headers", setHeaders);
|
|
@@ -27765,10 +27765,14 @@ __export(main_exports, {
|
|
|
27765
27765
|
DEFAULT_NODE_NAME: () => DEFAULT_NODE_NAME,
|
|
27766
27766
|
DEFAULT_NODE_PORT: () => DEFAULT_NODE_PORT,
|
|
27767
27767
|
applyStartMetadata: () => applyStartMetadata,
|
|
27768
|
+
closeHttpServer: () => closeHttpServer,
|
|
27768
27769
|
createDefaultConfig: () => createDefaultConfig,
|
|
27769
27770
|
createRuntimeDefaultConfig: () => createRuntimeDefaultConfig,
|
|
27770
27771
|
ensureStartupRequirements: () => ensureStartupRequirements,
|
|
27771
27772
|
formatBanner: () => formatBanner,
|
|
27773
|
+
formatFatalErrorForConsole: () => formatFatalErrorForConsole,
|
|
27774
|
+
formatFatalErrorForLog: () => formatFatalErrorForLog,
|
|
27775
|
+
formatHelp: () => formatHelp,
|
|
27772
27776
|
formatLoadedStartMetadata: () => formatLoadedStartMetadata,
|
|
27773
27777
|
getDefaultNodeName: () => getDefaultNodeName,
|
|
27774
27778
|
isDirectRunPath: () => isDirectRunPath,
|
|
@@ -27781,10 +27785,257 @@ __export(main_exports, {
|
|
|
27781
27785
|
resolveStartupRequirementsMetadata: () => resolveStartupRequirementsMetadata,
|
|
27782
27786
|
shouldCollectStartOptions: () => shouldCollectStartOptions,
|
|
27783
27787
|
shouldPromptForStartOptions: () => shouldPromptForStartOptions,
|
|
27784
|
-
shouldSkipStartupRequirementsCheck: () => shouldSkipStartupRequirementsCheck
|
|
27788
|
+
shouldSkipStartupRequirementsCheck: () => shouldSkipStartupRequirementsCheck,
|
|
27789
|
+
startNode: () => startNode
|
|
27785
27790
|
});
|
|
27786
27791
|
module.exports = __toCommonJS(main_exports);
|
|
27787
|
-
|
|
27792
|
+
|
|
27793
|
+
// ../../packages/cli/src/args.ts
|
|
27794
|
+
var DEFAULT_NODE_PORT = 12345;
|
|
27795
|
+
var KNOWN_COMMANDS = [
|
|
27796
|
+
"start",
|
|
27797
|
+
"status",
|
|
27798
|
+
"promote",
|
|
27799
|
+
"health",
|
|
27800
|
+
"info",
|
|
27801
|
+
"metrics",
|
|
27802
|
+
"tasks",
|
|
27803
|
+
"task",
|
|
27804
|
+
"nodes",
|
|
27805
|
+
"node",
|
|
27806
|
+
"cluster"
|
|
27807
|
+
];
|
|
27808
|
+
var HELP_ALIASES = /* @__PURE__ */ new Set(["help", "--help", "---help", "-h"]);
|
|
27809
|
+
var COMMANDS = new Set(KNOWN_COMMANDS);
|
|
27810
|
+
var SIMPLE_COMMAND_HELP = {
|
|
27811
|
+
status: { description: "Show cluster status." },
|
|
27812
|
+
promote: {
|
|
27813
|
+
description: "Promote a node to leader.",
|
|
27814
|
+
options: [" --host <host> Target node host (default: localhost)"]
|
|
27815
|
+
},
|
|
27816
|
+
health: { description: "Check node health." },
|
|
27817
|
+
info: { description: "Show node info." },
|
|
27818
|
+
metrics: { description: "Show task metrics." },
|
|
27819
|
+
tasks: {
|
|
27820
|
+
description: "List tasks.",
|
|
27821
|
+
options: [
|
|
27822
|
+
" -s, --status <status> Filter by status",
|
|
27823
|
+
" -P, --priority <priority> Filter by priority"
|
|
27824
|
+
]
|
|
27825
|
+
},
|
|
27826
|
+
nodes: {
|
|
27827
|
+
description: "List cluster nodes.",
|
|
27828
|
+
options: [" -s, --status <status> Filter by status (online, busy, offline)"]
|
|
27829
|
+
}
|
|
27830
|
+
};
|
|
27831
|
+
function isKnownCommand(value) {
|
|
27832
|
+
return COMMANDS.has(value);
|
|
27833
|
+
}
|
|
27834
|
+
function formatHelp(command) {
|
|
27835
|
+
const simpleHelp = command ? SIMPLE_COMMAND_HELP[command] : void 0;
|
|
27836
|
+
if (simpleHelp) {
|
|
27837
|
+
return [
|
|
27838
|
+
`Usage: meshy ${command} [options]`,
|
|
27839
|
+
"",
|
|
27840
|
+
simpleHelp.description,
|
|
27841
|
+
"",
|
|
27842
|
+
"Options:",
|
|
27843
|
+
" -p, --port <number> API port",
|
|
27844
|
+
...simpleHelp.options ?? [],
|
|
27845
|
+
" -h, --help Show this help"
|
|
27846
|
+
].join("\n");
|
|
27847
|
+
}
|
|
27848
|
+
if (command === "task") {
|
|
27849
|
+
return [
|
|
27850
|
+
"Usage: meshy task <command> [options]",
|
|
27851
|
+
"",
|
|
27852
|
+
"Manage tasks.",
|
|
27853
|
+
"",
|
|
27854
|
+
"Commands:",
|
|
27855
|
+
" create Create a new task",
|
|
27856
|
+
" get Get task details",
|
|
27857
|
+
" update Update task fields",
|
|
27858
|
+
" assign Assign a task to a node",
|
|
27859
|
+
" cancel Cancel a pending/running task",
|
|
27860
|
+
" delete Permanently delete a task",
|
|
27861
|
+
" retry Retry a failed task",
|
|
27862
|
+
"",
|
|
27863
|
+
"Options:",
|
|
27864
|
+
" -h, --help Show this help"
|
|
27865
|
+
].join("\n");
|
|
27866
|
+
}
|
|
27867
|
+
if (command === "node") {
|
|
27868
|
+
return [
|
|
27869
|
+
"Usage: meshy node <command> [options]",
|
|
27870
|
+
"",
|
|
27871
|
+
"Manage nodes.",
|
|
27872
|
+
"",
|
|
27873
|
+
"Commands:",
|
|
27874
|
+
" migrate Migrate legacy node storage into node-scoped directories",
|
|
27875
|
+
" get Get node details",
|
|
27876
|
+
" status Get node status with assigned tasks",
|
|
27877
|
+
" update Update node name or capabilities",
|
|
27878
|
+
" remove Remove a node from the cluster",
|
|
27879
|
+
"",
|
|
27880
|
+
"Options:",
|
|
27881
|
+
" -h, --help Show this help"
|
|
27882
|
+
].join("\n");
|
|
27883
|
+
}
|
|
27884
|
+
if (command === "cluster") {
|
|
27885
|
+
return [
|
|
27886
|
+
"Usage: meshy cluster <command> [options]",
|
|
27887
|
+
"",
|
|
27888
|
+
"Manage cluster membership.",
|
|
27889
|
+
"",
|
|
27890
|
+
"Commands:",
|
|
27891
|
+
" join Join a node to the cluster (leader-only)",
|
|
27892
|
+
" leave Remove a node from the cluster",
|
|
27893
|
+
"",
|
|
27894
|
+
"Options:",
|
|
27895
|
+
" -h, --help Show this help"
|
|
27896
|
+
].join("\n");
|
|
27897
|
+
}
|
|
27898
|
+
if (command === "start") {
|
|
27899
|
+
return [
|
|
27900
|
+
"Usage: meshy start [options]",
|
|
27901
|
+
"",
|
|
27902
|
+
"Start a meshy node.",
|
|
27903
|
+
"",
|
|
27904
|
+
"Options:",
|
|
27905
|
+
" -p, --port <number> HTTP port",
|
|
27906
|
+
" -n, --name <string> Node name",
|
|
27907
|
+
" -j, --join <url> Join existing cluster at URL",
|
|
27908
|
+
" -t, --transport <type> Transport type (direct, devtunnel, tailscale)",
|
|
27909
|
+
" -w, --work-dir <path> Base working directory for task execution",
|
|
27910
|
+
" -c, --config <path> Config file path (default: ./config.json)",
|
|
27911
|
+
" --reset Ignore remembered startup options and prompt again",
|
|
27912
|
+
" --disable-auth Disable bearer auth for this run",
|
|
27913
|
+
" -h, --help Show this help"
|
|
27914
|
+
].join("\n");
|
|
27915
|
+
}
|
|
27916
|
+
return [
|
|
27917
|
+
"Usage: meshy <command> [options]",
|
|
27918
|
+
"",
|
|
27919
|
+
"Meshy -- Distributed Task Orchestration",
|
|
27920
|
+
"",
|
|
27921
|
+
"Commands:",
|
|
27922
|
+
" start Start a meshy node (default)",
|
|
27923
|
+
" status Show cluster status",
|
|
27924
|
+
" promote Promote a node to leader",
|
|
27925
|
+
" health Check node health",
|
|
27926
|
+
" info Show node info",
|
|
27927
|
+
" metrics Show task metrics",
|
|
27928
|
+
" tasks List tasks",
|
|
27929
|
+
" task Manage tasks",
|
|
27930
|
+
" nodes List cluster nodes",
|
|
27931
|
+
" node Manage nodes",
|
|
27932
|
+
" cluster Manage cluster",
|
|
27933
|
+
" help Show this help",
|
|
27934
|
+
"",
|
|
27935
|
+
"Start Options:",
|
|
27936
|
+
" -p, --port <number> HTTP port",
|
|
27937
|
+
" -n, --name <string> Node name",
|
|
27938
|
+
" -j, --join <url> Join existing cluster at URL",
|
|
27939
|
+
" -t, --transport <type> Transport type (direct, devtunnel, tailscale)",
|
|
27940
|
+
" -w, --work-dir <path> Base working directory for task execution",
|
|
27941
|
+
" -c, --config <path> Config file path (default: ./config.json)",
|
|
27942
|
+
" --reset Ignore remembered startup options and prompt again",
|
|
27943
|
+
" --disable-auth Disable bearer auth for this run",
|
|
27944
|
+
" -h, --help Show this help"
|
|
27945
|
+
].join("\n");
|
|
27946
|
+
}
|
|
27947
|
+
function parseArgs(argv) {
|
|
27948
|
+
const result = {};
|
|
27949
|
+
for (let i = 0; i < argv.length; i++) {
|
|
27950
|
+
const arg = argv[i];
|
|
27951
|
+
if (!arg) {
|
|
27952
|
+
continue;
|
|
27953
|
+
}
|
|
27954
|
+
switch (arg) {
|
|
27955
|
+
case "help":
|
|
27956
|
+
case "--help":
|
|
27957
|
+
case "---help":
|
|
27958
|
+
case "-h":
|
|
27959
|
+
result.help = true;
|
|
27960
|
+
break;
|
|
27961
|
+
case "start":
|
|
27962
|
+
case "status":
|
|
27963
|
+
case "promote":
|
|
27964
|
+
case "health":
|
|
27965
|
+
case "info":
|
|
27966
|
+
case "metrics":
|
|
27967
|
+
case "tasks":
|
|
27968
|
+
case "task":
|
|
27969
|
+
case "nodes":
|
|
27970
|
+
case "node":
|
|
27971
|
+
case "cluster":
|
|
27972
|
+
result.command ??= arg;
|
|
27973
|
+
break;
|
|
27974
|
+
case "--port":
|
|
27975
|
+
case "-p": {
|
|
27976
|
+
const value = argv[i + 1];
|
|
27977
|
+
if (value !== void 0) {
|
|
27978
|
+
i += 1;
|
|
27979
|
+
const port = Number(value);
|
|
27980
|
+
if (!Number.isNaN(port) && port > 0) {
|
|
27981
|
+
result.port = port;
|
|
27982
|
+
}
|
|
27983
|
+
}
|
|
27984
|
+
break;
|
|
27985
|
+
}
|
|
27986
|
+
case "--name":
|
|
27987
|
+
case "-n":
|
|
27988
|
+
if (argv[i + 1] !== void 0) {
|
|
27989
|
+
result.name = argv[++i];
|
|
27990
|
+
}
|
|
27991
|
+
break;
|
|
27992
|
+
case "--join":
|
|
27993
|
+
case "-j":
|
|
27994
|
+
if (argv[i + 1] !== void 0) {
|
|
27995
|
+
result.join = argv[++i];
|
|
27996
|
+
}
|
|
27997
|
+
break;
|
|
27998
|
+
case "--transport":
|
|
27999
|
+
case "-t": {
|
|
28000
|
+
const value = argv[i + 1];
|
|
28001
|
+
if (value !== void 0) {
|
|
28002
|
+
i += 1;
|
|
28003
|
+
if (value === "direct" || value === "devtunnel" || value === "tailscale") {
|
|
28004
|
+
result.transport = value;
|
|
28005
|
+
}
|
|
28006
|
+
}
|
|
28007
|
+
break;
|
|
28008
|
+
}
|
|
28009
|
+
case "--work-dir":
|
|
28010
|
+
case "-w":
|
|
28011
|
+
if (argv[i + 1] !== void 0) {
|
|
28012
|
+
result.workDir = argv[++i];
|
|
28013
|
+
}
|
|
28014
|
+
break;
|
|
28015
|
+
case "--config":
|
|
28016
|
+
case "-c":
|
|
28017
|
+
if (argv[i + 1] !== void 0) {
|
|
28018
|
+
result.config = argv[++i];
|
|
28019
|
+
}
|
|
28020
|
+
break;
|
|
28021
|
+
case "--reset":
|
|
28022
|
+
result.reset = true;
|
|
28023
|
+
break;
|
|
28024
|
+
case "--disable-auth":
|
|
28025
|
+
result.disableAuth = true;
|
|
28026
|
+
break;
|
|
28027
|
+
default:
|
|
28028
|
+
if (!arg.startsWith("-") && !result.command && isKnownCommand(arg)) {
|
|
28029
|
+
result.command = arg;
|
|
28030
|
+
}
|
|
28031
|
+
if (HELP_ALIASES.has(arg)) {
|
|
28032
|
+
result.help = true;
|
|
28033
|
+
}
|
|
28034
|
+
break;
|
|
28035
|
+
}
|
|
28036
|
+
}
|
|
28037
|
+
return result;
|
|
28038
|
+
}
|
|
27788
28039
|
|
|
27789
28040
|
// ../../packages/core/src/runtime/logger.ts
|
|
27790
28041
|
var fs = __toESM(require("fs"), 1);
|
|
@@ -29808,7 +30059,7 @@ function wasClockTurnedBack(cachedAt) {
|
|
|
29808
30059
|
return cachedAtSec > nowSeconds();
|
|
29809
30060
|
}
|
|
29810
30061
|
function delay(t, value) {
|
|
29811
|
-
return new Promise((
|
|
30062
|
+
return new Promise((resolve14) => setTimeout(() => resolve14(value), t));
|
|
29812
30063
|
}
|
|
29813
30064
|
|
|
29814
30065
|
// ../../node_modules/.pnpm/@azure+msal-common@16.5.0/node_modules/@azure/msal-common/dist/cache/utils/CacheHelpers.mjs
|
|
@@ -31302,7 +31553,7 @@ var developerCliCredentialInternals = {
|
|
|
31302
31553
|
const encodedClaims = btoa(claims);
|
|
31303
31554
|
claimsSections = ["--claims", encodedClaims];
|
|
31304
31555
|
}
|
|
31305
|
-
return new Promise((
|
|
31556
|
+
return new Promise((resolve14, reject) => {
|
|
31306
31557
|
try {
|
|
31307
31558
|
const args = [
|
|
31308
31559
|
"auth",
|
|
@@ -31319,7 +31570,7 @@ var developerCliCredentialInternals = {
|
|
|
31319
31570
|
cwd: developerCliCredentialInternals.getSafeWorkingDir(),
|
|
31320
31571
|
timeout
|
|
31321
31572
|
}, (error, stdout, stderr) => {
|
|
31322
|
-
|
|
31573
|
+
resolve14({ stdout, stderr, error });
|
|
31323
31574
|
});
|
|
31324
31575
|
} catch (err) {
|
|
31325
31576
|
reject(err);
|
|
@@ -31467,7 +31718,7 @@ var cliCredentialInternals = {
|
|
|
31467
31718
|
if (subscription) {
|
|
31468
31719
|
subscriptionSection = ["--subscription", `"${subscription}"`];
|
|
31469
31720
|
}
|
|
31470
|
-
return new Promise((
|
|
31721
|
+
return new Promise((resolve14, reject) => {
|
|
31471
31722
|
try {
|
|
31472
31723
|
const args = [
|
|
31473
31724
|
"account",
|
|
@@ -31481,7 +31732,7 @@ var cliCredentialInternals = {
|
|
|
31481
31732
|
];
|
|
31482
31733
|
const command = ["az", ...args].join(" ");
|
|
31483
31734
|
import_child_process2.default.exec(command, { cwd: cliCredentialInternals.getSafeWorkingDir(), timeout }, (error, stdout, stderr) => {
|
|
31484
|
-
|
|
31735
|
+
resolve14({ stdout, stderr, error });
|
|
31485
31736
|
});
|
|
31486
31737
|
} catch (err) {
|
|
31487
31738
|
reject(err);
|
|
@@ -31622,7 +31873,7 @@ var processUtils = {
|
|
|
31622
31873
|
* @internal
|
|
31623
31874
|
*/
|
|
31624
31875
|
execFile(file, params, options) {
|
|
31625
|
-
return new Promise((
|
|
31876
|
+
return new Promise((resolve14, reject) => {
|
|
31626
31877
|
import_node_child_process.default.execFile(file, params, options, (error, stdout, stderr) => {
|
|
31627
31878
|
if (Buffer.isBuffer(stdout)) {
|
|
31628
31879
|
stdout = stdout.toString("utf8");
|
|
@@ -31633,7 +31884,7 @@ var processUtils = {
|
|
|
31633
31884
|
if (stderr || error) {
|
|
31634
31885
|
reject(stderr ? new Error(stderr) : error);
|
|
31635
31886
|
} else {
|
|
31636
|
-
|
|
31887
|
+
resolve14(stdout);
|
|
31637
31888
|
}
|
|
31638
31889
|
});
|
|
31639
31890
|
});
|
|
@@ -32014,11 +32265,11 @@ function persistNodeStartupTransport(storagePath, transport) {
|
|
|
32014
32265
|
transport
|
|
32015
32266
|
});
|
|
32016
32267
|
}
|
|
32017
|
-
function persistNodeStartupJoin(storagePath,
|
|
32268
|
+
function persistNodeStartupJoin(storagePath, join16) {
|
|
32018
32269
|
const startup = resolveNodeStartupMetadata(storagePath);
|
|
32019
32270
|
persistNodeStartupMetadata(storagePath, {
|
|
32020
32271
|
...startup,
|
|
32021
|
-
join:
|
|
32272
|
+
join: join16
|
|
32022
32273
|
});
|
|
32023
32274
|
}
|
|
32024
32275
|
function resolvePersistedDevTunnelId(storagePath, kind) {
|
|
@@ -33003,19 +33254,19 @@ async function fetchWithTimeout(url, init, timeoutMs = DEFAULT_NODE_REQUEST_TIME
|
|
|
33003
33254
|
cleanup();
|
|
33004
33255
|
}
|
|
33005
33256
|
}
|
|
33006
|
-
async function fetchNodeWithFallback(node,
|
|
33257
|
+
async function fetchNodeWithFallback(node, path21, init, timeoutMs = DEFAULT_NODE_REQUEST_TIMEOUT_MS, trace, options) {
|
|
33007
33258
|
let lastError;
|
|
33008
33259
|
const endpoints = getNodeRequestEndpoints(node, options);
|
|
33009
33260
|
for (const [index, endpoint] of endpoints.entries()) {
|
|
33010
33261
|
const attempt = index + 1;
|
|
33011
|
-
trace?.onAttempt?.({ attempt, endpoint, path:
|
|
33262
|
+
trace?.onAttempt?.({ attempt, endpoint, path: path21, timeoutMs, totalEndpoints: endpoints.length });
|
|
33012
33263
|
try {
|
|
33013
|
-
const response = await fetchWithTimeout(`${endpoint}${
|
|
33014
|
-
trace?.onResponse?.({ attempt, endpoint, path:
|
|
33264
|
+
const response = await fetchWithTimeout(`${endpoint}${path21}`, init, timeoutMs);
|
|
33265
|
+
trace?.onResponse?.({ attempt, endpoint, path: path21, response, timeoutMs, totalEndpoints: endpoints.length });
|
|
33015
33266
|
return { endpoint, response };
|
|
33016
33267
|
} catch (error) {
|
|
33017
33268
|
lastError = error;
|
|
33018
|
-
trace?.onError?.({ attempt, endpoint, error, path:
|
|
33269
|
+
trace?.onError?.({ attempt, endpoint, error, path: path21, timeoutMs, totalEndpoints: endpoints.length });
|
|
33019
33270
|
}
|
|
33020
33271
|
}
|
|
33021
33272
|
throw lastError instanceof Error ? lastError : new Error("No reachable node endpoint");
|
|
@@ -34162,7 +34413,7 @@ var KeepaliveNodeMessageQueue = class {
|
|
|
34162
34413
|
queued.push(requestMessage);
|
|
34163
34414
|
this.queuedMessages.set(nodeId, queued);
|
|
34164
34415
|
this.log.info("queued keepalive node message request", { nodeId, ...describeNodeMessage(requestMessage) });
|
|
34165
|
-
return new Promise((
|
|
34416
|
+
return new Promise((resolve14, reject) => {
|
|
34166
34417
|
const timeoutId = setTimeout(() => {
|
|
34167
34418
|
this.pendingResponses.delete(requestMessage.id);
|
|
34168
34419
|
reject(new Error(`Timed out waiting for ${requestMessage.kind} response from ${nodeId}`));
|
|
@@ -34170,7 +34421,7 @@ var KeepaliveNodeMessageQueue = class {
|
|
|
34170
34421
|
this.pendingResponses.set(requestMessage.id, {
|
|
34171
34422
|
nodeId,
|
|
34172
34423
|
kind: requestMessage.kind,
|
|
34173
|
-
resolve:
|
|
34424
|
+
resolve: resolve14,
|
|
34174
34425
|
reject,
|
|
34175
34426
|
timeoutId
|
|
34176
34427
|
});
|
|
@@ -35054,9 +35305,9 @@ var DataRouter = class {
|
|
|
35054
35305
|
/**
|
|
35055
35306
|
* Returns true if the request should be proxied to the leader.
|
|
35056
35307
|
*/
|
|
35057
|
-
shouldProxy(method,
|
|
35308
|
+
shouldProxy(method, path21) {
|
|
35058
35309
|
if (this.election.isLeader()) return false;
|
|
35059
|
-
if (this.isExcludedPath(
|
|
35310
|
+
if (this.isExcludedPath(path21)) return false;
|
|
35060
35311
|
if (method.toUpperCase() === "GET") return false;
|
|
35061
35312
|
return WRITE_METHODS.has(method.toUpperCase());
|
|
35062
35313
|
}
|
|
@@ -35160,8 +35411,8 @@ var DataRouter = class {
|
|
|
35160
35411
|
};
|
|
35161
35412
|
}
|
|
35162
35413
|
// ── Helpers ───────────────────────────────────────────────────────────
|
|
35163
|
-
isExcludedPath(
|
|
35164
|
-
return EXCLUDED_PATH_PREFIXES.some((prefix) =>
|
|
35414
|
+
isExcludedPath(path21) {
|
|
35415
|
+
return EXCLUDED_PATH_PREFIXES.some((prefix) => path21.startsWith(prefix)) || EXCLUDED_PATH_SUFFIXES.some((suffix) => path21.endsWith(suffix));
|
|
35165
35416
|
}
|
|
35166
35417
|
};
|
|
35167
35418
|
|
|
@@ -35703,7 +35954,7 @@ var LiteAgentRunner = class {
|
|
|
35703
35954
|
}
|
|
35704
35955
|
};
|
|
35705
35956
|
function runProcessForOutput(command, args, prompt, cwd, extractOutput) {
|
|
35706
|
-
return new Promise((
|
|
35957
|
+
return new Promise((resolve14, reject) => {
|
|
35707
35958
|
const proc = (0, import_node_child_process3.spawn)(command, args, {
|
|
35708
35959
|
cwd: cwd ?? process.cwd(),
|
|
35709
35960
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -35723,7 +35974,7 @@ function runProcessForOutput(command, args, prompt, cwd, extractOutput) {
|
|
|
35723
35974
|
return;
|
|
35724
35975
|
}
|
|
35725
35976
|
try {
|
|
35726
|
-
|
|
35977
|
+
resolve14(extractOutput ? extractOutput(stdout) : stdout.trim());
|
|
35727
35978
|
} catch (error) {
|
|
35728
35979
|
reject(error);
|
|
35729
35980
|
}
|
|
@@ -36459,9 +36710,347 @@ function resolveDefaultStoragePath(options = {}) {
|
|
|
36459
36710
|
const baseDir = mode === "cwd" ? envBaseDir ?? options.cwd ?? process.cwd() : options.homeDir ?? os4.homedir();
|
|
36460
36711
|
return path10.resolve(baseDir, ".meshy");
|
|
36461
36712
|
}
|
|
36713
|
+
function toSafeNodeStorageName(nodeName) {
|
|
36714
|
+
const safeName = nodeName.trim().replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
36715
|
+
return safeName.length > 0 ? safeName : "node";
|
|
36716
|
+
}
|
|
36717
|
+
function resolveNodeScopedStoragePath(storageRoot, nodeName) {
|
|
36718
|
+
return path10.resolve(storageRoot, toSafeNodeStorageName(nodeName));
|
|
36719
|
+
}
|
|
36720
|
+
|
|
36721
|
+
// ../../packages/core/src/storage/storage-migration.ts
|
|
36722
|
+
var fs10 = __toESM(require("fs"), 1);
|
|
36723
|
+
var path11 = __toESM(require("path"), 1);
|
|
36724
|
+
var LEGACY_FILES = [
|
|
36725
|
+
"metadata.json",
|
|
36726
|
+
"cluster.json",
|
|
36727
|
+
"nodes.json",
|
|
36728
|
+
"tasks.json",
|
|
36729
|
+
"shares.json",
|
|
36730
|
+
"election.json"
|
|
36731
|
+
];
|
|
36732
|
+
var LEGACY_DIRS = ["logs", "task-logs"];
|
|
36733
|
+
function migrateLegacyNodeStorage(options) {
|
|
36734
|
+
const sourcePath = path11.resolve(options.storageRoot);
|
|
36735
|
+
if (normalizeString2(options.nodeName)) {
|
|
36736
|
+
return migrateIntoRequestedNode({ ...options, storageRoot: sourcePath, nodeName: normalizeString2(options.nodeName) });
|
|
36737
|
+
}
|
|
36738
|
+
return migrateByDiscoveredNodes({ ...options, storageRoot: sourcePath });
|
|
36739
|
+
}
|
|
36740
|
+
function migrateIntoRequestedNode(options) {
|
|
36741
|
+
const sourcePath = path11.resolve(options.storageRoot);
|
|
36742
|
+
const targetPath = resolveNodeScopedStoragePath(sourcePath, options.nodeName);
|
|
36743
|
+
const moved = [];
|
|
36744
|
+
const skipped = [];
|
|
36745
|
+
const entries = collectLegacyEntries(sourcePath, options.nodeName);
|
|
36746
|
+
for (const entry of entries) {
|
|
36747
|
+
const source = path11.join(sourcePath, entry.sourceName);
|
|
36748
|
+
const target = path11.join(targetPath, entry.targetName);
|
|
36749
|
+
if (!fs10.existsSync(source)) {
|
|
36750
|
+
continue;
|
|
36751
|
+
}
|
|
36752
|
+
if (fs10.existsSync(target) && options.overwrite !== true) {
|
|
36753
|
+
skipped.push(entry.targetName);
|
|
36754
|
+
continue;
|
|
36755
|
+
}
|
|
36756
|
+
fs10.mkdirSync(path11.dirname(target), { recursive: true });
|
|
36757
|
+
if (fs10.existsSync(target)) {
|
|
36758
|
+
fs10.rmSync(target, { recursive: true, force: true });
|
|
36759
|
+
}
|
|
36760
|
+
fs10.renameSync(source, target);
|
|
36761
|
+
moved.push(entry.targetName);
|
|
36762
|
+
}
|
|
36763
|
+
return {
|
|
36764
|
+
migrated: moved.length > 0 && skipped.length === 0,
|
|
36765
|
+
sourcePath,
|
|
36766
|
+
targetPath,
|
|
36767
|
+
targetPaths: moved.length > 0 ? [targetPath] : [],
|
|
36768
|
+
targetNodeNames: moved.length > 0 ? [options.nodeName] : [],
|
|
36769
|
+
moved,
|
|
36770
|
+
skipped,
|
|
36771
|
+
dropped: []
|
|
36772
|
+
};
|
|
36773
|
+
}
|
|
36774
|
+
function migrateByDiscoveredNodes(options) {
|
|
36775
|
+
const sourcePath = path11.resolve(options.storageRoot);
|
|
36776
|
+
const moved = [];
|
|
36777
|
+
const skipped = [];
|
|
36778
|
+
const dropped = [];
|
|
36779
|
+
const targetNames = /* @__PURE__ */ new Set();
|
|
36780
|
+
const nodeIdToName = /* @__PURE__ */ new Map();
|
|
36781
|
+
const nodes = readJsonRecord(path11.join(sourcePath, "nodes.json"));
|
|
36782
|
+
const nodesByName = /* @__PURE__ */ new Map();
|
|
36783
|
+
for (const [key, value] of Object.entries(nodes)) {
|
|
36784
|
+
if (!isRecord2(value)) {
|
|
36785
|
+
dropped.push(`node:${key}`);
|
|
36786
|
+
continue;
|
|
36787
|
+
}
|
|
36788
|
+
const nodeName = normalizeString2(value.name);
|
|
36789
|
+
const nodeId = normalizeString2(value.id) ?? key;
|
|
36790
|
+
if (!nodeName) {
|
|
36791
|
+
dropped.push(`node:${nodeId}`);
|
|
36792
|
+
continue;
|
|
36793
|
+
}
|
|
36794
|
+
targetNames.add(nodeName);
|
|
36795
|
+
nodeIdToName.set(nodeId, nodeName);
|
|
36796
|
+
nodesByName.set(nodeName, { ...nodesByName.get(nodeName) ?? {}, [nodeId]: value });
|
|
36797
|
+
}
|
|
36798
|
+
const metadata = readJsonRecord(path11.join(sourcePath, "metadata.json"));
|
|
36799
|
+
const metadataNodeName = normalizeString2(metadata.defaultNodeName);
|
|
36800
|
+
if (metadataNodeName) {
|
|
36801
|
+
targetNames.add(metadataNodeName);
|
|
36802
|
+
}
|
|
36803
|
+
const identities = collectIdentityEntries(sourcePath);
|
|
36804
|
+
for (const identity of identities) {
|
|
36805
|
+
if (identity.nodeName) {
|
|
36806
|
+
targetNames.add(identity.nodeName);
|
|
36807
|
+
}
|
|
36808
|
+
}
|
|
36809
|
+
const taskNodeNames = migrateTasksAndShares(sourcePath, nodeIdToName, targetNames, options.overwrite === true, moved, skipped, dropped);
|
|
36810
|
+
for (const nodeName of taskNodeNames) {
|
|
36811
|
+
targetNames.add(nodeName);
|
|
36812
|
+
}
|
|
36813
|
+
const nodeSkipStart = skipped.length;
|
|
36814
|
+
for (const [nodeName, nodeGroup] of nodesByName) {
|
|
36815
|
+
writeScopedJson(sourcePath, nodeName, "nodes.json", nodeGroup, options.overwrite === true, moved, skipped);
|
|
36816
|
+
}
|
|
36817
|
+
if (skipped.length === nodeSkipStart) {
|
|
36818
|
+
removeLegacyFile(sourcePath, "nodes.json", dropped);
|
|
36819
|
+
}
|
|
36820
|
+
for (const identity of identities) {
|
|
36821
|
+
if (!identity.nodeName) {
|
|
36822
|
+
removeLegacyPath(identity.sourcePath);
|
|
36823
|
+
dropped.push(identity.sourceName);
|
|
36824
|
+
continue;
|
|
36825
|
+
}
|
|
36826
|
+
moveScopedPath(
|
|
36827
|
+
identity.sourcePath,
|
|
36828
|
+
path11.join(resolveNodeScopedStoragePath(sourcePath, identity.nodeName), "node-identity.json"),
|
|
36829
|
+
`${identity.nodeName}/node-identity.json`,
|
|
36830
|
+
options.overwrite === true,
|
|
36831
|
+
moved,
|
|
36832
|
+
skipped
|
|
36833
|
+
);
|
|
36834
|
+
}
|
|
36835
|
+
const inferredSingleNodeName = targetNames.size === 1 ? [...targetNames][0] : void 0;
|
|
36836
|
+
migrateNodeScopedOrDrop(sourcePath, metadataNodeName ?? inferredSingleNodeName, "metadata.json", options.overwrite === true, moved, skipped, dropped);
|
|
36837
|
+
migrateNodeScopedOrDrop(sourcePath, resolveElectionNodeName(sourcePath, nodeIdToName) ?? inferredSingleNodeName, "election.json", options.overwrite === true, moved, skipped, dropped);
|
|
36838
|
+
migrateNodeScopedOrDrop(sourcePath, inferredSingleNodeName, "cluster.json", options.overwrite === true, moved, skipped, dropped);
|
|
36839
|
+
migrateNodeScopedOrDrop(sourcePath, inferredSingleNodeName, "logs", options.overwrite === true, moved, skipped, dropped);
|
|
36840
|
+
cleanupEmptyDir(path11.join(sourcePath, "task-logs"));
|
|
36841
|
+
const targetNodeNames = [...targetNames].filter((nodeName) => fs10.existsSync(resolveNodeScopedStoragePath(sourcePath, nodeName))).sort();
|
|
36842
|
+
const targetPaths = targetNodeNames.map((nodeName) => resolveNodeScopedStoragePath(sourcePath, nodeName));
|
|
36843
|
+
return {
|
|
36844
|
+
migrated: moved.length > 0 && skipped.length === 0,
|
|
36845
|
+
sourcePath,
|
|
36846
|
+
targetPath: targetPaths[0] ?? resolveNodeScopedStoragePath(sourcePath, "node"),
|
|
36847
|
+
targetPaths,
|
|
36848
|
+
targetNodeNames,
|
|
36849
|
+
moved,
|
|
36850
|
+
skipped,
|
|
36851
|
+
dropped
|
|
36852
|
+
};
|
|
36853
|
+
}
|
|
36854
|
+
function migrateTasksAndShares(sourcePath, nodeIdToName, targetNames, overwrite, moved, skipped, dropped) {
|
|
36855
|
+
const taskNodeNames = /* @__PURE__ */ new Set();
|
|
36856
|
+
const taskIdToNodeName = /* @__PURE__ */ new Map();
|
|
36857
|
+
const tasksByName = /* @__PURE__ */ new Map();
|
|
36858
|
+
const tasks = readJsonRecord(path11.join(sourcePath, "tasks.json"));
|
|
36859
|
+
for (const [key, value] of Object.entries(tasks)) {
|
|
36860
|
+
if (!isRecord2(value)) {
|
|
36861
|
+
dropped.push(`task:${key}`);
|
|
36862
|
+
continue;
|
|
36863
|
+
}
|
|
36864
|
+
const taskId = normalizeString2(value.id) ?? key;
|
|
36865
|
+
const assignedTo = normalizeString2(value.assignedTo);
|
|
36866
|
+
const nodeName = normalizeString2(value.assignedNodeName) ?? (assignedTo ? nodeIdToName.get(assignedTo) : void 0);
|
|
36867
|
+
if (!nodeName) {
|
|
36868
|
+
dropped.push(`task:${taskId}`);
|
|
36869
|
+
continue;
|
|
36870
|
+
}
|
|
36871
|
+
taskNodeNames.add(nodeName);
|
|
36872
|
+
taskIdToNodeName.set(taskId, nodeName);
|
|
36873
|
+
tasksByName.set(nodeName, { ...tasksByName.get(nodeName) ?? {}, [taskId]: value });
|
|
36874
|
+
}
|
|
36875
|
+
const taskSkipStart = skipped.length;
|
|
36876
|
+
for (const [nodeName, taskGroup] of tasksByName) {
|
|
36877
|
+
writeScopedJson(sourcePath, nodeName, "tasks.json", taskGroup, overwrite, moved, skipped);
|
|
36878
|
+
}
|
|
36879
|
+
if (skipped.length === taskSkipStart && fs10.existsSync(path11.join(sourcePath, "tasks.json"))) {
|
|
36880
|
+
if (tasksByName.size === 0) {
|
|
36881
|
+
dropped.push("tasks.json");
|
|
36882
|
+
}
|
|
36883
|
+
fs10.rmSync(path11.join(sourcePath, "tasks.json"), { force: true });
|
|
36884
|
+
}
|
|
36885
|
+
const sharesByName = /* @__PURE__ */ new Map();
|
|
36886
|
+
const shares = readJsonRecord(path11.join(sourcePath, "shares.json"));
|
|
36887
|
+
for (const [key, value] of Object.entries(shares)) {
|
|
36888
|
+
if (!isRecord2(value)) {
|
|
36889
|
+
dropped.push(`share:${key}`);
|
|
36890
|
+
continue;
|
|
36891
|
+
}
|
|
36892
|
+
const shareId = normalizeString2(value.id) ?? key;
|
|
36893
|
+
const taskId = normalizeString2(value.taskId);
|
|
36894
|
+
const nodeName = taskId ? taskIdToNodeName.get(taskId) : void 0;
|
|
36895
|
+
if (!nodeName) {
|
|
36896
|
+
dropped.push(`share:${shareId}`);
|
|
36897
|
+
continue;
|
|
36898
|
+
}
|
|
36899
|
+
sharesByName.set(nodeName, { ...sharesByName.get(nodeName) ?? {}, [shareId]: value });
|
|
36900
|
+
}
|
|
36901
|
+
const shareSkipStart = skipped.length;
|
|
36902
|
+
for (const [nodeName, shareGroup] of sharesByName) {
|
|
36903
|
+
writeScopedJson(sourcePath, nodeName, "shares.json", shareGroup, overwrite, moved, skipped);
|
|
36904
|
+
}
|
|
36905
|
+
if (skipped.length === shareSkipStart) {
|
|
36906
|
+
removeLegacyFile(sourcePath, "shares.json", dropped);
|
|
36907
|
+
}
|
|
36908
|
+
migrateTaskLogs(sourcePath, taskIdToNodeName, overwrite, moved, skipped, dropped);
|
|
36909
|
+
for (const nodeName of taskNodeNames) {
|
|
36910
|
+
targetNames.add(nodeName);
|
|
36911
|
+
}
|
|
36912
|
+
return taskNodeNames;
|
|
36913
|
+
}
|
|
36914
|
+
function migrateTaskLogs(sourcePath, taskIdToNodeName, overwrite, moved, skipped, dropped) {
|
|
36915
|
+
const sourceDir = path11.join(sourcePath, "task-logs");
|
|
36916
|
+
if (!fs10.existsSync(sourceDir)) return;
|
|
36917
|
+
for (const fileName of fs10.readdirSync(sourceDir)) {
|
|
36918
|
+
const source = path11.join(sourceDir, fileName);
|
|
36919
|
+
const stat = fs10.statSync(source);
|
|
36920
|
+
if (!stat.isFile()) continue;
|
|
36921
|
+
const taskId = fileName.endsWith(".jsonl") ? fileName.slice(0, -".jsonl".length) : fileName;
|
|
36922
|
+
const nodeName = taskIdToNodeName.get(taskId);
|
|
36923
|
+
if (!nodeName) {
|
|
36924
|
+
fs10.rmSync(source, { force: true });
|
|
36925
|
+
dropped.push(`task-log:${fileName}`);
|
|
36926
|
+
continue;
|
|
36927
|
+
}
|
|
36928
|
+
moveScopedPath(
|
|
36929
|
+
source,
|
|
36930
|
+
path11.join(resolveNodeScopedStoragePath(sourcePath, nodeName), "task-logs", fileName),
|
|
36931
|
+
`${nodeName}/task-logs/${fileName}`,
|
|
36932
|
+
overwrite,
|
|
36933
|
+
moved,
|
|
36934
|
+
skipped
|
|
36935
|
+
);
|
|
36936
|
+
}
|
|
36937
|
+
}
|
|
36938
|
+
function migrateNodeScopedOrDrop(sourcePath, nodeName, sourceName, overwrite, moved, skipped, dropped) {
|
|
36939
|
+
const source = path11.join(sourcePath, sourceName);
|
|
36940
|
+
if (!fs10.existsSync(source)) return;
|
|
36941
|
+
if (!nodeName) {
|
|
36942
|
+
removeLegacyPath(source);
|
|
36943
|
+
dropped.push(sourceName);
|
|
36944
|
+
return;
|
|
36945
|
+
}
|
|
36946
|
+
moveScopedPath(
|
|
36947
|
+
source,
|
|
36948
|
+
path11.join(resolveNodeScopedStoragePath(sourcePath, nodeName), sourceName),
|
|
36949
|
+
`${nodeName}/${sourceName}`,
|
|
36950
|
+
overwrite,
|
|
36951
|
+
moved,
|
|
36952
|
+
skipped
|
|
36953
|
+
);
|
|
36954
|
+
}
|
|
36955
|
+
function writeScopedJson(sourcePath, nodeName, fileName, value, overwrite, moved, skipped) {
|
|
36956
|
+
if (Object.keys(value).length === 0) return;
|
|
36957
|
+
const target = path11.join(resolveNodeScopedStoragePath(sourcePath, nodeName), fileName);
|
|
36958
|
+
const label = `${nodeName}/${fileName}`;
|
|
36959
|
+
if (fs10.existsSync(target) && !overwrite) {
|
|
36960
|
+
skipped.push(label);
|
|
36961
|
+
return;
|
|
36962
|
+
}
|
|
36963
|
+
fs10.mkdirSync(path11.dirname(target), { recursive: true });
|
|
36964
|
+
fs10.writeFileSync(target, JSON.stringify(value, null, 2) + "\n", "utf-8");
|
|
36965
|
+
moved.push(label);
|
|
36966
|
+
}
|
|
36967
|
+
function moveScopedPath(source, target, label, overwrite, moved, skipped) {
|
|
36968
|
+
if (!fs10.existsSync(source)) return;
|
|
36969
|
+
if (fs10.existsSync(target) && !overwrite) {
|
|
36970
|
+
skipped.push(label);
|
|
36971
|
+
return;
|
|
36972
|
+
}
|
|
36973
|
+
fs10.mkdirSync(path11.dirname(target), { recursive: true });
|
|
36974
|
+
if (fs10.existsSync(target)) {
|
|
36975
|
+
fs10.rmSync(target, { recursive: true, force: true });
|
|
36976
|
+
}
|
|
36977
|
+
fs10.renameSync(source, target);
|
|
36978
|
+
moved.push(label);
|
|
36979
|
+
}
|
|
36980
|
+
function collectIdentityEntries(storageRoot) {
|
|
36981
|
+
if (!fs10.existsSync(storageRoot)) return [];
|
|
36982
|
+
const entries = [];
|
|
36983
|
+
for (const sourceName of fs10.readdirSync(storageRoot)) {
|
|
36984
|
+
const match = /^node-identity-(.+)\.json$/.exec(sourceName);
|
|
36985
|
+
if (sourceName !== "node-identity.json" && !match) continue;
|
|
36986
|
+
const sourcePath = path11.join(storageRoot, sourceName);
|
|
36987
|
+
if (!fs10.statSync(sourcePath).isFile()) continue;
|
|
36988
|
+
const identity = readJsonRecord(sourcePath);
|
|
36989
|
+
const nodeName = normalizeString2(identity.name) ?? (match ? match[1] : void 0);
|
|
36990
|
+
entries.push({ sourceName, sourcePath, nodeName });
|
|
36991
|
+
}
|
|
36992
|
+
return entries;
|
|
36993
|
+
}
|
|
36994
|
+
function resolveElectionNodeName(sourcePath, nodeIdToName) {
|
|
36995
|
+
const election = readJsonRecord(path11.join(sourcePath, "election.json"));
|
|
36996
|
+
const leaderId = normalizeString2(election.leaderId);
|
|
36997
|
+
return leaderId ? nodeIdToName.get(leaderId) : void 0;
|
|
36998
|
+
}
|
|
36999
|
+
function removeLegacyFile(sourcePath, fileName, dropped) {
|
|
37000
|
+
const target = path11.join(sourcePath, fileName);
|
|
37001
|
+
if (!fs10.existsSync(target)) return;
|
|
37002
|
+
fs10.rmSync(target, { force: true });
|
|
37003
|
+
if (fileName !== "nodes.json" && fileName !== "shares.json") {
|
|
37004
|
+
dropped.push(fileName);
|
|
37005
|
+
}
|
|
37006
|
+
}
|
|
37007
|
+
function cleanupEmptyDir(dirPath) {
|
|
37008
|
+
if (!fs10.existsSync(dirPath)) return;
|
|
37009
|
+
if (fs10.readdirSync(dirPath).length === 0) {
|
|
37010
|
+
fs10.rmSync(dirPath, { recursive: true, force: true });
|
|
37011
|
+
}
|
|
37012
|
+
}
|
|
37013
|
+
function removeLegacyPath(targetPath) {
|
|
37014
|
+
if (fs10.existsSync(targetPath)) {
|
|
37015
|
+
fs10.rmSync(targetPath, { recursive: true, force: true });
|
|
37016
|
+
}
|
|
37017
|
+
}
|
|
37018
|
+
function collectLegacyEntries(storageRoot, nodeName) {
|
|
37019
|
+
const safeName = toSafeNodeStorageName(nodeName);
|
|
37020
|
+
const entries = [];
|
|
37021
|
+
for (const fileName of LEGACY_FILES) {
|
|
37022
|
+
entries.push({ sourceName: fileName, targetName: fileName });
|
|
37023
|
+
}
|
|
37024
|
+
for (const dirName of LEGACY_DIRS) {
|
|
37025
|
+
entries.push({ sourceName: dirName, targetName: dirName });
|
|
37026
|
+
}
|
|
37027
|
+
const exactIdentity = `node-identity-${safeName}.json`;
|
|
37028
|
+
entries.push({ sourceName: exactIdentity, targetName: "node-identity.json" });
|
|
37029
|
+
const legacyIdentity = path11.join(storageRoot, "node-identity.json");
|
|
37030
|
+
if (fs10.existsSync(legacyIdentity)) {
|
|
37031
|
+
entries.push({ sourceName: "node-identity.json", targetName: "node-identity.json" });
|
|
37032
|
+
}
|
|
37033
|
+
return entries;
|
|
37034
|
+
}
|
|
37035
|
+
function readJsonRecord(filePath) {
|
|
37036
|
+
try {
|
|
37037
|
+
const parsed = JSON.parse(fs10.readFileSync(filePath, "utf-8"));
|
|
37038
|
+
return isRecord2(parsed) ? parsed : {};
|
|
37039
|
+
} catch {
|
|
37040
|
+
return {};
|
|
37041
|
+
}
|
|
37042
|
+
}
|
|
37043
|
+
function normalizeString2(value) {
|
|
37044
|
+
if (typeof value !== "string") return void 0;
|
|
37045
|
+
const trimmed = value.trim();
|
|
37046
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
37047
|
+
}
|
|
37048
|
+
function isRecord2(value) {
|
|
37049
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37050
|
+
}
|
|
36462
37051
|
|
|
36463
37052
|
// ../../packages/core/src/node/node.ts
|
|
36464
|
-
var
|
|
37053
|
+
var path13 = __toESM(require("path"), 1);
|
|
36465
37054
|
|
|
36466
37055
|
// ../../packages/core/src/messaging/node-local-message-handler.ts
|
|
36467
37056
|
async function handleLocalNodeMessage(deps, message) {
|
|
@@ -36506,8 +37095,8 @@ async function handleLocalNodeMessage(deps, message) {
|
|
|
36506
37095
|
}
|
|
36507
37096
|
|
|
36508
37097
|
// ../../packages/core/src/node/node-identity.ts
|
|
36509
|
-
var
|
|
36510
|
-
var
|
|
37098
|
+
var fs11 = __toESM(require("fs"), 1);
|
|
37099
|
+
var path12 = __toESM(require("path"), 1);
|
|
36511
37100
|
|
|
36512
37101
|
// ../../node_modules/.pnpm/nanoid@5.1.7/node_modules/nanoid/index.js
|
|
36513
37102
|
var import_node_crypto6 = require("crypto");
|
|
@@ -36541,18 +37130,17 @@ function nanoid(size = 21) {
|
|
|
36541
37130
|
|
|
36542
37131
|
// ../../packages/core/src/node/node-identity.ts
|
|
36543
37132
|
function loadOrCreateNodeId(storagePath, nodeName) {
|
|
36544
|
-
const
|
|
36545
|
-
const identityPath = path11.join(storagePath, `node-identity-${safeName}.json`);
|
|
37133
|
+
const identityPath = path12.join(storagePath, "node-identity.json");
|
|
36546
37134
|
try {
|
|
36547
|
-
if (
|
|
36548
|
-
const raw = JSON.parse(
|
|
37135
|
+
if (fs11.existsSync(identityPath)) {
|
|
37136
|
+
const raw = JSON.parse(fs11.readFileSync(identityPath, "utf-8"));
|
|
36549
37137
|
if (typeof raw.id === "string" && raw.id.length > 0) return raw.id;
|
|
36550
37138
|
}
|
|
36551
37139
|
} catch {
|
|
36552
37140
|
}
|
|
36553
37141
|
const id = nanoid();
|
|
36554
|
-
|
|
36555
|
-
|
|
37142
|
+
fs11.mkdirSync(path12.dirname(identityPath), { recursive: true });
|
|
37143
|
+
fs11.writeFileSync(identityPath, JSON.stringify({ id, name: nodeName }, null, 2) + "\n", "utf-8");
|
|
36556
37144
|
return id;
|
|
36557
37145
|
}
|
|
36558
37146
|
|
|
@@ -36596,7 +37184,7 @@ var MeshyNode = class {
|
|
|
36596
37184
|
await this.transport.start(this.config.node.port);
|
|
36597
37185
|
const endpoint = await this.transport.getEndpoint();
|
|
36598
37186
|
const now = Date.now();
|
|
36599
|
-
const workDir =
|
|
37187
|
+
const workDir = path13.resolve(this.config.node.workDir ?? process.cwd());
|
|
36600
37188
|
this.selfInfo = {
|
|
36601
37189
|
id: nodeId,
|
|
36602
37190
|
name: this.config.node.name,
|
|
@@ -36626,7 +37214,7 @@ var MeshyNode = class {
|
|
|
36626
37214
|
this.logger,
|
|
36627
37215
|
this.getSettingsSnapshot
|
|
36628
37216
|
);
|
|
36629
|
-
const logDir =
|
|
37217
|
+
const logDir = path13.join(this.config.storage.path, "task-logs");
|
|
36630
37218
|
this.taskEngine = new TaskEngine(this.store, this.nodeRegistry, this.eventBus, logDir);
|
|
36631
37219
|
this.heartbeat.setGetAssignedTasks((nodeId2) => {
|
|
36632
37220
|
const result = this.taskEngine.listTasks({ assignedTo: nodeId2, status: "assigned" });
|
|
@@ -37152,6 +37740,613 @@ ${joinErrors.map((e) => ` - ${e}`).join("\n")}`
|
|
|
37152
37740
|
}
|
|
37153
37741
|
};
|
|
37154
37742
|
|
|
37743
|
+
// ../../packages/cli/src/node/migrate.ts
|
|
37744
|
+
function runNodeMigrateCommand(options) {
|
|
37745
|
+
const stdout = options.stdout ?? process.stdout;
|
|
37746
|
+
const stderr = options.stderr ?? process.stderr;
|
|
37747
|
+
const result = migrateLegacyNodeStorage({
|
|
37748
|
+
storageRoot: options.storageRoot ?? resolveDefaultStoragePath(),
|
|
37749
|
+
nodeName: options.nodeName,
|
|
37750
|
+
overwrite: options.overwrite
|
|
37751
|
+
});
|
|
37752
|
+
const defaultNodeName = options.nodeName ?? (result.targetNodeNames.length === 1 ? result.targetNodeNames[0] : void 0);
|
|
37753
|
+
if (defaultNodeName) {
|
|
37754
|
+
persistDefaultNodeName(result.sourcePath, defaultNodeName);
|
|
37755
|
+
}
|
|
37756
|
+
if (result.moved.length > 0) {
|
|
37757
|
+
const verb = options.nodeName ? "Migrated" : "Auto-migrated";
|
|
37758
|
+
const targetSummary = result.targetPaths.length === 1 ? result.targetPath : `${result.targetPaths.length} node directories`;
|
|
37759
|
+
stdout.write(`${verb} legacy Meshy storage to ${targetSummary}
|
|
37760
|
+
`);
|
|
37761
|
+
stdout.write(`Moved: ${result.moved.join(", ")}
|
|
37762
|
+
`);
|
|
37763
|
+
} else {
|
|
37764
|
+
stdout.write(`No legacy Meshy storage entries found for migration under ${result.sourcePath}
|
|
37765
|
+
`);
|
|
37766
|
+
}
|
|
37767
|
+
if (result.dropped.length > 0) {
|
|
37768
|
+
stdout.write(`Dropped: ${result.dropped.join(", ")}
|
|
37769
|
+
`);
|
|
37770
|
+
}
|
|
37771
|
+
if (result.skipped.length > 0) {
|
|
37772
|
+
stderr.write(`Skipped existing target entries: ${result.skipped.join(", ")}
|
|
37773
|
+
`);
|
|
37774
|
+
}
|
|
37775
|
+
return result;
|
|
37776
|
+
}
|
|
37777
|
+
|
|
37778
|
+
// ../../packages/cli/src/runner.ts
|
|
37779
|
+
async function runMeshyCli(argv, deps) {
|
|
37780
|
+
const parsed = parseArgs(argv);
|
|
37781
|
+
const command = parsed.command ?? "start";
|
|
37782
|
+
const stdout = deps.stdout ?? process.stdout;
|
|
37783
|
+
const stderr = deps.stderr ?? process.stderr;
|
|
37784
|
+
if (parsed.help) {
|
|
37785
|
+
stdout.write(`${formatHelp(parsed.command)}
|
|
37786
|
+
`);
|
|
37787
|
+
return 0;
|
|
37788
|
+
}
|
|
37789
|
+
if (command === "start") {
|
|
37790
|
+
await deps.startNode(parsed);
|
|
37791
|
+
return 0;
|
|
37792
|
+
}
|
|
37793
|
+
const ctx = {
|
|
37794
|
+
argv,
|
|
37795
|
+
command,
|
|
37796
|
+
commandArgs: argsAfterCommand(argv, command),
|
|
37797
|
+
fetchImpl: deps.fetchImpl ?? fetch,
|
|
37798
|
+
stdout,
|
|
37799
|
+
stderr
|
|
37800
|
+
};
|
|
37801
|
+
try {
|
|
37802
|
+
switch (command) {
|
|
37803
|
+
case "status":
|
|
37804
|
+
await runStatus(ctx);
|
|
37805
|
+
return 0;
|
|
37806
|
+
case "promote":
|
|
37807
|
+
await runPromote(ctx);
|
|
37808
|
+
return 0;
|
|
37809
|
+
case "health":
|
|
37810
|
+
await runHealth(ctx);
|
|
37811
|
+
return 0;
|
|
37812
|
+
case "info":
|
|
37813
|
+
await runInfo(ctx);
|
|
37814
|
+
return 0;
|
|
37815
|
+
case "metrics":
|
|
37816
|
+
await runMetrics(ctx);
|
|
37817
|
+
return 0;
|
|
37818
|
+
case "tasks":
|
|
37819
|
+
await runTasks(ctx);
|
|
37820
|
+
return 0;
|
|
37821
|
+
case "task":
|
|
37822
|
+
return await runTask(ctx);
|
|
37823
|
+
case "nodes":
|
|
37824
|
+
await runNodes(ctx);
|
|
37825
|
+
return 0;
|
|
37826
|
+
case "node":
|
|
37827
|
+
return runNode(ctx);
|
|
37828
|
+
case "cluster":
|
|
37829
|
+
return await runCluster(ctx);
|
|
37830
|
+
}
|
|
37831
|
+
} catch (err) {
|
|
37832
|
+
stderr.write(`${err instanceof Error ? err.message : String(err)}
|
|
37833
|
+
`);
|
|
37834
|
+
return 1;
|
|
37835
|
+
}
|
|
37836
|
+
}
|
|
37837
|
+
function argsAfterCommand(argv, command) {
|
|
37838
|
+
const index = argv.indexOf(command);
|
|
37839
|
+
return index >= 0 ? argv.slice(index + 1) : [];
|
|
37840
|
+
}
|
|
37841
|
+
function getOption(args, names) {
|
|
37842
|
+
for (let i = 0; i < args.length; i++) {
|
|
37843
|
+
const arg = args[i];
|
|
37844
|
+
if (!arg) {
|
|
37845
|
+
continue;
|
|
37846
|
+
}
|
|
37847
|
+
for (const name2 of names) {
|
|
37848
|
+
if (arg === name2) {
|
|
37849
|
+
return args[i + 1];
|
|
37850
|
+
}
|
|
37851
|
+
if (arg.startsWith(`${name2}=`)) {
|
|
37852
|
+
return arg.slice(name2.length + 1);
|
|
37853
|
+
}
|
|
37854
|
+
}
|
|
37855
|
+
}
|
|
37856
|
+
return void 0;
|
|
37857
|
+
}
|
|
37858
|
+
function hasFlag(args, name2) {
|
|
37859
|
+
return args.includes(name2);
|
|
37860
|
+
}
|
|
37861
|
+
function getPort(args) {
|
|
37862
|
+
const value = getOption(args, ["--port", "-p"]);
|
|
37863
|
+
const port = value === void 0 ? DEFAULT_NODE_PORT : Number(value);
|
|
37864
|
+
return Number.isInteger(port) && port > 0 ? port : DEFAULT_NODE_PORT;
|
|
37865
|
+
}
|
|
37866
|
+
function getPositionals(args) {
|
|
37867
|
+
const result = [];
|
|
37868
|
+
const optionsWithValues = /* @__PURE__ */ new Set([
|
|
37869
|
+
"--agent",
|
|
37870
|
+
"-a",
|
|
37871
|
+
"--assign",
|
|
37872
|
+
"--caps",
|
|
37873
|
+
"--description",
|
|
37874
|
+
"-d",
|
|
37875
|
+
"--endpoint",
|
|
37876
|
+
"--host",
|
|
37877
|
+
"--id",
|
|
37878
|
+
"--name",
|
|
37879
|
+
"-n",
|
|
37880
|
+
"--node-id",
|
|
37881
|
+
"--port",
|
|
37882
|
+
"-p",
|
|
37883
|
+
"--priority",
|
|
37884
|
+
"-P",
|
|
37885
|
+
"--project",
|
|
37886
|
+
"--status",
|
|
37887
|
+
"-s",
|
|
37888
|
+
"--storage",
|
|
37889
|
+
"--title",
|
|
37890
|
+
"-t"
|
|
37891
|
+
]);
|
|
37892
|
+
for (let i = 0; i < args.length; i++) {
|
|
37893
|
+
const arg = args[i];
|
|
37894
|
+
if (!arg) {
|
|
37895
|
+
continue;
|
|
37896
|
+
}
|
|
37897
|
+
if (optionsWithValues.has(arg)) {
|
|
37898
|
+
i += 1;
|
|
37899
|
+
continue;
|
|
37900
|
+
}
|
|
37901
|
+
if (arg.startsWith("-")) {
|
|
37902
|
+
continue;
|
|
37903
|
+
}
|
|
37904
|
+
result.push(arg);
|
|
37905
|
+
}
|
|
37906
|
+
return result;
|
|
37907
|
+
}
|
|
37908
|
+
async function apiFetch(ctx, port, apiPath) {
|
|
37909
|
+
const res = await ctx.fetchImpl(`http://localhost:${port}${apiPath}`);
|
|
37910
|
+
if (!res.ok) {
|
|
37911
|
+
const body = await res.json().catch(() => null);
|
|
37912
|
+
throw new Error(body?.error?.message ?? `API error: ${res.status} ${res.statusText}`);
|
|
37913
|
+
}
|
|
37914
|
+
return res.json();
|
|
37915
|
+
}
|
|
37916
|
+
async function apiWrite(ctx, method, port, apiPath, body) {
|
|
37917
|
+
const res = await ctx.fetchImpl(`http://localhost:${port}${apiPath}`, {
|
|
37918
|
+
method,
|
|
37919
|
+
headers: { "Content-Type": "application/json" },
|
|
37920
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
37921
|
+
});
|
|
37922
|
+
if (!res.ok) {
|
|
37923
|
+
const data = await res.json().catch(() => null);
|
|
37924
|
+
throw new Error(data?.error?.message ?? `HTTP ${res.status}`);
|
|
37925
|
+
}
|
|
37926
|
+
return res.json();
|
|
37927
|
+
}
|
|
37928
|
+
function writeLines(stream, lines) {
|
|
37929
|
+
stream.write(`${lines.join("\n")}
|
|
37930
|
+
`);
|
|
37931
|
+
}
|
|
37932
|
+
function formatDate(value) {
|
|
37933
|
+
return value ? new Date(String(value)).toISOString() : "Never";
|
|
37934
|
+
}
|
|
37935
|
+
async function runStatus(ctx) {
|
|
37936
|
+
const port = getPort(ctx.commandArgs);
|
|
37937
|
+
const data = await apiFetch(ctx, port, "/api/cluster/state");
|
|
37938
|
+
const lines = ["", " Cluster Status", ` Leader: ${data.leaderId ?? "none"}`, ` Term: ${data.term}`, ""];
|
|
37939
|
+
if (data.nodes?.length) {
|
|
37940
|
+
lines.push(` Nodes (${data.nodes.length}):`);
|
|
37941
|
+
const header = ` ${"ID".padEnd(24)} ${"Name".padEnd(16)} ${"Role".padEnd(10)} ${"Status".padEnd(10)} Endpoint`;
|
|
37942
|
+
lines.push(header, ` ${"-".repeat(header.length - 2)}`);
|
|
37943
|
+
for (const node of data.nodes) {
|
|
37944
|
+
lines.push(` ${node.id.padEnd(24)} ${node.name.padEnd(16)} ${node.role.padEnd(10)} ${node.status.padEnd(10)} ${node.endpoint}`);
|
|
37945
|
+
}
|
|
37946
|
+
}
|
|
37947
|
+
if (data.taskSummary) {
|
|
37948
|
+
const summary = data.taskSummary;
|
|
37949
|
+
lines.push("", ` Tasks: ${summary.total} total | ${summary.pending} pending | ${summary.running} running | ${summary.completed} completed | ${summary.failed} failed`);
|
|
37950
|
+
}
|
|
37951
|
+
lines.push("");
|
|
37952
|
+
writeLines(ctx.stdout, lines);
|
|
37953
|
+
}
|
|
37954
|
+
async function runPromote(ctx) {
|
|
37955
|
+
const port = getPort(ctx.commandArgs);
|
|
37956
|
+
const host = getOption(ctx.commandArgs, ["--host"]) ?? "localhost";
|
|
37957
|
+
const res = await ctx.fetchImpl(`http://${host}:${port}/api/cluster/promote`, {
|
|
37958
|
+
method: "POST",
|
|
37959
|
+
headers: { "Content-Type": "application/json" }
|
|
37960
|
+
});
|
|
37961
|
+
if (!res.ok) {
|
|
37962
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
37963
|
+
}
|
|
37964
|
+
writeLines(ctx.stdout, [` Node at ${host}:${port} promoted to leader`]);
|
|
37965
|
+
}
|
|
37966
|
+
async function runHealth(ctx) {
|
|
37967
|
+
const data = await apiFetch(ctx, getPort(ctx.commandArgs), "/api/system/health");
|
|
37968
|
+
writeLines(ctx.stdout, [` Status: ${data.status}`, ` Time: ${new Date(data.timestamp).toISOString()}`]);
|
|
37969
|
+
}
|
|
37970
|
+
async function runInfo(ctx) {
|
|
37971
|
+
const data = await apiFetch(ctx, getPort(ctx.commandArgs), "/api/system/info");
|
|
37972
|
+
const lines = ["", " Node Info", ` ID: ${data.nodeId ?? data.id}`, ` Name: ${data.name}`, ` Role: ${data.role}`, ` Status: ${data.status}`, ` Endpoint: ${data.endpoint}`];
|
|
37973
|
+
if (data.workDir) {
|
|
37974
|
+
lines.push(` WorkDir: ${data.workDir}`);
|
|
37975
|
+
}
|
|
37976
|
+
lines.push(` Version: ${data.version}`, ` Uptime: ${Math.floor((data.uptime ?? 0) / 1e3)}s`);
|
|
37977
|
+
if (data.capabilities?.length) {
|
|
37978
|
+
lines.push(` Caps: ${data.capabilities.join(", ")}`);
|
|
37979
|
+
}
|
|
37980
|
+
lines.push("");
|
|
37981
|
+
writeLines(ctx.stdout, lines);
|
|
37982
|
+
}
|
|
37983
|
+
async function runMetrics(ctx) {
|
|
37984
|
+
const metrics = await apiFetch(ctx, getPort(ctx.commandArgs), "/api/system/metrics");
|
|
37985
|
+
const lines = ["", " Task Metrics", ` Total: ${metrics.total}`, ` Assigned: ${metrics.assigned}`, ` Unassigned: ${metrics.unassigned}`, ` Completed/1h: ${metrics.completedLast1h}`, ` Failed/1h: ${metrics.failedLast1h}`, ` Avg Time: ${Math.round(metrics.avgCompletionTime)}ms`];
|
|
37986
|
+
if (metrics.byStatus) {
|
|
37987
|
+
lines.push(` By Status: ${Object.entries(metrics.byStatus).map(([key, value]) => `${key}=${value}`).join(" ")}`);
|
|
37988
|
+
}
|
|
37989
|
+
if (metrics.byPriority) {
|
|
37990
|
+
lines.push(` By Priority: ${Object.entries(metrics.byPriority).map(([key, value]) => `${key}=${value}`).join(" ")}`);
|
|
37991
|
+
}
|
|
37992
|
+
lines.push("");
|
|
37993
|
+
writeLines(ctx.stdout, lines);
|
|
37994
|
+
}
|
|
37995
|
+
async function runTasks(ctx) {
|
|
37996
|
+
const params = new URLSearchParams();
|
|
37997
|
+
const status = getOption(ctx.commandArgs, ["--status", "-s"]);
|
|
37998
|
+
const priority = getOption(ctx.commandArgs, ["--priority", "-P"]);
|
|
37999
|
+
if (status) {
|
|
38000
|
+
params.set("status", status);
|
|
38001
|
+
}
|
|
38002
|
+
if (priority) {
|
|
38003
|
+
params.set("priority", priority);
|
|
38004
|
+
}
|
|
38005
|
+
const query = params.toString();
|
|
38006
|
+
const data = await apiFetch(ctx, getPort(ctx.commandArgs), `/api/tasks${query ? `?${query}` : ""}`);
|
|
38007
|
+
const lines = ["", ` Tasks (${data.total} total):`];
|
|
38008
|
+
if (!data.tasks?.length) {
|
|
38009
|
+
lines.push(" No tasks found.");
|
|
38010
|
+
} else {
|
|
38011
|
+
const header = ` ${"ID".padEnd(38)} ${"Title".padEnd(20)} ${"Agent".padEnd(16)} ${"Status".padEnd(12)} ${"Priority".padEnd(10)} Assigned To`;
|
|
38012
|
+
lines.push(header, ` ${"-".repeat(header.length - 2)}`);
|
|
38013
|
+
for (const task of data.tasks) {
|
|
38014
|
+
lines.push(` ${task.id.padEnd(38)} ${(task.title || "").slice(0, 18).padEnd(20)} ${(task.agent || "-").slice(0, 14).padEnd(16)} ${task.status.padEnd(12)} ${task.priority.padEnd(10)} ${task.assignedTo ?? "unassigned"}`);
|
|
38015
|
+
}
|
|
38016
|
+
}
|
|
38017
|
+
lines.push("");
|
|
38018
|
+
writeLines(ctx.stdout, lines);
|
|
38019
|
+
}
|
|
38020
|
+
async function runTask(ctx) {
|
|
38021
|
+
const [subcommand, taskId, nodeId] = getPositionals(ctx.commandArgs);
|
|
38022
|
+
const port = getPort(ctx.commandArgs);
|
|
38023
|
+
switch (subcommand) {
|
|
38024
|
+
case "create": {
|
|
38025
|
+
const agent = getOption(ctx.commandArgs, ["--agent", "-a"]);
|
|
38026
|
+
const title = getOption(ctx.commandArgs, ["--title", "-t"]);
|
|
38027
|
+
if (!title || !agent) {
|
|
38028
|
+
throw new Error(" Failed: task create requires --title and --agent");
|
|
38029
|
+
}
|
|
38030
|
+
const validAgents = ["mars", "codex", "claudecode", "eureka"];
|
|
38031
|
+
if (!validAgents.includes(agent)) {
|
|
38032
|
+
throw new Error(` Invalid agent '${agent}'. Must be one of: ${validAgents.join(", ")}`);
|
|
38033
|
+
}
|
|
38034
|
+
const body = {
|
|
38035
|
+
title,
|
|
38036
|
+
agent,
|
|
38037
|
+
description: getOption(ctx.commandArgs, ["--description", "-d"]) ?? "",
|
|
38038
|
+
priority: getOption(ctx.commandArgs, ["--priority", "-P"]) ?? "normal"
|
|
38039
|
+
};
|
|
38040
|
+
const project = getOption(ctx.commandArgs, ["--project"]);
|
|
38041
|
+
const assign = getOption(ctx.commandArgs, ["--assign"]);
|
|
38042
|
+
if (project) {
|
|
38043
|
+
body.project = project;
|
|
38044
|
+
}
|
|
38045
|
+
if (assign) {
|
|
38046
|
+
body.assignTo = assign;
|
|
38047
|
+
}
|
|
38048
|
+
const created = await apiWrite(ctx, "POST", port, "/api/tasks", body);
|
|
38049
|
+
writeLines(ctx.stdout, [` Task created: ${created.id}`, ` Title: ${created.title}`, ` Agent: ${created.agent}`, ` Priority: ${created.priority}`, ` Status: ${created.status}`]);
|
|
38050
|
+
return 0;
|
|
38051
|
+
}
|
|
38052
|
+
case "get": {
|
|
38053
|
+
if (!taskId) {
|
|
38054
|
+
throw new Error(" Failed: task get requires <taskId>");
|
|
38055
|
+
}
|
|
38056
|
+
const task = await apiFetch(ctx, port, `/api/tasks/${taskId}`);
|
|
38057
|
+
const lines = ["", ` ID: ${task.id}`, ` Title: ${task.title}`, ` Agent: ${task.agent}`];
|
|
38058
|
+
if (task.project) {
|
|
38059
|
+
lines.push(` Project: ${task.project}`);
|
|
38060
|
+
}
|
|
38061
|
+
lines.push(` Description: ${task.description || "(none)"}`, ` Status: ${task.status}`, ` Priority: ${task.priority}`, ` Assigned To: ${task.assignedTo ?? "unassigned"}`, ` Retries: ${task.retryCount}/${task.maxRetries}`);
|
|
38062
|
+
if (task.error) {
|
|
38063
|
+
lines.push(` Error: ${task.error}`);
|
|
38064
|
+
}
|
|
38065
|
+
if (task.result) {
|
|
38066
|
+
lines.push(` Result: ${JSON.stringify(task.result)}`);
|
|
38067
|
+
}
|
|
38068
|
+
lines.push(` Created: ${formatDate(task.createdAt)}`, ` Updated: ${formatDate(task.updatedAt)}`, "");
|
|
38069
|
+
writeLines(ctx.stdout, lines);
|
|
38070
|
+
return 0;
|
|
38071
|
+
}
|
|
38072
|
+
case "update": {
|
|
38073
|
+
if (!taskId) {
|
|
38074
|
+
throw new Error(" Failed: task update requires <taskId>");
|
|
38075
|
+
}
|
|
38076
|
+
const body = {};
|
|
38077
|
+
const priority = getOption(ctx.commandArgs, ["--priority", "-P"]);
|
|
38078
|
+
const status = getOption(ctx.commandArgs, ["--status", "-s"]);
|
|
38079
|
+
const assign = getOption(ctx.commandArgs, ["--assign"]);
|
|
38080
|
+
if (priority) {
|
|
38081
|
+
body.priority = priority;
|
|
38082
|
+
}
|
|
38083
|
+
if (status) {
|
|
38084
|
+
body.status = status;
|
|
38085
|
+
}
|
|
38086
|
+
if (assign !== void 0) {
|
|
38087
|
+
body.assignedTo = assign === "null" ? null : assign;
|
|
38088
|
+
}
|
|
38089
|
+
const task = await apiWrite(ctx, "PATCH", port, `/api/tasks/${taskId}`, body);
|
|
38090
|
+
writeLines(ctx.stdout, [` Task ${task.id} updated (status: ${task.status}, priority: ${task.priority})`]);
|
|
38091
|
+
return 0;
|
|
38092
|
+
}
|
|
38093
|
+
case "assign": {
|
|
38094
|
+
if (!taskId || !nodeId) {
|
|
38095
|
+
throw new Error(" Failed: task assign requires <taskId> <nodeId>");
|
|
38096
|
+
}
|
|
38097
|
+
const task = await apiWrite(ctx, "POST", port, `/api/tasks/${taskId}/assign`, { nodeId });
|
|
38098
|
+
writeLines(ctx.stdout, [` Task ${task.id} assigned to ${nodeId} (status: ${task.status})`]);
|
|
38099
|
+
return 0;
|
|
38100
|
+
}
|
|
38101
|
+
case "cancel":
|
|
38102
|
+
case "delete":
|
|
38103
|
+
case "retry": {
|
|
38104
|
+
if (!taskId) {
|
|
38105
|
+
throw new Error(` Failed: task ${subcommand} requires <taskId>`);
|
|
38106
|
+
}
|
|
38107
|
+
if (subcommand === "delete") {
|
|
38108
|
+
await apiWrite(ctx, "DELETE", port, `/api/tasks/${taskId}`);
|
|
38109
|
+
writeLines(ctx.stdout, [` Task ${taskId} deleted`]);
|
|
38110
|
+
} else if (subcommand === "cancel") {
|
|
38111
|
+
await apiWrite(ctx, "POST", port, `/api/tasks/${taskId}/cancel`);
|
|
38112
|
+
writeLines(ctx.stdout, [` Task ${taskId} cancelled`]);
|
|
38113
|
+
} else {
|
|
38114
|
+
const task = await apiWrite(ctx, "POST", port, `/api/tasks/${taskId}/retry`);
|
|
38115
|
+
writeLines(ctx.stdout, [` Task ${task.id} queued for retry (status: ${task.status})`]);
|
|
38116
|
+
}
|
|
38117
|
+
return 0;
|
|
38118
|
+
}
|
|
38119
|
+
default:
|
|
38120
|
+
ctx.stderr.write(`${formatHelp("task")}
|
|
38121
|
+
`);
|
|
38122
|
+
return 1;
|
|
38123
|
+
}
|
|
38124
|
+
}
|
|
38125
|
+
async function runNodes(ctx) {
|
|
38126
|
+
const params = new URLSearchParams();
|
|
38127
|
+
const status = getOption(ctx.commandArgs, ["--status", "-s"]);
|
|
38128
|
+
if (status) {
|
|
38129
|
+
params.set("status", status);
|
|
38130
|
+
}
|
|
38131
|
+
const query = params.toString();
|
|
38132
|
+
const data = await apiFetch(ctx, getPort(ctx.commandArgs), `/api/nodes${query ? `?${query}` : ""}`);
|
|
38133
|
+
const nodes = data.nodes ?? [];
|
|
38134
|
+
const lines = ["", ` Nodes (${nodes.length}):`];
|
|
38135
|
+
if (nodes.length === 0) {
|
|
38136
|
+
lines.push(" No nodes found.");
|
|
38137
|
+
} else {
|
|
38138
|
+
const header = ` ${"ID".padEnd(24)} ${"Name".padEnd(16)} ${"Role".padEnd(10)} ${"Status".padEnd(10)} Endpoint`;
|
|
38139
|
+
lines.push(header, ` ${"-".repeat(header.length - 2)}`);
|
|
38140
|
+
for (const node of nodes) {
|
|
38141
|
+
lines.push(` ${node.id.padEnd(24)} ${node.name.padEnd(16)} ${node.role.padEnd(10)} ${node.status.padEnd(10)} ${node.endpoint}`);
|
|
38142
|
+
}
|
|
38143
|
+
}
|
|
38144
|
+
lines.push("");
|
|
38145
|
+
writeLines(ctx.stdout, lines);
|
|
38146
|
+
}
|
|
38147
|
+
function runNode(ctx) {
|
|
38148
|
+
const [subcommand, nodeId] = getPositionals(ctx.commandArgs);
|
|
38149
|
+
const port = getPort(ctx.commandArgs);
|
|
38150
|
+
switch (subcommand) {
|
|
38151
|
+
case "migrate":
|
|
38152
|
+
return runNodeMigrate(ctx);
|
|
38153
|
+
case "get":
|
|
38154
|
+
return runNodeGet(ctx, port, nodeId);
|
|
38155
|
+
case "status":
|
|
38156
|
+
return runNodeStatus(ctx, port, nodeId);
|
|
38157
|
+
case "update":
|
|
38158
|
+
return runNodeUpdate(ctx, port, nodeId);
|
|
38159
|
+
case "remove":
|
|
38160
|
+
return runNodeRemove(ctx, port, nodeId);
|
|
38161
|
+
default:
|
|
38162
|
+
ctx.stderr.write(`${formatHelp("node")}
|
|
38163
|
+
`);
|
|
38164
|
+
return 1;
|
|
38165
|
+
}
|
|
38166
|
+
}
|
|
38167
|
+
function runNodeMigrate(ctx) {
|
|
38168
|
+
const result = runNodeMigrateCommand({
|
|
38169
|
+
storageRoot: getOption(ctx.commandArgs, ["--storage", "-s"]),
|
|
38170
|
+
nodeName: getOption(ctx.commandArgs, ["--name", "-n"]),
|
|
38171
|
+
overwrite: hasFlag(ctx.commandArgs, "--overwrite"),
|
|
38172
|
+
stdout: ctx.stdout,
|
|
38173
|
+
stderr: ctx.stderr
|
|
38174
|
+
});
|
|
38175
|
+
return result.skipped.length > 0 && !hasFlag(ctx.commandArgs, "--overwrite") ? 1 : 0;
|
|
38176
|
+
}
|
|
38177
|
+
async function runNodeGet(ctx, port, nodeId) {
|
|
38178
|
+
if (!nodeId) {
|
|
38179
|
+
throw new Error(" Failed: node get requires <nodeId>");
|
|
38180
|
+
}
|
|
38181
|
+
const node = await apiFetch(ctx, port, `/api/nodes/${nodeId}`);
|
|
38182
|
+
writeLines(ctx.stdout, ["", ` ID: ${node.id}`, ` Name: ${node.name}`, ` Role: ${node.role}`, ` Status: ${node.status}`, ` Endpoint: ${node.endpoint}`, ` Capabilities: ${node.capabilities?.join(", ") || "(none)"}`, ` Joined: ${formatDate(node.joinedAt)}`, ` Heartbeat: ${formatDate(node.lastHeartbeat)}`, ""]);
|
|
38183
|
+
return 0;
|
|
38184
|
+
}
|
|
38185
|
+
async function runNodeStatus(ctx, port, nodeId) {
|
|
38186
|
+
if (!nodeId) {
|
|
38187
|
+
throw new Error(" Failed: node status requires <nodeId>");
|
|
38188
|
+
}
|
|
38189
|
+
const data = await apiFetch(ctx, port, `/api/nodes/${nodeId}/status`);
|
|
38190
|
+
const node = data.node;
|
|
38191
|
+
const lines = ["", ` Node: ${node.name} (${node.role}, ${node.status})`, ` Endpoint: ${node.endpoint}`, ""];
|
|
38192
|
+
if (data.tasks?.length) {
|
|
38193
|
+
lines.push(` Tasks (${data.tasks.length}):`);
|
|
38194
|
+
for (const task of data.tasks) {
|
|
38195
|
+
lines.push(` ${task.id.slice(0, 13).padEnd(15)} ${task.title.slice(0, 24).padEnd(26)} ${task.status.padEnd(12)} ${task.priority}`);
|
|
38196
|
+
}
|
|
38197
|
+
} else {
|
|
38198
|
+
lines.push(" No tasks assigned.");
|
|
38199
|
+
}
|
|
38200
|
+
lines.push("");
|
|
38201
|
+
writeLines(ctx.stdout, lines);
|
|
38202
|
+
return 0;
|
|
38203
|
+
}
|
|
38204
|
+
async function runNodeUpdate(ctx, port, nodeId) {
|
|
38205
|
+
if (!nodeId) {
|
|
38206
|
+
throw new Error(" Failed: node update requires <nodeId>");
|
|
38207
|
+
}
|
|
38208
|
+
const body = {};
|
|
38209
|
+
const name2 = getOption(ctx.commandArgs, ["--name", "-n"]);
|
|
38210
|
+
const caps = getOption(ctx.commandArgs, ["--caps"]);
|
|
38211
|
+
if (name2) {
|
|
38212
|
+
body.name = name2;
|
|
38213
|
+
}
|
|
38214
|
+
if (caps) {
|
|
38215
|
+
body.capabilities = caps.split(",").map((capability) => capability.trim());
|
|
38216
|
+
}
|
|
38217
|
+
const node = await apiWrite(ctx, "PATCH", port, `/api/nodes/${nodeId}`, body);
|
|
38218
|
+
writeLines(ctx.stdout, [` Node ${node.id} updated (name: ${node.name})`]);
|
|
38219
|
+
return 0;
|
|
38220
|
+
}
|
|
38221
|
+
async function runNodeRemove(ctx, port, nodeId) {
|
|
38222
|
+
if (!nodeId) {
|
|
38223
|
+
throw new Error(" Failed: node remove requires <nodeId>");
|
|
38224
|
+
}
|
|
38225
|
+
await apiWrite(ctx, "DELETE", port, `/api/nodes/${nodeId}`);
|
|
38226
|
+
writeLines(ctx.stdout, [` Node ${nodeId} removed`]);
|
|
38227
|
+
return 0;
|
|
38228
|
+
}
|
|
38229
|
+
async function runCluster(ctx) {
|
|
38230
|
+
const [subcommand] = getPositionals(ctx.commandArgs);
|
|
38231
|
+
const port = getPort(ctx.commandArgs);
|
|
38232
|
+
switch (subcommand) {
|
|
38233
|
+
case "join": {
|
|
38234
|
+
const id = getOption(ctx.commandArgs, ["--id"]);
|
|
38235
|
+
const endpoint = getOption(ctx.commandArgs, ["--endpoint"]);
|
|
38236
|
+
const name2 = getOption(ctx.commandArgs, ["--name", "-n"]);
|
|
38237
|
+
if (!id || !endpoint || !name2) {
|
|
38238
|
+
throw new Error(" Failed: cluster join requires --id, --endpoint, and --name");
|
|
38239
|
+
}
|
|
38240
|
+
const body = { id, endpoint, name: name2 };
|
|
38241
|
+
const caps = getOption(ctx.commandArgs, ["--caps"]);
|
|
38242
|
+
if (caps) {
|
|
38243
|
+
body.capabilities = caps.split(",").map((capability) => capability.trim());
|
|
38244
|
+
}
|
|
38245
|
+
const data = await apiWrite(ctx, "POST", port, "/api/cluster/join", body);
|
|
38246
|
+
writeLines(ctx.stdout, [" Node joined cluster", ` Cluster: ${data.clusterId}`, ` Leader: ${data.leaderId ?? "none"}`, ` Term: ${data.term}`, ` Nodes: ${data.nodes?.length ?? 0}`]);
|
|
38247
|
+
return 0;
|
|
38248
|
+
}
|
|
38249
|
+
case "leave": {
|
|
38250
|
+
const nodeId = getOption(ctx.commandArgs, ["--node-id"]);
|
|
38251
|
+
if (!nodeId) {
|
|
38252
|
+
throw new Error(" Failed: cluster leave requires --node-id");
|
|
38253
|
+
}
|
|
38254
|
+
await apiWrite(ctx, "POST", port, "/api/cluster/leave", { nodeId });
|
|
38255
|
+
writeLines(ctx.stdout, [` Node ${nodeId} left cluster`]);
|
|
38256
|
+
return 0;
|
|
38257
|
+
}
|
|
38258
|
+
default:
|
|
38259
|
+
ctx.stderr.write(`${formatHelp("cluster")}
|
|
38260
|
+
`);
|
|
38261
|
+
return 1;
|
|
38262
|
+
}
|
|
38263
|
+
}
|
|
38264
|
+
|
|
38265
|
+
// src/bootstrap/banner.ts
|
|
38266
|
+
function formatBanner(info) {
|
|
38267
|
+
const lines = [
|
|
38268
|
+
`Node: ${info.name}`,
|
|
38269
|
+
`Role: ${info.role} (term ${info.term})`,
|
|
38270
|
+
`Endpoint: ${info.endpoint}`,
|
|
38271
|
+
`Dashboard: http://localhost:${info.port}`
|
|
38272
|
+
];
|
|
38273
|
+
if (info.dashboardOrigin) {
|
|
38274
|
+
lines.push(`Dashboard Tunnel: ${info.dashboardOrigin}`);
|
|
38275
|
+
}
|
|
38276
|
+
const maxLen = Math.max(...lines.map((line) => line.length));
|
|
38277
|
+
const innerWidth = maxLen + 4;
|
|
38278
|
+
const top = ` \u256D${"\u2500".repeat(innerWidth)}\u256E`;
|
|
38279
|
+
const bottom = ` \u2570${"\u2500".repeat(innerWidth)}\u256F`;
|
|
38280
|
+
const body = lines.map((line) => ` \u2502 ${line.padEnd(maxLen + 2)}\u2502`);
|
|
38281
|
+
return [top, ...body, bottom].join("\n");
|
|
38282
|
+
}
|
|
38283
|
+
|
|
38284
|
+
// src/bootstrap/process.ts
|
|
38285
|
+
var fs12 = __toESM(require("fs"), 1);
|
|
38286
|
+
var nodePath = __toESM(require("path"), 1);
|
|
38287
|
+
var startupFatalLogPath;
|
|
38288
|
+
function getErrorMessage2(err) {
|
|
38289
|
+
if (err instanceof Error) {
|
|
38290
|
+
return err.message;
|
|
38291
|
+
}
|
|
38292
|
+
return String(err);
|
|
38293
|
+
}
|
|
38294
|
+
function setStartupFatalLogPath(logPath) {
|
|
38295
|
+
startupFatalLogPath = logPath;
|
|
38296
|
+
}
|
|
38297
|
+
function formatFatalErrorForConsole(err) {
|
|
38298
|
+
return `Fatal error: ${getErrorMessage2(err)}`;
|
|
38299
|
+
}
|
|
38300
|
+
function formatFatalErrorForLog(err, now = /* @__PURE__ */ new Date()) {
|
|
38301
|
+
const details = err instanceof Error ? err.stack ?? `${err.name}: ${err.message}` : String(err);
|
|
38302
|
+
return `[${now.toISOString()}] Fatal startup error
|
|
38303
|
+
${details}
|
|
38304
|
+
`;
|
|
38305
|
+
}
|
|
38306
|
+
function writeStartupFatalError(err, logPath = startupFatalLogPath) {
|
|
38307
|
+
if (!logPath) {
|
|
38308
|
+
return void 0;
|
|
38309
|
+
}
|
|
38310
|
+
fs12.mkdirSync(nodePath.dirname(logPath), { recursive: true });
|
|
38311
|
+
fs12.appendFileSync(logPath, formatFatalErrorForLog(err), "utf-8");
|
|
38312
|
+
return logPath;
|
|
38313
|
+
}
|
|
38314
|
+
async function closeHttpServer(server, options = {}) {
|
|
38315
|
+
if (!server) {
|
|
38316
|
+
return;
|
|
38317
|
+
}
|
|
38318
|
+
const forceAfterMs = options.forceAfterMs ?? 1e3;
|
|
38319
|
+
await new Promise((resolve14, reject) => {
|
|
38320
|
+
const forceTimer = setTimeout(() => {
|
|
38321
|
+
server.closeAllConnections?.();
|
|
38322
|
+
server.closeIdleConnections?.();
|
|
38323
|
+
}, forceAfterMs);
|
|
38324
|
+
forceTimer.unref?.();
|
|
38325
|
+
server.close((err) => {
|
|
38326
|
+
clearTimeout(forceTimer);
|
|
38327
|
+
if (err) {
|
|
38328
|
+
reject(err);
|
|
38329
|
+
return;
|
|
38330
|
+
}
|
|
38331
|
+
resolve14();
|
|
38332
|
+
});
|
|
38333
|
+
server.closeIdleConnections?.();
|
|
38334
|
+
});
|
|
38335
|
+
}
|
|
38336
|
+
function isDirectRunPath(entryPath) {
|
|
38337
|
+
if (!entryPath) {
|
|
38338
|
+
return false;
|
|
38339
|
+
}
|
|
38340
|
+
const entryName = entryPath.split(/[/\\]/).pop()?.toLowerCase();
|
|
38341
|
+
if (!entryName) {
|
|
38342
|
+
return false;
|
|
38343
|
+
}
|
|
38344
|
+
return entryName === "meshy" || entryName === "meshy.cmd" || entryName === "main.js" || entryName === "main.cjs" || entryName === "main.ts";
|
|
38345
|
+
}
|
|
38346
|
+
|
|
38347
|
+
// src/bootstrap/start-node.ts
|
|
38348
|
+
var nodePath2 = __toESM(require("path"), 1);
|
|
38349
|
+
|
|
37155
38350
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
37156
38351
|
var external_exports = {};
|
|
37157
38352
|
__export(external_exports, {
|
|
@@ -37630,8 +38825,8 @@ function getErrorMap() {
|
|
|
37630
38825
|
|
|
37631
38826
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
37632
38827
|
var makeIssue = (params) => {
|
|
37633
|
-
const { data, path:
|
|
37634
|
-
const fullPath = [...
|
|
38828
|
+
const { data, path: path21, errorMaps, issueData } = params;
|
|
38829
|
+
const fullPath = [...path21, ...issueData.path || []];
|
|
37635
38830
|
const fullIssue = {
|
|
37636
38831
|
...issueData,
|
|
37637
38832
|
path: fullPath
|
|
@@ -37747,11 +38942,11 @@ var errorUtil;
|
|
|
37747
38942
|
|
|
37748
38943
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
37749
38944
|
var ParseInputLazyPath = class {
|
|
37750
|
-
constructor(parent, value,
|
|
38945
|
+
constructor(parent, value, path21, key) {
|
|
37751
38946
|
this._cachedPath = [];
|
|
37752
38947
|
this.parent = parent;
|
|
37753
38948
|
this.data = value;
|
|
37754
|
-
this._path =
|
|
38949
|
+
this._path = path21;
|
|
37755
38950
|
this._key = key;
|
|
37756
38951
|
}
|
|
37757
38952
|
get path() {
|
|
@@ -41609,8 +42804,8 @@ var BatchTaskIdsBody = external_exports.object({
|
|
|
41609
42804
|
});
|
|
41610
42805
|
|
|
41611
42806
|
// ../../packages/api/src/app/server.ts
|
|
41612
|
-
var
|
|
41613
|
-
var
|
|
42807
|
+
var path18 = __toESM(require("path"), 1);
|
|
42808
|
+
var fs17 = __toESM(require("fs"), 1);
|
|
41614
42809
|
var import_express12 = __toESM(require_express2(), 1);
|
|
41615
42810
|
|
|
41616
42811
|
// ../../packages/api/src/middleware/auth.ts
|
|
@@ -42062,11 +43257,11 @@ function assertCanChangeNodeDevTunnel(taskEngine, nodeId) {
|
|
|
42062
43257
|
var import_express3 = __toESM(require_express2(), 1);
|
|
42063
43258
|
|
|
42064
43259
|
// ../../packages/api/src/node/node-workdir-service.ts
|
|
42065
|
-
var
|
|
43260
|
+
var path15 = __toESM(require("path"), 1);
|
|
42066
43261
|
|
|
42067
43262
|
// ../../packages/api/src/output/helpers.ts
|
|
42068
|
-
var
|
|
42069
|
-
var
|
|
43263
|
+
var fs13 = __toESM(require("fs"), 1);
|
|
43264
|
+
var path14 = __toESM(require("path"), 1);
|
|
42070
43265
|
var MAX_INLINE_SIZE = 512 * 1024;
|
|
42071
43266
|
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
42072
43267
|
".txt",
|
|
@@ -42179,15 +43374,15 @@ function mimeForExt(ext) {
|
|
|
42179
43374
|
return MIME_MAP[ext] ?? "application/octet-stream";
|
|
42180
43375
|
}
|
|
42181
43376
|
function resolveOutputPath(root, relativePath) {
|
|
42182
|
-
const resolved =
|
|
42183
|
-
const normalizedRoot =
|
|
42184
|
-
if (!resolved.startsWith(normalizedRoot +
|
|
43377
|
+
const resolved = path14.resolve(root, relativePath);
|
|
43378
|
+
const normalizedRoot = path14.resolve(root);
|
|
43379
|
+
if (!resolved.startsWith(normalizedRoot + path14.sep) && resolved !== normalizedRoot) {
|
|
42185
43380
|
throw new Error("Path traversal detected");
|
|
42186
43381
|
}
|
|
42187
43382
|
return resolved;
|
|
42188
43383
|
}
|
|
42189
43384
|
function classifyFile(filePath) {
|
|
42190
|
-
const ext =
|
|
43385
|
+
const ext = path14.extname(filePath).toLowerCase();
|
|
42191
43386
|
if (ext === ".json" || ext === ".jsonl" || ext === ".ndjson") {
|
|
42192
43387
|
return { kind: "json", mimeType: "application/json" };
|
|
42193
43388
|
}
|
|
@@ -42217,21 +43412,21 @@ function listDirectory(root, relativePath, options = {}) {
|
|
|
42217
43412
|
return listResolvedDirectory(absPath, relativePath, options);
|
|
42218
43413
|
}
|
|
42219
43414
|
function listAbsoluteDirectory(absoluteDir, options = {}) {
|
|
42220
|
-
if (!
|
|
43415
|
+
if (!path14.isAbsolute(absoluteDir)) {
|
|
42221
43416
|
throw new Error("listAbsoluteDirectory requires an absolute path");
|
|
42222
43417
|
}
|
|
42223
43418
|
return listResolvedDirectory(absoluteDir, absoluteDir, { ...options, childPathStyle: "absolute" });
|
|
42224
43419
|
}
|
|
42225
43420
|
function listResolvedDirectory(absPath, relativeBase, options = {}) {
|
|
42226
|
-
if (!
|
|
43421
|
+
if (!fs13.existsSync(absPath) || !fs13.statSync(absPath).isDirectory()) {
|
|
42227
43422
|
return [];
|
|
42228
43423
|
}
|
|
42229
|
-
const entries =
|
|
43424
|
+
const entries = fs13.readdirSync(absPath, { withFileTypes: true });
|
|
42230
43425
|
const result = [];
|
|
42231
43426
|
const childPathStyle = options.childPathStyle ?? "relative";
|
|
42232
43427
|
for (const entry of entries) {
|
|
42233
43428
|
if (entry.name.startsWith(".")) continue;
|
|
42234
|
-
const entryRelPath = childPathStyle === "absolute" ?
|
|
43429
|
+
const entryRelPath = childPathStyle === "absolute" ? path14.join(absPath, entry.name) : path14.join(relativeBase || ".", entry.name).split(path14.sep).join("/");
|
|
42235
43430
|
if (entry.isDirectory()) {
|
|
42236
43431
|
result.push({
|
|
42237
43432
|
path: entryRelPath,
|
|
@@ -42241,8 +43436,8 @@ function listResolvedDirectory(absPath, relativeBase, options = {}) {
|
|
|
42241
43436
|
} else if (options.directoriesOnly) {
|
|
42242
43437
|
continue;
|
|
42243
43438
|
} else if (entry.isFile()) {
|
|
42244
|
-
const fullPath =
|
|
42245
|
-
const stat =
|
|
43439
|
+
const fullPath = path14.join(absPath, entry.name);
|
|
43440
|
+
const stat = fs13.statSync(fullPath);
|
|
42246
43441
|
const { kind, mimeType } = classifyFile(entry.name);
|
|
42247
43442
|
result.push({
|
|
42248
43443
|
path: entryRelPath,
|
|
@@ -42262,11 +43457,11 @@ function listResolvedDirectory(absPath, relativeBase, options = {}) {
|
|
|
42262
43457
|
}
|
|
42263
43458
|
function detectHtmlEntries(root) {
|
|
42264
43459
|
const entries = [];
|
|
42265
|
-
if (
|
|
43460
|
+
if (fs13.existsSync(path14.join(root, "index.html"))) {
|
|
42266
43461
|
entries.push({ path: "index.html", label: "index.html" });
|
|
42267
43462
|
}
|
|
42268
43463
|
try {
|
|
42269
|
-
const topLevel =
|
|
43464
|
+
const topLevel = fs13.readdirSync(root, { withFileTypes: true });
|
|
42270
43465
|
const htmlFiles = topLevel.filter(
|
|
42271
43466
|
(e) => e.isFile() && e.name.endsWith(".html") && !e.name.startsWith(".")
|
|
42272
43467
|
);
|
|
@@ -42277,8 +43472,8 @@ function detectHtmlEntries(root) {
|
|
|
42277
43472
|
}
|
|
42278
43473
|
const subdirs = topLevel.filter((e) => e.isDirectory() && !e.name.startsWith("."));
|
|
42279
43474
|
for (const dir of subdirs) {
|
|
42280
|
-
const subIndex =
|
|
42281
|
-
if (
|
|
43475
|
+
const subIndex = path14.join(root, dir.name, "index.html");
|
|
43476
|
+
if (fs13.existsSync(subIndex)) {
|
|
42282
43477
|
entries.push({
|
|
42283
43478
|
path: `${dir.name}/index.html`,
|
|
42284
43479
|
label: `${dir.name}/index.html`
|
|
@@ -42290,11 +43485,11 @@ function detectHtmlEntries(root) {
|
|
|
42290
43485
|
return entries;
|
|
42291
43486
|
}
|
|
42292
43487
|
function getOutputSummary(root) {
|
|
42293
|
-
const rootName =
|
|
43488
|
+
const rootName = path14.basename(root);
|
|
42294
43489
|
const htmlEntries = detectHtmlEntries(root);
|
|
42295
43490
|
let fileCount;
|
|
42296
43491
|
try {
|
|
42297
|
-
const entries =
|
|
43492
|
+
const entries = fs13.readdirSync(root, { withFileTypes: true });
|
|
42298
43493
|
fileCount = entries.filter((e) => !e.name.startsWith(".")).length;
|
|
42299
43494
|
} catch {
|
|
42300
43495
|
fileCount = void 0;
|
|
@@ -42310,14 +43505,14 @@ function getOutputSummary(root) {
|
|
|
42310
43505
|
}
|
|
42311
43506
|
function readFileContent(root, relativePath) {
|
|
42312
43507
|
const absPath = resolveOutputPath(root, relativePath);
|
|
42313
|
-
if (!
|
|
43508
|
+
if (!fs13.existsSync(absPath) || !fs13.statSync(absPath).isFile()) {
|
|
42314
43509
|
throw new Error("File not found");
|
|
42315
43510
|
}
|
|
42316
|
-
const stat =
|
|
43511
|
+
const stat = fs13.statSync(absPath);
|
|
42317
43512
|
const { kind, mimeType } = classifyFile(absPath);
|
|
42318
43513
|
if (kind === "image" || kind === "pdf" || kind === "binary") {
|
|
42319
43514
|
const truncated2 = stat.size > MAX_INLINE_SIZE;
|
|
42320
|
-
const buffer = truncated2 ? Buffer.alloc(0) :
|
|
43515
|
+
const buffer = truncated2 ? Buffer.alloc(0) : fs13.readFileSync(absPath);
|
|
42321
43516
|
return {
|
|
42322
43517
|
path: relativePath,
|
|
42323
43518
|
kind,
|
|
@@ -42328,7 +43523,7 @@ function readFileContent(root, relativePath) {
|
|
|
42328
43523
|
};
|
|
42329
43524
|
}
|
|
42330
43525
|
const truncated = stat.size > MAX_INLINE_SIZE;
|
|
42331
|
-
const content = truncated ?
|
|
43526
|
+
const content = truncated ? fs13.readFileSync(absPath, "utf-8").slice(0, MAX_INLINE_SIZE) : fs13.readFileSync(absPath, "utf-8");
|
|
42332
43527
|
return {
|
|
42333
43528
|
path: relativePath,
|
|
42334
43529
|
kind,
|
|
@@ -42573,14 +43768,14 @@ function getGitDiff(dirPath) {
|
|
|
42573
43768
|
|
|
42574
43769
|
// ../../packages/api/src/node/node-workdir-service.ts
|
|
42575
43770
|
function isAbsolutePath(p) {
|
|
42576
|
-
return
|
|
43771
|
+
return path15.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p);
|
|
42577
43772
|
}
|
|
42578
43773
|
function resolveNodeWorkDirTarget(nodeId, rootPath, currentPath, allowAbsolute) {
|
|
42579
43774
|
if (!rootPath) {
|
|
42580
43775
|
throw new MeshyError("VALIDATION_ERROR", `Node ${nodeId} does not expose a working directory`, 400);
|
|
42581
43776
|
}
|
|
42582
43777
|
const useAbsolute = allowAbsolute && isAbsolutePath(currentPath);
|
|
42583
|
-
const resolvedPath = useAbsolute ?
|
|
43778
|
+
const resolvedPath = useAbsolute ? path15.resolve(currentPath) : currentPath;
|
|
42584
43779
|
return {
|
|
42585
43780
|
rootPath,
|
|
42586
43781
|
resolvedPath,
|
|
@@ -42665,13 +43860,13 @@ function createLocalNodeWorkDirBranch(nodeId, rootPath, currentPath, options) {
|
|
|
42665
43860
|
}
|
|
42666
43861
|
function computeParentPath(rootPath, currentPath, useAbsolute) {
|
|
42667
43862
|
if (useAbsolute) {
|
|
42668
|
-
const parent =
|
|
43863
|
+
const parent = path15.dirname(currentPath);
|
|
42669
43864
|
return parent === currentPath ? null : parent;
|
|
42670
43865
|
}
|
|
42671
43866
|
const normalized = currentPath.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
42672
43867
|
if (normalized === "" || normalized === ".") {
|
|
42673
|
-
const absParent =
|
|
42674
|
-
return absParent ===
|
|
43868
|
+
const absParent = path15.dirname(path15.resolve(rootPath));
|
|
43869
|
+
return absParent === path15.resolve(rootPath) ? null : absParent;
|
|
42675
43870
|
}
|
|
42676
43871
|
const segments = normalized.split("/").filter(Boolean);
|
|
42677
43872
|
segments.pop();
|
|
@@ -42771,7 +43966,7 @@ function sendLocalNodeWorkDirBranchCreate(req, res, nodeId, options = {}) {
|
|
|
42771
43966
|
}
|
|
42772
43967
|
|
|
42773
43968
|
// ../../packages/api/src/tasks/task-route-utils.ts
|
|
42774
|
-
var
|
|
43969
|
+
var fs14 = __toESM(require("fs"), 1);
|
|
42775
43970
|
function restoreTaskState(taskEngine, task) {
|
|
42776
43971
|
taskEngine.updateTask(task.id, {
|
|
42777
43972
|
status: task.status,
|
|
@@ -42786,10 +43981,10 @@ function readLocalTaskLogs(engineRegistry, taskId, after, agent) {
|
|
|
42786
43981
|
throw new MeshyError("VALIDATION_ERROR", `Engine not registered for agent: ${agent}`, 400);
|
|
42787
43982
|
}
|
|
42788
43983
|
const logPath = engine.getLogPath(taskId);
|
|
42789
|
-
if (!
|
|
43984
|
+
if (!fs14.existsSync(logPath)) {
|
|
42790
43985
|
return { logs: [], total: 0 };
|
|
42791
43986
|
}
|
|
42792
|
-
const content =
|
|
43987
|
+
const content = fs14.readFileSync(logPath, "utf-8");
|
|
42793
43988
|
const allLines = content.trim().split("\n").filter(Boolean);
|
|
42794
43989
|
const logs = [];
|
|
42795
43990
|
for (let i = after; i < allLines.length; i++) {
|
|
@@ -42871,29 +44066,29 @@ function cancelTaskOnCurrentNode(deps, taskId, options = {}) {
|
|
|
42871
44066
|
}
|
|
42872
44067
|
|
|
42873
44068
|
// ../../packages/api/src/tasks/task-output-service.ts
|
|
42874
|
-
var
|
|
42875
|
-
var
|
|
44069
|
+
var fs16 = __toESM(require("fs"), 1);
|
|
44070
|
+
var path17 = __toESM(require("path"), 1);
|
|
42876
44071
|
|
|
42877
44072
|
// ../../packages/api/src/preview/preview-server.ts
|
|
42878
44073
|
var crypto3 = __toESM(require("crypto"), 1);
|
|
42879
|
-
var
|
|
42880
|
-
var
|
|
44074
|
+
var fs15 = __toESM(require("fs"), 1);
|
|
44075
|
+
var path16 = __toESM(require("path"), 1);
|
|
42881
44076
|
var http2 = __toESM(require("http"), 1);
|
|
42882
44077
|
function resolvePreviewPath(rootPath, relativePath) {
|
|
42883
44078
|
const sanitizedPath = relativePath.replace(/\\/g, "/");
|
|
42884
|
-
const resolvedPath =
|
|
42885
|
-
const normalizedRoot =
|
|
42886
|
-
if (!resolvedPath.startsWith(normalizedRoot +
|
|
44079
|
+
const resolvedPath = path16.resolve(rootPath, sanitizedPath);
|
|
44080
|
+
const normalizedRoot = path16.resolve(rootPath);
|
|
44081
|
+
if (!resolvedPath.startsWith(normalizedRoot + path16.sep) && resolvedPath !== normalizedRoot) {
|
|
42887
44082
|
throw new Error("Invalid preview path");
|
|
42888
44083
|
}
|
|
42889
44084
|
return {
|
|
42890
44085
|
absolutePath: resolvedPath,
|
|
42891
|
-
normalizedPath:
|
|
44086
|
+
normalizedPath: path16.relative(normalizedRoot, resolvedPath).split(path16.sep).join("/")
|
|
42892
44087
|
};
|
|
42893
44088
|
}
|
|
42894
44089
|
function resolvePreviewEntryPath(rootPath, entryPath) {
|
|
42895
44090
|
const { absolutePath, normalizedPath } = resolvePreviewPath(rootPath, entryPath ?? "index.html");
|
|
42896
|
-
if (!
|
|
44091
|
+
if (!fs15.existsSync(absolutePath) || !fs15.statSync(absolutePath).isFile()) {
|
|
42897
44092
|
throw new Error("Preview entry not found");
|
|
42898
44093
|
}
|
|
42899
44094
|
return normalizedPath;
|
|
@@ -42957,7 +44152,7 @@ var MIME_MAP2 = {
|
|
|
42957
44152
|
".pdf": "application/pdf"
|
|
42958
44153
|
};
|
|
42959
44154
|
function getMime(filePath) {
|
|
42960
|
-
return MIME_MAP2[
|
|
44155
|
+
return MIME_MAP2[path16.extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
42961
44156
|
}
|
|
42962
44157
|
function sendPreviewAssetResponse(sessionManager, token, requestedPath, res) {
|
|
42963
44158
|
const session = sessionManager.get(token);
|
|
@@ -42975,13 +44170,13 @@ function sendPreviewAssetResponse(sessionManager, token, requestedPath, res) {
|
|
|
42975
44170
|
res.end("Invalid path");
|
|
42976
44171
|
return;
|
|
42977
44172
|
}
|
|
42978
|
-
if (!
|
|
44173
|
+
if (!fs15.existsSync(resolved) || !fs15.statSync(resolved).isFile()) {
|
|
42979
44174
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
42980
44175
|
res.end("File not found");
|
|
42981
44176
|
return;
|
|
42982
44177
|
}
|
|
42983
44178
|
const mime = getMime(resolved);
|
|
42984
|
-
const content =
|
|
44179
|
+
const content = fs15.readFileSync(resolved);
|
|
42985
44180
|
res.writeHead(200, {
|
|
42986
44181
|
"Content-Type": mime,
|
|
42987
44182
|
"Content-Length": content.length,
|
|
@@ -43254,13 +44449,13 @@ function getLocalTaskOutputDownload(taskEngine, taskId, filePath) {
|
|
|
43254
44449
|
const rootPath = getTaskOutputRoot(taskEngine, taskId);
|
|
43255
44450
|
try {
|
|
43256
44451
|
const absolutePath = resolveOutputPath(rootPath, filePath);
|
|
43257
|
-
if (!
|
|
44452
|
+
if (!fs16.existsSync(absolutePath) || !fs16.statSync(absolutePath).isFile()) {
|
|
43258
44453
|
throw new MeshyError("TASK_NOT_FOUND", `File not found: ${filePath}`, 404);
|
|
43259
44454
|
}
|
|
43260
44455
|
const { mimeType } = classifyFile(absolutePath);
|
|
43261
|
-
const fileName =
|
|
44456
|
+
const fileName = path17.basename(absolutePath).replace(/"/g, "");
|
|
43262
44457
|
return {
|
|
43263
|
-
content:
|
|
44458
|
+
content: fs16.readFileSync(absolutePath),
|
|
43264
44459
|
headers: {
|
|
43265
44460
|
"Content-Type": mimeType,
|
|
43266
44461
|
"Content-Disposition": `inline; filename="${fileName}"`,
|
|
@@ -45805,8 +47000,8 @@ function isAllowedSharePath(pathname) {
|
|
|
45805
47000
|
function resolveRuntimeBaseDir() {
|
|
45806
47001
|
const entryPath = process.argv[1];
|
|
45807
47002
|
if (typeof entryPath === "string" && entryPath.length > 0) {
|
|
45808
|
-
const resolved =
|
|
45809
|
-
return
|
|
47003
|
+
const resolved = fs17.realpathSync(path18.resolve(entryPath));
|
|
47004
|
+
return path18.dirname(resolved);
|
|
45810
47005
|
}
|
|
45811
47006
|
return process.cwd();
|
|
45812
47007
|
}
|
|
@@ -45814,18 +47009,18 @@ function resolveStaticDir(baseDir) {
|
|
|
45814
47009
|
const envStaticDir = process.env.MESHY_STATIC_DIR;
|
|
45815
47010
|
const candidateDirs = [
|
|
45816
47011
|
envStaticDir,
|
|
45817
|
-
|
|
45818
|
-
|
|
45819
|
-
|
|
45820
|
-
|
|
45821
|
-
|
|
45822
|
-
|
|
45823
|
-
|
|
45824
|
-
|
|
45825
|
-
|
|
47012
|
+
path18.resolve(baseDir, "dashboard"),
|
|
47013
|
+
path18.resolve(baseDir, "../dashboard"),
|
|
47014
|
+
path18.resolve(baseDir, "../../dashboard/dist"),
|
|
47015
|
+
path18.resolve(baseDir, "../../../packages/dashboard/dist"),
|
|
47016
|
+
path18.resolve(baseDir, "../public"),
|
|
47017
|
+
path18.resolve(baseDir, "../../packages/api/public"),
|
|
47018
|
+
path18.resolve(baseDir, "../../../packages/api/public"),
|
|
47019
|
+
path18.resolve(process.cwd(), "packages/dashboard/dist"),
|
|
47020
|
+
path18.resolve(process.cwd(), "packages/api/public")
|
|
45826
47021
|
].filter((value) => typeof value === "string" && value.length > 0);
|
|
45827
47022
|
for (const candidate of candidateDirs) {
|
|
45828
|
-
if (
|
|
47023
|
+
if (fs17.existsSync(candidate)) {
|
|
45829
47024
|
return candidate;
|
|
45830
47025
|
}
|
|
45831
47026
|
}
|
|
@@ -45919,8 +47114,8 @@ function createServer2(deps) {
|
|
|
45919
47114
|
app.use("/api/system", createSystemRoutes());
|
|
45920
47115
|
app.use("/api/events", createEventRoutes());
|
|
45921
47116
|
if (staticDir) {
|
|
45922
|
-
const indexPath =
|
|
45923
|
-
if (
|
|
47117
|
+
const indexPath = path18.join(staticDir, "index.html");
|
|
47118
|
+
if (fs17.existsSync(indexPath)) {
|
|
45924
47119
|
app.get("*", (req, res, next) => {
|
|
45925
47120
|
if (isApiRequest(req)) {
|
|
45926
47121
|
next();
|
|
@@ -45954,12 +47149,12 @@ function detectLocalIp() {
|
|
|
45954
47149
|
return "127.0.0.1";
|
|
45955
47150
|
}
|
|
45956
47151
|
function detectAvailablePort() {
|
|
45957
|
-
return new Promise((
|
|
47152
|
+
return new Promise((resolve14, reject) => {
|
|
45958
47153
|
const srv = (0, import_node_http2.createServer)();
|
|
45959
47154
|
srv.listen(0, () => {
|
|
45960
47155
|
const addr = srv.address();
|
|
45961
47156
|
const port = addr && typeof addr !== "string" ? addr.port : 0;
|
|
45962
|
-
srv.close((err) => err ? reject(err) :
|
|
47157
|
+
srv.close((err) => err ? reject(err) : resolve14(port));
|
|
45963
47158
|
});
|
|
45964
47159
|
srv.on("error", reject);
|
|
45965
47160
|
});
|
|
@@ -46041,7 +47236,7 @@ var DevTunnelTransport = class {
|
|
|
46041
47236
|
stdio: ["pipe", "pipe", "pipe"]
|
|
46042
47237
|
});
|
|
46043
47238
|
this.process = child;
|
|
46044
|
-
this.publicUrl = await new Promise((
|
|
47239
|
+
this.publicUrl = await new Promise((resolve14, reject) => {
|
|
46045
47240
|
const timeout = setTimeout(() => {
|
|
46046
47241
|
child.kill();
|
|
46047
47242
|
this.process = null;
|
|
@@ -46064,7 +47259,7 @@ var DevTunnelTransport = class {
|
|
|
46064
47259
|
clearTimeout(timeout);
|
|
46065
47260
|
child.stdout?.removeListener("data", onData);
|
|
46066
47261
|
child.stderr?.removeListener("data", onErrData);
|
|
46067
|
-
|
|
47262
|
+
resolve14(url.replace(/\/+$/, ""));
|
|
46068
47263
|
};
|
|
46069
47264
|
child.stdout?.on("data", onData);
|
|
46070
47265
|
child.stderr?.on("data", onErrData);
|
|
@@ -46096,14 +47291,14 @@ ${lines.join("")}`
|
|
|
46096
47291
|
this.publicUrl = null;
|
|
46097
47292
|
if (child.exitCode === null) {
|
|
46098
47293
|
child.kill("SIGTERM");
|
|
46099
|
-
await new Promise((
|
|
47294
|
+
await new Promise((resolve14) => {
|
|
46100
47295
|
const killTimer = setTimeout(() => {
|
|
46101
47296
|
child.kill("SIGKILL");
|
|
46102
|
-
|
|
47297
|
+
resolve14();
|
|
46103
47298
|
}, 5e3);
|
|
46104
47299
|
child.on("close", () => {
|
|
46105
47300
|
clearTimeout(killTimer);
|
|
46106
|
-
|
|
47301
|
+
resolve14();
|
|
46107
47302
|
});
|
|
46108
47303
|
});
|
|
46109
47304
|
}
|
|
@@ -46177,6 +47372,9 @@ ${lines.join("")}`
|
|
|
46177
47372
|
}
|
|
46178
47373
|
ensureTunnelPort(tunnelId, localPort) {
|
|
46179
47374
|
const ports = this.listTunnelPorts(tunnelId);
|
|
47375
|
+
for (const stalePort of ports.filter((p) => p !== localPort)) {
|
|
47376
|
+
(0, import_node_child_process9.execFileSync)("devtunnel", ["port", "delete", tunnelId, "-p", String(stalePort)], { stdio: "pipe" });
|
|
47377
|
+
}
|
|
46180
47378
|
if (ports.includes(localPort)) {
|
|
46181
47379
|
return;
|
|
46182
47380
|
}
|
|
@@ -46287,21 +47485,20 @@ function createTransport(config) {
|
|
|
46287
47485
|
}
|
|
46288
47486
|
|
|
46289
47487
|
// src/startup.ts
|
|
46290
|
-
var
|
|
46291
|
-
var
|
|
47488
|
+
var fs18 = __toESM(require("fs"), 1);
|
|
47489
|
+
var path19 = __toESM(require("path"), 1);
|
|
46292
47490
|
var readline = __toESM(require("readline/promises"), 1);
|
|
46293
47491
|
var import_node_child_process10 = require("child_process");
|
|
46294
47492
|
function getDefaultNodeName() {
|
|
46295
47493
|
return getDeviceNodeName();
|
|
46296
47494
|
}
|
|
46297
47495
|
var DEFAULT_NODE_NAME = getDefaultNodeName();
|
|
46298
|
-
var DEFAULT_NODE_PORT = 12345;
|
|
46299
47496
|
var SUPPORTED_TRANSPORTS = ["direct", "devtunnel", "tailscale"];
|
|
46300
47497
|
var STARTUP_REQUIREMENTS = ["az", "devtunnel", "claude", "codex"];
|
|
46301
47498
|
function createDefaultConfig(storagePath = resolveDefaultStoragePath(), nodeName = DEFAULT_NODE_NAME) {
|
|
46302
47499
|
return {
|
|
46303
|
-
node: { name: nodeName, port: DEFAULT_NODE_PORT },
|
|
46304
|
-
transport: { type: "
|
|
47500
|
+
node: { name: nodeName, port: DEFAULT_NODE_PORT, workDir: process.cwd() },
|
|
47501
|
+
transport: { type: "devtunnel" },
|
|
46305
47502
|
cluster: { seeds: [], heartbeatInterval: 3e3, electionTimeout: 36e3, apiKey: "" },
|
|
46306
47503
|
storage: { path: storagePath }
|
|
46307
47504
|
};
|
|
@@ -46352,19 +47549,19 @@ function createDefaultCommandRunner(platform2) {
|
|
|
46352
47549
|
};
|
|
46353
47550
|
}
|
|
46354
47551
|
function getNodeMetadataPath2(storagePath) {
|
|
46355
|
-
return
|
|
47552
|
+
return path19.join(storagePath, "metadata.json");
|
|
46356
47553
|
}
|
|
46357
47554
|
function readStartupMetadataFile(storagePath) {
|
|
46358
47555
|
try {
|
|
46359
|
-
const raw = JSON.parse(
|
|
47556
|
+
const raw = JSON.parse(fs18.readFileSync(getNodeMetadataPath2(storagePath), "utf-8"));
|
|
46360
47557
|
return typeof raw === "object" && raw !== null ? raw : {};
|
|
46361
47558
|
} catch {
|
|
46362
47559
|
return {};
|
|
46363
47560
|
}
|
|
46364
47561
|
}
|
|
46365
47562
|
function writeStartupMetadataFile(storagePath, metadata) {
|
|
46366
|
-
|
|
46367
|
-
|
|
47563
|
+
fs18.mkdirSync(storagePath, { recursive: true });
|
|
47564
|
+
fs18.writeFileSync(getNodeMetadataPath2(storagePath), JSON.stringify(metadata, null, 2) + "\n", "utf-8");
|
|
46368
47565
|
}
|
|
46369
47566
|
function formatLocalDate(now) {
|
|
46370
47567
|
const year = now.getFullYear();
|
|
@@ -46425,7 +47622,16 @@ function buildLoginCommand(requirement) {
|
|
|
46425
47622
|
}
|
|
46426
47623
|
function isAuthenticated(requirement, commandRunner) {
|
|
46427
47624
|
const command = requirement === "az" ? { command: "az", args: ["account", "show"] } : { command: "devtunnel", args: ["user", "show"] };
|
|
46428
|
-
|
|
47625
|
+
const result = commandRunner(command.command, command.args, false);
|
|
47626
|
+
if (!result.ok) {
|
|
47627
|
+
return false;
|
|
47628
|
+
}
|
|
47629
|
+
if (requirement === "devtunnel") {
|
|
47630
|
+
const output = `${result.stdout}
|
|
47631
|
+
${result.stderr}`.toLowerCase();
|
|
47632
|
+
return !output.includes("not logged in");
|
|
47633
|
+
}
|
|
47634
|
+
return true;
|
|
46429
47635
|
}
|
|
46430
47636
|
function isRequirementSatisfied(requirement, status) {
|
|
46431
47637
|
if (!status || status.installed !== true || status.status !== "ok") {
|
|
@@ -46436,6 +47642,12 @@ function isRequirementSatisfied(requirement, status) {
|
|
|
46436
47642
|
}
|
|
46437
47643
|
return true;
|
|
46438
47644
|
}
|
|
47645
|
+
function sleep(ms) {
|
|
47646
|
+
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
47647
|
+
}
|
|
47648
|
+
function areCachedAuthRequirementsCurrent(commandRunner) {
|
|
47649
|
+
return isAuthenticated("az", commandRunner) && isAuthenticated("devtunnel", commandRunner);
|
|
47650
|
+
}
|
|
46439
47651
|
function resolveStartupRequirementsMetadata(storagePath) {
|
|
46440
47652
|
const metadata = readStartupMetadataFile(storagePath).startupRequirements;
|
|
46441
47653
|
return metadata && typeof metadata === "object" ? metadata : {};
|
|
@@ -46447,10 +47659,11 @@ function shouldSkipStartupRequirementsCheck(storagePath, now = /* @__PURE__ */ n
|
|
|
46447
47659
|
}
|
|
46448
47660
|
return STARTUP_REQUIREMENTS.every((requirement) => isRequirementSatisfied(requirement, metadata.components?.[requirement]));
|
|
46449
47661
|
}
|
|
46450
|
-
async function ensureRequirementInstalled(requirement, platform2,
|
|
47662
|
+
async function ensureRequirementInstalled(requirement, platform2, getAsk, commandRunner, stdout, stderr, releasePrompt) {
|
|
46451
47663
|
if (isCommandAvailable(commandRunner, platform2, requirement)) {
|
|
46452
47664
|
return { installed: true, status: "ok" };
|
|
46453
47665
|
}
|
|
47666
|
+
const ask = getAsk();
|
|
46454
47667
|
if (!ask) {
|
|
46455
47668
|
writeLine(stderr, `Missing required component "${requirement}". Start in a TTY to install it automatically.`);
|
|
46456
47669
|
return { installed: false, status: "missing" };
|
|
@@ -46463,6 +47676,7 @@ async function ensureRequirementInstalled(requirement, platform2, ask, commandRu
|
|
|
46463
47676
|
if (!await confirm(ask, `Required component "${requirement}" is missing. Install it now?`)) {
|
|
46464
47677
|
return { installed: false, status: "missing" };
|
|
46465
47678
|
}
|
|
47679
|
+
await releasePrompt();
|
|
46466
47680
|
writeLine(stdout, `Installing ${requirement}...`);
|
|
46467
47681
|
const result = commandRunner(install.command, install.args, true);
|
|
46468
47682
|
if (!result.ok) {
|
|
@@ -46471,17 +47685,15 @@ async function ensureRequirementInstalled(requirement, platform2, ask, commandRu
|
|
|
46471
47685
|
}
|
|
46472
47686
|
return isCommandAvailable(commandRunner, platform2, requirement) ? { installed: true, status: "ok" } : { installed: false, status: "install-failed" };
|
|
46473
47687
|
}
|
|
46474
|
-
async function ensureRequirementAuthenticated(requirement,
|
|
47688
|
+
async function ensureRequirementAuthenticated(requirement, getAsk, commandRunner, stdout, stderr, releasePrompt, authPollIntervalMs, authPollTimeoutMs) {
|
|
46475
47689
|
if (isAuthenticated(requirement, commandRunner)) {
|
|
46476
47690
|
return { authenticated: true, status: "ok" };
|
|
46477
47691
|
}
|
|
46478
|
-
if (!
|
|
47692
|
+
if (!getAsk()) {
|
|
46479
47693
|
writeLine(stderr, `${requirement} is installed but not logged in. Start in a TTY to log in automatically.`);
|
|
46480
47694
|
return { authenticated: false, status: "not-authenticated" };
|
|
46481
47695
|
}
|
|
46482
|
-
|
|
46483
|
-
return { authenticated: false, status: "not-authenticated" };
|
|
46484
|
-
}
|
|
47696
|
+
await releasePrompt();
|
|
46485
47697
|
writeLine(stdout, `Opening ${requirement} login...`);
|
|
46486
47698
|
const login = buildLoginCommand(requirement);
|
|
46487
47699
|
const result = commandRunner(login.command, login.args, true);
|
|
@@ -46489,21 +47701,42 @@ async function ensureRequirementAuthenticated(requirement, ask, commandRunner, s
|
|
|
46489
47701
|
writeLine(stderr, `Failed to complete ${requirement} login.`);
|
|
46490
47702
|
return { authenticated: false, status: "login-failed" };
|
|
46491
47703
|
}
|
|
46492
|
-
|
|
47704
|
+
const deadline = Date.now() + authPollTimeoutMs;
|
|
47705
|
+
while (Date.now() <= deadline) {
|
|
47706
|
+
if (isAuthenticated(requirement, commandRunner)) {
|
|
47707
|
+
return { authenticated: true, status: "ok" };
|
|
47708
|
+
}
|
|
47709
|
+
await sleep(Math.max(0, authPollIntervalMs));
|
|
47710
|
+
}
|
|
47711
|
+
writeLine(stderr, `${requirement} login finished, but authentication was not available before timeout.`);
|
|
47712
|
+
return { authenticated: false, status: "login-failed" };
|
|
46493
47713
|
}
|
|
46494
47714
|
async function ensureStartupRequirements(storagePath, options = {}) {
|
|
46495
47715
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
46496
|
-
|
|
47716
|
+
const platform2 = options.platform ?? process.platform;
|
|
47717
|
+
const stdout = options.stdout ?? process.stdout;
|
|
47718
|
+
const stderr = options.stderr ?? process.stderr;
|
|
47719
|
+
const commandRunner = options.commandRunner ?? createDefaultCommandRunner(platform2);
|
|
47720
|
+
const authPollIntervalMs = options.authPollIntervalMs ?? 1e3;
|
|
47721
|
+
const authPollTimeoutMs = options.authPollTimeoutMs ?? 12e4;
|
|
47722
|
+
if (shouldSkipStartupRequirementsCheck(storagePath, now) && areCachedAuthRequirementsCurrent(commandRunner)) {
|
|
46497
47723
|
return {
|
|
46498
47724
|
skipped: true,
|
|
46499
47725
|
metadata: resolveStartupRequirementsMetadata(storagePath)
|
|
46500
47726
|
};
|
|
46501
47727
|
}
|
|
46502
|
-
const
|
|
46503
|
-
|
|
46504
|
-
const
|
|
46505
|
-
|
|
46506
|
-
|
|
47728
|
+
const promptSessionFactory = options.promptSessionFactory ?? createPromptSession;
|
|
47729
|
+
let promptSession;
|
|
47730
|
+
const getAsk = () => {
|
|
47731
|
+
promptSession ??= promptSessionFactory(options.prompt);
|
|
47732
|
+
return promptSession?.ask;
|
|
47733
|
+
};
|
|
47734
|
+
const releasePrompt = async () => {
|
|
47735
|
+
if (!promptSession) return;
|
|
47736
|
+
const current = promptSession;
|
|
47737
|
+
promptSession = void 0;
|
|
47738
|
+
await current.close();
|
|
47739
|
+
};
|
|
46507
47740
|
const checkedAt = now.toISOString();
|
|
46508
47741
|
const checkedOn = formatLocalDate(now);
|
|
46509
47742
|
const components = {};
|
|
@@ -46512,10 +47745,11 @@ async function ensureStartupRequirements(storagePath, options = {}) {
|
|
|
46512
47745
|
const installResult = await ensureRequirementInstalled(
|
|
46513
47746
|
requirement,
|
|
46514
47747
|
platform2,
|
|
46515
|
-
|
|
47748
|
+
getAsk,
|
|
46516
47749
|
commandRunner,
|
|
46517
47750
|
stdout,
|
|
46518
|
-
stderr
|
|
47751
|
+
stderr,
|
|
47752
|
+
releasePrompt
|
|
46519
47753
|
);
|
|
46520
47754
|
if (!installResult.installed) {
|
|
46521
47755
|
components[requirement] = {
|
|
@@ -46528,10 +47762,13 @@ async function ensureStartupRequirements(storagePath, options = {}) {
|
|
|
46528
47762
|
if (requirement === "az" || requirement === "devtunnel") {
|
|
46529
47763
|
const authResult = await ensureRequirementAuthenticated(
|
|
46530
47764
|
requirement,
|
|
46531
|
-
|
|
47765
|
+
getAsk,
|
|
46532
47766
|
commandRunner,
|
|
46533
47767
|
stdout,
|
|
46534
|
-
stderr
|
|
47768
|
+
stderr,
|
|
47769
|
+
releasePrompt,
|
|
47770
|
+
authPollIntervalMs,
|
|
47771
|
+
authPollTimeoutMs
|
|
46535
47772
|
);
|
|
46536
47773
|
components[requirement] = {
|
|
46537
47774
|
installed: true,
|
|
@@ -46548,7 +47785,7 @@ async function ensureStartupRequirements(storagePath, options = {}) {
|
|
|
46548
47785
|
};
|
|
46549
47786
|
}
|
|
46550
47787
|
} finally {
|
|
46551
|
-
await
|
|
47788
|
+
await releasePrompt();
|
|
46552
47789
|
}
|
|
46553
47790
|
const metadataFile = readStartupMetadataFile(storagePath);
|
|
46554
47791
|
const metadata = {
|
|
@@ -46563,55 +47800,9 @@ async function ensureStartupRequirements(storagePath, options = {}) {
|
|
|
46563
47800
|
metadata
|
|
46564
47801
|
};
|
|
46565
47802
|
}
|
|
46566
|
-
function
|
|
46567
|
-
const result = {};
|
|
46568
|
-
for (let i = 0; i < argv.length; i++) {
|
|
46569
|
-
const arg = argv[i];
|
|
46570
|
-
switch (arg) {
|
|
46571
|
-
case "--port":
|
|
46572
|
-
if (i + 1 < argv.length) {
|
|
46573
|
-
const port = Number(argv[++i]);
|
|
46574
|
-
if (!Number.isNaN(port) && port > 0) {
|
|
46575
|
-
result.port = port;
|
|
46576
|
-
}
|
|
46577
|
-
}
|
|
46578
|
-
break;
|
|
46579
|
-
case "--name":
|
|
46580
|
-
if (i + 1 < argv.length) {
|
|
46581
|
-
result.name = argv[++i];
|
|
46582
|
-
}
|
|
46583
|
-
break;
|
|
46584
|
-
case "--join":
|
|
46585
|
-
if (i + 1 < argv.length) {
|
|
46586
|
-
result.join = argv[++i];
|
|
46587
|
-
}
|
|
46588
|
-
break;
|
|
46589
|
-
case "--transport":
|
|
46590
|
-
if (i + 1 < argv.length) {
|
|
46591
|
-
const t = argv[++i];
|
|
46592
|
-
if (t === "direct" || t === "devtunnel" || t === "tailscale") {
|
|
46593
|
-
result.transport = t;
|
|
46594
|
-
}
|
|
46595
|
-
}
|
|
46596
|
-
break;
|
|
46597
|
-
case "--config":
|
|
46598
|
-
if (i + 1 < argv.length) {
|
|
46599
|
-
result.config = argv[++i];
|
|
46600
|
-
}
|
|
46601
|
-
break;
|
|
46602
|
-
case "--reset":
|
|
46603
|
-
result.reset = true;
|
|
46604
|
-
break;
|
|
46605
|
-
case "--disable-auth":
|
|
46606
|
-
result.disableAuth = true;
|
|
46607
|
-
break;
|
|
46608
|
-
}
|
|
46609
|
-
}
|
|
46610
|
-
return result;
|
|
46611
|
-
}
|
|
46612
|
-
function loadConfigFile(path20) {
|
|
47803
|
+
function loadConfigFile(path21) {
|
|
46613
47804
|
try {
|
|
46614
|
-
const raw =
|
|
47805
|
+
const raw = fs18.readFileSync(path21, "utf-8");
|
|
46615
47806
|
return JSON.parse(raw);
|
|
46616
47807
|
} catch {
|
|
46617
47808
|
return {};
|
|
@@ -46621,7 +47812,8 @@ function mergeConfig(defaults, fileConfig, args) {
|
|
|
46621
47812
|
const config = {
|
|
46622
47813
|
node: {
|
|
46623
47814
|
name: args.name ?? fileConfig.node?.name ?? defaults.node.name,
|
|
46624
|
-
port: args.port ?? fileConfig.node?.port ?? defaults.node.port
|
|
47815
|
+
port: args.port ?? fileConfig.node?.port ?? defaults.node.port,
|
|
47816
|
+
workDir: args.workDir ?? fileConfig.node?.workDir ?? defaults.node.workDir
|
|
46625
47817
|
},
|
|
46626
47818
|
transport: {
|
|
46627
47819
|
type: args.transport ?? fileConfig.transport?.type ?? defaults.transport.type,
|
|
@@ -46710,6 +47902,11 @@ async function promptStartOptions(args, fileConfig, defaults, prompt) {
|
|
|
46710
47902
|
const input = normalizePromptValue(await ask(formatPrompt("Join URL (optional)", defaultJoin)));
|
|
46711
47903
|
result.join = input ?? defaultJoin;
|
|
46712
47904
|
}
|
|
47905
|
+
if (result.workDir === void 0) {
|
|
47906
|
+
const defaultWorkDir = merged.node.workDir ?? process.cwd();
|
|
47907
|
+
const input = normalizePromptValue(await ask(formatPrompt("Work directory", defaultWorkDir)));
|
|
47908
|
+
result.workDir = input ?? defaultWorkDir;
|
|
47909
|
+
}
|
|
46713
47910
|
return result;
|
|
46714
47911
|
} finally {
|
|
46715
47912
|
await closePrompt?.();
|
|
@@ -46735,6 +47932,10 @@ function applyStartMetadata(storagePath, args) {
|
|
|
46735
47932
|
result.join = startup.join;
|
|
46736
47933
|
loaded.join = startup.join;
|
|
46737
47934
|
}
|
|
47935
|
+
if (startup.workDir && result.workDir === void 0) {
|
|
47936
|
+
result.workDir = startup.workDir;
|
|
47937
|
+
loaded.workDir = startup.workDir;
|
|
47938
|
+
}
|
|
46738
47939
|
return {
|
|
46739
47940
|
args: result,
|
|
46740
47941
|
loaded: Object.keys(loaded).length > 0 ? loaded : void 0
|
|
@@ -46771,31 +47972,34 @@ function formatLoadedStartMetadata(info, authEnabled) {
|
|
|
46771
47972
|
if (info.join) {
|
|
46772
47973
|
lines.push(` Join: ${info.join}`);
|
|
46773
47974
|
}
|
|
47975
|
+
if (info.workDir) {
|
|
47976
|
+
lines.push(` Work directory: ${info.workDir}`);
|
|
47977
|
+
}
|
|
46774
47978
|
lines.push(` Auth: ${authEnabled ? "enabled" : "disabled"}`);
|
|
46775
47979
|
return lines.join("\n");
|
|
46776
47980
|
}
|
|
46777
47981
|
|
|
46778
47982
|
// src/runtime-metadata.ts
|
|
46779
|
-
var
|
|
46780
|
-
var
|
|
47983
|
+
var fs19 = __toESM(require("fs"), 1);
|
|
47984
|
+
var path20 = __toESM(require("path"), 1);
|
|
46781
47985
|
var import_node_child_process11 = require("child_process");
|
|
46782
47986
|
var runtimeDir = resolveRuntimeDir();
|
|
46783
47987
|
var appRoot = resolveAppRoot(runtimeDir);
|
|
46784
|
-
var repoRoot =
|
|
47988
|
+
var repoRoot = path20.resolve(appRoot, "../..");
|
|
46785
47989
|
function resolveRuntimeDir() {
|
|
46786
47990
|
const entryPath = process.argv[1];
|
|
46787
47991
|
if (typeof entryPath === "string" && entryPath.length > 0) {
|
|
46788
47992
|
try {
|
|
46789
|
-
return
|
|
47993
|
+
return path20.dirname(fs19.realpathSync(path20.resolve(entryPath)));
|
|
46790
47994
|
} catch {
|
|
46791
|
-
return
|
|
47995
|
+
return path20.dirname(path20.resolve(entryPath));
|
|
46792
47996
|
}
|
|
46793
47997
|
}
|
|
46794
47998
|
return process.cwd();
|
|
46795
47999
|
}
|
|
46796
48000
|
function readJsonFile(filePath) {
|
|
46797
48001
|
try {
|
|
46798
|
-
return JSON.parse(
|
|
48002
|
+
return JSON.parse(fs19.readFileSync(filePath, "utf-8"));
|
|
46799
48003
|
} catch {
|
|
46800
48004
|
return null;
|
|
46801
48005
|
}
|
|
@@ -46805,9 +48009,9 @@ function readPackageManifest(filePath) {
|
|
|
46805
48009
|
}
|
|
46806
48010
|
function readEmbeddedRuntimeMetadata() {
|
|
46807
48011
|
const candidates = [
|
|
46808
|
-
|
|
46809
|
-
|
|
46810
|
-
|
|
48012
|
+
path20.join(appRoot, "runtime-metadata.json"),
|
|
48013
|
+
path20.join(runtimeDir, "runtime-metadata.json"),
|
|
48014
|
+
path20.resolve(process.cwd(), "apps/node/dist/runtime-metadata.json")
|
|
46811
48015
|
];
|
|
46812
48016
|
for (const candidate of candidates) {
|
|
46813
48017
|
const metadata = readJsonFile(candidate);
|
|
@@ -46820,23 +48024,23 @@ function readEmbeddedRuntimeMetadata() {
|
|
|
46820
48024
|
function resolveAppRoot(baseDir) {
|
|
46821
48025
|
const candidates = [
|
|
46822
48026
|
baseDir,
|
|
46823
|
-
|
|
46824
|
-
|
|
46825
|
-
|
|
48027
|
+
path20.resolve(baseDir, ".."),
|
|
48028
|
+
path20.resolve(process.cwd(), "apps/node/dist"),
|
|
48029
|
+
path20.resolve(process.cwd(), "apps/node"),
|
|
46826
48030
|
process.cwd()
|
|
46827
48031
|
];
|
|
46828
48032
|
for (const candidate of candidates) {
|
|
46829
|
-
const manifest = readPackageManifest(
|
|
48033
|
+
const manifest = readPackageManifest(path20.join(candidate, "package.json"));
|
|
46830
48034
|
if (manifest?.name === "@meshy/node" || manifest?.name === "meshy-node") {
|
|
46831
48035
|
return candidate;
|
|
46832
48036
|
}
|
|
46833
48037
|
}
|
|
46834
48038
|
for (const candidate of candidates) {
|
|
46835
|
-
if (
|
|
48039
|
+
if (fs19.existsSync(path20.join(candidate, "package.json"))) {
|
|
46836
48040
|
return candidate;
|
|
46837
48041
|
}
|
|
46838
48042
|
}
|
|
46839
|
-
return
|
|
48043
|
+
return path20.resolve(baseDir, "..");
|
|
46840
48044
|
}
|
|
46841
48045
|
function toPackageInfo(filePath) {
|
|
46842
48046
|
const manifest = readPackageManifest(filePath);
|
|
@@ -46896,8 +48100,8 @@ function buildRuntimeMetadata(storagePath) {
|
|
|
46896
48100
|
components: startupRequirements.components
|
|
46897
48101
|
};
|
|
46898
48102
|
}
|
|
46899
|
-
const appPackage = toPackageInfo(
|
|
46900
|
-
const workspaceManifest = readPackageManifest(
|
|
48103
|
+
const appPackage = toPackageInfo(path20.join(appRoot, "package.json"));
|
|
48104
|
+
const workspaceManifest = readPackageManifest(path20.join(repoRoot, "package.json"));
|
|
46901
48105
|
return {
|
|
46902
48106
|
packageName: appPackage?.name ?? "meshy",
|
|
46903
48107
|
packageVersion: appPackage?.version ?? "0.1.0",
|
|
@@ -46905,11 +48109,11 @@ function buildRuntimeMetadata(storagePath) {
|
|
|
46905
48109
|
startupRequirementsLastCheckedOn: startupRequirements.lastCheckedOn,
|
|
46906
48110
|
components: startupRequirements.components,
|
|
46907
48111
|
packages: {
|
|
46908
|
-
workspace: toPackageInfo(
|
|
48112
|
+
workspace: toPackageInfo(path20.join(repoRoot, "package.json")),
|
|
46909
48113
|
node: appPackage,
|
|
46910
|
-
core: toPackageInfo(
|
|
46911
|
-
dashboard: toPackageInfo(
|
|
46912
|
-
api: toPackageInfo(
|
|
48114
|
+
core: toPackageInfo(path20.join(repoRoot, "packages/core/package.json")),
|
|
48115
|
+
dashboard: toPackageInfo(path20.join(repoRoot, "packages/dashboard/package.json")),
|
|
48116
|
+
api: toPackageInfo(path20.join(repoRoot, "packages/api/package.json"))
|
|
46913
48117
|
},
|
|
46914
48118
|
repository: {
|
|
46915
48119
|
url: normalizeRepositoryUrl(readGitValue(["config", "--get", "remote.origin.url"])) ?? readRepositoryUrlFromManifest(workspaceManifest),
|
|
@@ -46919,132 +48123,84 @@ function buildRuntimeMetadata(storagePath) {
|
|
|
46919
48123
|
};
|
|
46920
48124
|
}
|
|
46921
48125
|
|
|
46922
|
-
// src/
|
|
46923
|
-
function
|
|
46924
|
-
|
|
46925
|
-
|
|
46926
|
-
|
|
46927
|
-
|
|
46928
|
-
|
|
46929
|
-
|
|
46930
|
-
|
|
46931
|
-
|
|
46932
|
-
|
|
46933
|
-
|
|
46934
|
-
|
|
46935
|
-
|
|
46936
|
-
|
|
46937
|
-
|
|
46938
|
-
|
|
46939
|
-
|
|
46940
|
-
|
|
46941
|
-
if (!entryPath) {
|
|
46942
|
-
return false;
|
|
46943
|
-
}
|
|
46944
|
-
const entryName = entryPath.split(/[/\\]/).pop()?.toLowerCase();
|
|
46945
|
-
if (!entryName) {
|
|
46946
|
-
return false;
|
|
46947
|
-
}
|
|
46948
|
-
return entryName === "meshy" || entryName === "meshy.cmd" || entryName === "main.js" || entryName === "main.cjs" || entryName === "main.ts";
|
|
48126
|
+
// src/bootstrap/start-node.ts
|
|
48127
|
+
function createSettingsSnapshotProvider(options) {
|
|
48128
|
+
let cachedSnapshot = null;
|
|
48129
|
+
let cachedSnapshotAt = 0;
|
|
48130
|
+
return function getSettingsSnapshot() {
|
|
48131
|
+
const now = Date.now();
|
|
48132
|
+
if (cachedSnapshot && now - cachedSnapshotAt < 3e4) {
|
|
48133
|
+
return structuredClone(cachedSnapshot);
|
|
48134
|
+
}
|
|
48135
|
+
cachedSnapshot = buildNodeSettingsSnapshot({
|
|
48136
|
+
auth: options.authMetadata,
|
|
48137
|
+
localDashboardOrigin: options.localDashboardOrigin,
|
|
48138
|
+
runtimeMetadata: options.runtimeMetadata,
|
|
48139
|
+
storagePath: options.storagePath,
|
|
48140
|
+
workDir: options.workDir
|
|
48141
|
+
});
|
|
48142
|
+
cachedSnapshotAt = now;
|
|
48143
|
+
return structuredClone(cachedSnapshot);
|
|
48144
|
+
};
|
|
46949
48145
|
}
|
|
46950
|
-
async function
|
|
46951
|
-
const args = parseArgs(process.argv.slice(2));
|
|
48146
|
+
async function resolveStartConfig(args) {
|
|
46952
48147
|
const configPath = args.config ?? "./config.json";
|
|
46953
48148
|
const fileConfig = loadConfigFile(configPath);
|
|
46954
|
-
const
|
|
46955
|
-
const
|
|
46956
|
-
const
|
|
48149
|
+
const storageRoot = fileConfig.storage?.path ?? resolveDefaultStoragePath();
|
|
48150
|
+
const initialNodeName = args.name ?? fileConfig.node?.name ?? resolveDefaultNodeName(storageRoot);
|
|
48151
|
+
const initialStoragePath = resolveNodeScopedStoragePath(storageRoot, initialNodeName);
|
|
48152
|
+
const hydratedArgs = args.reset ? { args: { ...args }, loaded: void 0 } : applyStartMetadata(initialStoragePath, args);
|
|
48153
|
+
const initialFileConfig = {
|
|
48154
|
+
...fileConfig,
|
|
48155
|
+
storage: { path: initialStoragePath }
|
|
48156
|
+
};
|
|
48157
|
+
const initialDefaults = createRuntimeDefaultConfig(initialFileConfig, {
|
|
46957
48158
|
ignorePersistedName: args.reset === true
|
|
46958
48159
|
});
|
|
46959
|
-
const resolvedArgs = shouldCollectStartOptions(args,
|
|
48160
|
+
const resolvedArgs = shouldCollectStartOptions(args, initialStoragePath) ? await promptStartOptions(
|
|
46960
48161
|
args.reset ? args : hydratedArgs.args,
|
|
46961
|
-
|
|
46962
|
-
|
|
48162
|
+
initialFileConfig,
|
|
48163
|
+
initialDefaults
|
|
46963
48164
|
) : hydratedArgs.args;
|
|
46964
|
-
const
|
|
48165
|
+
const nodeName = resolvedArgs.name ?? fileConfig.node?.name ?? initialDefaults.node.name;
|
|
48166
|
+
const storagePath = resolveNodeScopedStoragePath(storageRoot, nodeName);
|
|
48167
|
+
const scopedFileConfig = {
|
|
48168
|
+
...fileConfig,
|
|
48169
|
+
storage: { path: storagePath }
|
|
48170
|
+
};
|
|
48171
|
+
const defaults = createRuntimeDefaultConfig(scopedFileConfig, {
|
|
48172
|
+
ignorePersistedName: args.reset === true
|
|
48173
|
+
});
|
|
48174
|
+
const config = mergeConfig(defaults, scopedFileConfig, resolvedArgs);
|
|
48175
|
+
setStartupFatalLogPath(nodePath2.join(config.storage.path, "logs", "startup-fatal.log"));
|
|
48176
|
+
persistDefaultNodeName(storageRoot, config.node.name);
|
|
46965
48177
|
persistDefaultNodeName(config.storage.path, config.node.name);
|
|
46966
48178
|
persistNodeStartupMetadata(config.storage.path, {
|
|
46967
48179
|
port: config.node.port,
|
|
46968
48180
|
transport: config.transport.type,
|
|
46969
|
-
join: resolvedArgs.join
|
|
48181
|
+
join: resolvedArgs.join,
|
|
48182
|
+
workDir: config.node.workDir
|
|
46970
48183
|
});
|
|
46971
48184
|
const authMetadata = resolveRuntimeAuthMetadata(config.storage.path, resolvedArgs.disableAuth === true);
|
|
46972
48185
|
if (!resolvedArgs.disableAuth) {
|
|
46973
48186
|
persistNodeAuthMetadata(config.storage.path, authMetadata);
|
|
46974
48187
|
}
|
|
46975
|
-
|
|
46976
|
-
|
|
46977
|
-
|
|
46978
|
-
|
|
46979
|
-
|
|
46980
|
-
|
|
46981
|
-
const localDashboardOrigin = `http://localhost:${config.node.port}`;
|
|
46982
|
-
const logDir = nodePath.join(config.storage.path, "logs");
|
|
46983
|
-
const logger27 = createLogger({
|
|
46984
|
-
component: "node",
|
|
46985
|
-
logDir,
|
|
46986
|
-
console: true
|
|
46987
|
-
});
|
|
46988
|
-
const nodeAuth = new AzureCliNodeAuth(config.storage.path, {
|
|
46989
|
-
logger: logger27.child("azure-auth"),
|
|
46990
|
-
settingsProvider: () => authMetadata
|
|
46991
|
-
});
|
|
46992
|
-
if (hydratedArgs.loaded) {
|
|
46993
|
-
console.log("");
|
|
46994
|
-
console.log(formatLoadedStartMetadata(hydratedArgs.loaded, authMetadata.enabled));
|
|
46995
|
-
console.log("");
|
|
46996
|
-
}
|
|
46997
|
-
if (authMetadata.enabled) {
|
|
46998
|
-
await nodeAuth.warmup();
|
|
46999
|
-
setRequestAuthHeadersProvider(() => nodeAuth.getAuthorizationHeaders());
|
|
47000
|
-
} else {
|
|
47001
|
-
setRequestAuthHeadersProvider(null);
|
|
47002
|
-
}
|
|
47003
|
-
let cachedSettingsSnapshot = null;
|
|
47004
|
-
let cachedSettingsSnapshotAt = 0;
|
|
47005
|
-
const getSettingsSnapshot = () => {
|
|
47006
|
-
const now = Date.now();
|
|
47007
|
-
if (cachedSettingsSnapshot && now - cachedSettingsSnapshotAt < 3e4) {
|
|
47008
|
-
return structuredClone(cachedSettingsSnapshot);
|
|
47009
|
-
}
|
|
47010
|
-
cachedSettingsSnapshot = buildNodeSettingsSnapshot({
|
|
47011
|
-
auth: authMetadata,
|
|
47012
|
-
localDashboardOrigin,
|
|
47013
|
-
runtimeMetadata,
|
|
47014
|
-
storagePath: config.storage.path,
|
|
47015
|
-
workDir: nodePath.resolve(config.node.workDir ?? process.cwd())
|
|
47016
|
-
});
|
|
47017
|
-
cachedSettingsSnapshotAt = now;
|
|
47018
|
-
return structuredClone(cachedSettingsSnapshot);
|
|
48188
|
+
return {
|
|
48189
|
+
authMetadata,
|
|
48190
|
+
config,
|
|
48191
|
+
hydratedArgs,
|
|
48192
|
+
runtimeMetadata: buildRuntimeMetadata(config.storage.path),
|
|
48193
|
+
storageRoot
|
|
47019
48194
|
};
|
|
47020
|
-
|
|
47021
|
-
|
|
47022
|
-
|
|
47023
|
-
getSettingsSnapshot
|
|
47024
|
-
});
|
|
47025
|
-
await meshyNode.start();
|
|
47026
|
-
meshyNode.getNodeRegistry().updateSettingsSnapshot(meshyNode.getNodeRegistry().getSelf().id, getSettingsSnapshot());
|
|
47027
|
-
const previewSessionManager = new PreviewSessionManager();
|
|
47028
|
-
const previewProxyManager = new PreviewProxyManager();
|
|
47029
|
-
let dashboardTransport = null;
|
|
47030
|
-
let shareTransport = null;
|
|
48195
|
+
}
|
|
48196
|
+
function createTunnelManager(options) {
|
|
48197
|
+
const { authMetadata, config, meshyNode } = options;
|
|
47031
48198
|
let dashboardOrigin;
|
|
47032
48199
|
let shareOrigin;
|
|
47033
|
-
let
|
|
47034
|
-
|
|
47035
|
-
|
|
47036
|
-
|
|
47037
|
-
}
|
|
47038
|
-
await new Promise((resolve13, reject) => {
|
|
47039
|
-
server2.close((err) => {
|
|
47040
|
-
if (err) {
|
|
47041
|
-
reject(err);
|
|
47042
|
-
return;
|
|
47043
|
-
}
|
|
47044
|
-
resolve13();
|
|
47045
|
-
});
|
|
47046
|
-
});
|
|
47047
|
-
}
|
|
48200
|
+
let dashboardTransport = null;
|
|
48201
|
+
let shareTransport = null;
|
|
48202
|
+
let dashboardHealthTimer = null;
|
|
48203
|
+
let nodeTunnelHealthTimer = null;
|
|
47048
48204
|
function createDashboardTransportConfig() {
|
|
47049
48205
|
return {
|
|
47050
48206
|
type: "devtunnel",
|
|
@@ -47072,14 +48228,14 @@ async function main() {
|
|
|
47072
48228
|
}
|
|
47073
48229
|
};
|
|
47074
48230
|
}
|
|
47075
|
-
function
|
|
48231
|
+
function setDashboardOrigin(origin) {
|
|
47076
48232
|
dashboardOrigin = origin;
|
|
47077
|
-
|
|
48233
|
+
options.onDashboardOriginChange(origin);
|
|
47078
48234
|
meshyNode.getNodeRegistry().updateDashboardOrigin(meshyNode.getNodeRegistry().getSelf().id, origin);
|
|
47079
48235
|
}
|
|
47080
48236
|
function setShareOrigin(origin) {
|
|
47081
48237
|
shareOrigin = origin;
|
|
47082
|
-
|
|
48238
|
+
options.onShareOriginChange(origin);
|
|
47083
48239
|
}
|
|
47084
48240
|
function shouldPublishDashboardTunnel() {
|
|
47085
48241
|
return authMetadata.enabled && (meshyNode.getTransportType() === "devtunnel" || meshyNode.isDevTunnelEnabled());
|
|
@@ -47087,13 +48243,13 @@ async function main() {
|
|
|
47087
48243
|
async function stopDashboardTransport(reason) {
|
|
47088
48244
|
if (!dashboardTransport) {
|
|
47089
48245
|
if (dashboardOrigin) {
|
|
47090
|
-
|
|
48246
|
+
setDashboardOrigin(void 0);
|
|
47091
48247
|
}
|
|
47092
48248
|
return;
|
|
47093
48249
|
}
|
|
47094
48250
|
await dashboardTransport.stop().catch(() => void 0);
|
|
47095
48251
|
dashboardTransport = null;
|
|
47096
|
-
|
|
48252
|
+
setDashboardOrigin(void 0);
|
|
47097
48253
|
meshyNode.getLogger().info("stopped dashboard tunnel", {
|
|
47098
48254
|
reason,
|
|
47099
48255
|
mainTransportType: meshyNode.getTransportType(),
|
|
@@ -47107,14 +48263,14 @@ async function main() {
|
|
|
47107
48263
|
if (previousTransport) {
|
|
47108
48264
|
await previousTransport.stop().catch(() => void 0);
|
|
47109
48265
|
dashboardTransport = null;
|
|
47110
|
-
|
|
48266
|
+
setDashboardOrigin(void 0);
|
|
47111
48267
|
}
|
|
47112
48268
|
try {
|
|
47113
48269
|
nextTransport = createTransport(transportConfig);
|
|
47114
48270
|
await nextTransport.start(config.node.port);
|
|
47115
48271
|
const nextOrigin = await nextTransport.getEndpoint();
|
|
47116
48272
|
dashboardTransport = nextTransport;
|
|
47117
|
-
|
|
48273
|
+
setDashboardOrigin(nextOrigin);
|
|
47118
48274
|
meshyNode.getLogger().info("started dashboard tunnel", {
|
|
47119
48275
|
reason,
|
|
47120
48276
|
dashboardOrigin: nextOrigin,
|
|
@@ -47127,7 +48283,7 @@ async function main() {
|
|
|
47127
48283
|
await nextTransport.stop().catch(() => void 0);
|
|
47128
48284
|
}
|
|
47129
48285
|
dashboardTransport = null;
|
|
47130
|
-
|
|
48286
|
+
setDashboardOrigin(void 0);
|
|
47131
48287
|
meshyNode.getLogger().warn("failed to start dashboard transport", {
|
|
47132
48288
|
reason,
|
|
47133
48289
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -47183,6 +48339,183 @@ async function main() {
|
|
|
47183
48339
|
});
|
|
47184
48340
|
return nextOrigin;
|
|
47185
48341
|
}
|
|
48342
|
+
function startHealthChecks() {
|
|
48343
|
+
if (!nodeTunnelHealthTimer) {
|
|
48344
|
+
nodeTunnelHealthTimer = setInterval(() => {
|
|
48345
|
+
void (async () => {
|
|
48346
|
+
if (!meshyNode.hasPublishedNodeTunnel()) {
|
|
48347
|
+
return;
|
|
48348
|
+
}
|
|
48349
|
+
const healthy = await meshyNode.isPublishedNodeTunnelHealthy().catch(() => false);
|
|
48350
|
+
if (healthy) {
|
|
48351
|
+
return;
|
|
48352
|
+
}
|
|
48353
|
+
meshyNode.getLogger().warn("published node tunnel became unhealthy; restarting with stable id", {
|
|
48354
|
+
mainTransportType: meshyNode.getTransportType(),
|
|
48355
|
+
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
48356
|
+
});
|
|
48357
|
+
try {
|
|
48358
|
+
const endpoint = await meshyNode.restartPublishedNodeTunnel();
|
|
48359
|
+
meshyNode.getLogger().info("restarted published node tunnel", {
|
|
48360
|
+
endpoint,
|
|
48361
|
+
stableUrl: true,
|
|
48362
|
+
mainTransportType: meshyNode.getTransportType(),
|
|
48363
|
+
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
48364
|
+
});
|
|
48365
|
+
} catch (err) {
|
|
48366
|
+
meshyNode.getLogger().warn("failed to restart published node tunnel", {
|
|
48367
|
+
error: err instanceof Error ? err.message : String(err),
|
|
48368
|
+
mainTransportType: meshyNode.getTransportType(),
|
|
48369
|
+
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
48370
|
+
});
|
|
48371
|
+
}
|
|
48372
|
+
})();
|
|
48373
|
+
}, config.cluster.heartbeatInterval);
|
|
48374
|
+
}
|
|
48375
|
+
if (!dashboardHealthTimer) {
|
|
48376
|
+
dashboardHealthTimer = setInterval(() => {
|
|
48377
|
+
void (async () => {
|
|
48378
|
+
if (!dashboardTransport) {
|
|
48379
|
+
return;
|
|
48380
|
+
}
|
|
48381
|
+
const healthy = await dashboardTransport.isHealthy().catch(() => false);
|
|
48382
|
+
if (healthy) {
|
|
48383
|
+
return;
|
|
48384
|
+
}
|
|
48385
|
+
meshyNode.getLogger().warn("dashboard tunnel became unhealthy; restarting with stable id", {
|
|
48386
|
+
port: config.node.port
|
|
48387
|
+
});
|
|
48388
|
+
await restartDashboardTransport("healthcheck");
|
|
48389
|
+
})();
|
|
48390
|
+
}, config.cluster.heartbeatInterval);
|
|
48391
|
+
}
|
|
48392
|
+
}
|
|
48393
|
+
function stopHealthChecks() {
|
|
48394
|
+
if (dashboardHealthTimer) {
|
|
48395
|
+
clearInterval(dashboardHealthTimer);
|
|
48396
|
+
dashboardHealthTimer = null;
|
|
48397
|
+
}
|
|
48398
|
+
if (nodeTunnelHealthTimer) {
|
|
48399
|
+
clearInterval(nodeTunnelHealthTimer);
|
|
48400
|
+
nodeTunnelHealthTimer = null;
|
|
48401
|
+
}
|
|
48402
|
+
}
|
|
48403
|
+
async function stop() {
|
|
48404
|
+
stopHealthChecks();
|
|
48405
|
+
if (dashboardTransport) {
|
|
48406
|
+
await dashboardTransport.stop();
|
|
48407
|
+
dashboardTransport = null;
|
|
48408
|
+
setDashboardOrigin(void 0);
|
|
48409
|
+
}
|
|
48410
|
+
if (shareTransport) {
|
|
48411
|
+
await shareTransport.stop();
|
|
48412
|
+
shareTransport = null;
|
|
48413
|
+
setShareOrigin(void 0);
|
|
48414
|
+
}
|
|
48415
|
+
}
|
|
48416
|
+
return {
|
|
48417
|
+
ensureShareTunnel,
|
|
48418
|
+
getDashboardOrigin: () => dashboardOrigin,
|
|
48419
|
+
getShareOrigin: () => shareOrigin,
|
|
48420
|
+
startHealthChecks,
|
|
48421
|
+
stop,
|
|
48422
|
+
stopHealthChecks,
|
|
48423
|
+
syncDashboardTransport
|
|
48424
|
+
};
|
|
48425
|
+
}
|
|
48426
|
+
function registerShutdownHandlers(options) {
|
|
48427
|
+
let shuttingDown = false;
|
|
48428
|
+
async function shutdown() {
|
|
48429
|
+
if (shuttingDown) {
|
|
48430
|
+
console.log("Force exit.");
|
|
48431
|
+
process.exit(130);
|
|
48432
|
+
}
|
|
48433
|
+
shuttingDown = true;
|
|
48434
|
+
console.log("\nShutting down...");
|
|
48435
|
+
const forceExitTimer = setTimeout(() => {
|
|
48436
|
+
console.log("Force exit.");
|
|
48437
|
+
process.exit(0);
|
|
48438
|
+
}, 1e4);
|
|
48439
|
+
forceExitTimer.unref?.();
|
|
48440
|
+
try {
|
|
48441
|
+
options.tunnelManager.stopHealthChecks();
|
|
48442
|
+
await closeHttpServer(options.server);
|
|
48443
|
+
await options.tunnelManager.stop();
|
|
48444
|
+
await options.meshyNode.stop();
|
|
48445
|
+
clearTimeout(forceExitTimer);
|
|
48446
|
+
console.log("Goodbye!");
|
|
48447
|
+
process.exit(0);
|
|
48448
|
+
} catch (err) {
|
|
48449
|
+
console.error("Error during shutdown:", err);
|
|
48450
|
+
process.exit(1);
|
|
48451
|
+
}
|
|
48452
|
+
}
|
|
48453
|
+
process.on("SIGINT", shutdown);
|
|
48454
|
+
process.on("SIGTERM", shutdown);
|
|
48455
|
+
}
|
|
48456
|
+
async function startNode(args) {
|
|
48457
|
+
const { authMetadata, config, hydratedArgs, runtimeMetadata, storageRoot } = await resolveStartConfig(args);
|
|
48458
|
+
console.log("Checking startup requirements (az, devtunnel, claude, codex)...");
|
|
48459
|
+
const startupRequirements = await ensureStartupRequirements(config.storage.path);
|
|
48460
|
+
console.log(
|
|
48461
|
+
startupRequirements.skipped ? "Startup requirements already verified today; skipping checks." : "Startup requirements check complete."
|
|
48462
|
+
);
|
|
48463
|
+
const localDashboardOrigin = `http://localhost:${config.node.port}`;
|
|
48464
|
+
const logger27 = createLogger({
|
|
48465
|
+
component: "node",
|
|
48466
|
+
logDir: nodePath2.join(config.storage.path, "logs"),
|
|
48467
|
+
console: true
|
|
48468
|
+
});
|
|
48469
|
+
const nodeAuth = new AzureCliNodeAuth(config.storage.path, {
|
|
48470
|
+
logger: logger27.child("azure-auth"),
|
|
48471
|
+
settingsProvider: () => authMetadata
|
|
48472
|
+
});
|
|
48473
|
+
if (hydratedArgs.loaded) {
|
|
48474
|
+
console.log("");
|
|
48475
|
+
console.log(formatLoadedStartMetadata(hydratedArgs.loaded, authMetadata.enabled));
|
|
48476
|
+
console.log("");
|
|
48477
|
+
}
|
|
48478
|
+
if (authMetadata.enabled) {
|
|
48479
|
+
await nodeAuth.warmup();
|
|
48480
|
+
setRequestAuthHeadersProvider(() => nodeAuth.getAuthorizationHeaders());
|
|
48481
|
+
} else {
|
|
48482
|
+
setRequestAuthHeadersProvider(null);
|
|
48483
|
+
}
|
|
48484
|
+
const getSettingsSnapshot = createSettingsSnapshotProvider({
|
|
48485
|
+
authMetadata,
|
|
48486
|
+
localDashboardOrigin,
|
|
48487
|
+
runtimeMetadata,
|
|
48488
|
+
storagePath: config.storage.path,
|
|
48489
|
+
workDir: nodePath2.resolve(config.node.workDir ?? process.cwd())
|
|
48490
|
+
});
|
|
48491
|
+
const meshyNode = new MeshyNode(config, {
|
|
48492
|
+
logger: logger27,
|
|
48493
|
+
transportFactory: createTransport,
|
|
48494
|
+
getSettingsSnapshot
|
|
48495
|
+
});
|
|
48496
|
+
await meshyNode.start();
|
|
48497
|
+
meshyNode.getNodeRegistry().updateSettingsSnapshot(
|
|
48498
|
+
meshyNode.getNodeRegistry().getSelf().id,
|
|
48499
|
+
getSettingsSnapshot()
|
|
48500
|
+
);
|
|
48501
|
+
const previewSessionManager = new PreviewSessionManager();
|
|
48502
|
+
const previewProxyManager = new PreviewProxyManager();
|
|
48503
|
+
let deps;
|
|
48504
|
+
const tunnelManager = createTunnelManager({
|
|
48505
|
+
authMetadata,
|
|
48506
|
+
config,
|
|
48507
|
+
meshyNode,
|
|
48508
|
+
onDashboardOriginChange: (origin) => {
|
|
48509
|
+
if (deps) {
|
|
48510
|
+
deps.dashboardOrigin = origin;
|
|
48511
|
+
}
|
|
48512
|
+
},
|
|
48513
|
+
onShareOriginChange: (origin) => {
|
|
48514
|
+
if (deps) {
|
|
48515
|
+
deps.shareOrigin = origin;
|
|
48516
|
+
}
|
|
48517
|
+
}
|
|
48518
|
+
});
|
|
47186
48519
|
deps = {
|
|
47187
48520
|
dataRouter: meshyNode.getDataRouter(),
|
|
47188
48521
|
taskEngine: meshyNode.getTaskEngine(),
|
|
@@ -47203,10 +48536,13 @@ async function main() {
|
|
|
47203
48536
|
},
|
|
47204
48537
|
workDir: meshyNode.getWorkDir(),
|
|
47205
48538
|
storagePath: config.storage.path,
|
|
47206
|
-
persistNodeNamePreference: (name2) =>
|
|
48539
|
+
persistNodeNamePreference: (name2) => {
|
|
48540
|
+
persistDefaultNodeName(storageRoot, name2);
|
|
48541
|
+
persistDefaultNodeName(config.storage.path, name2);
|
|
48542
|
+
},
|
|
47207
48543
|
joinCurrentNodeToCluster: async (leaderEndpoint) => {
|
|
47208
48544
|
await meshyNode.joinCluster(leaderEndpoint);
|
|
47209
|
-
await syncDashboardTransport("joinCluster");
|
|
48545
|
+
await tunnelManager.syncDashboardTransport("joinCluster");
|
|
47210
48546
|
},
|
|
47211
48547
|
leaveCurrentCluster: async () => {
|
|
47212
48548
|
await meshyNode.leaveCluster();
|
|
@@ -47214,14 +48550,14 @@ async function main() {
|
|
|
47214
48550
|
switchTransport: async (type) => {
|
|
47215
48551
|
const endpoint = await meshyNode.switchTransport(type);
|
|
47216
48552
|
persistNodeStartupTransport(config.storage.path, type);
|
|
47217
|
-
await syncDashboardTransport(`switchTransport:${type}`);
|
|
48553
|
+
await tunnelManager.syncDashboardTransport(`switchTransport:${type}`);
|
|
47218
48554
|
return endpoint;
|
|
47219
48555
|
},
|
|
47220
48556
|
getTransportType: () => meshyNode.getTransportType(),
|
|
47221
48557
|
enableDevTunnel: async () => {
|
|
47222
48558
|
const endpoint = await meshyNode.enableDevTunnel();
|
|
47223
48559
|
persistNodeStartupTransport(config.storage.path, "devtunnel");
|
|
47224
|
-
await syncDashboardTransport("enableDevTunnel");
|
|
48560
|
+
await tunnelManager.syncDashboardTransport("enableDevTunnel");
|
|
47225
48561
|
return endpoint;
|
|
47226
48562
|
},
|
|
47227
48563
|
disableDevTunnel: async () => {
|
|
@@ -47230,19 +48566,17 @@ async function main() {
|
|
|
47230
48566
|
config.storage.path,
|
|
47231
48567
|
meshyNode.getTransportType()
|
|
47232
48568
|
);
|
|
47233
|
-
await syncDashboardTransport("disableDevTunnel");
|
|
48569
|
+
await tunnelManager.syncDashboardTransport("disableDevTunnel");
|
|
47234
48570
|
},
|
|
47235
48571
|
isDevTunnelEnabled: () => meshyNode.isDevTunnelEnabled(),
|
|
47236
48572
|
localDashboardOrigin,
|
|
47237
|
-
dashboardOrigin,
|
|
47238
|
-
shareOrigin,
|
|
47239
|
-
ensureShareTunnel,
|
|
47240
|
-
runtimeMetadata
|
|
48573
|
+
dashboardOrigin: tunnelManager.getDashboardOrigin(),
|
|
48574
|
+
shareOrigin: tunnelManager.getShareOrigin(),
|
|
48575
|
+
ensureShareTunnel: () => tunnelManager.ensureShareTunnel(),
|
|
48576
|
+
runtimeMetadata,
|
|
48577
|
+
previewSessionManager,
|
|
48578
|
+
previewProxyManager
|
|
47241
48579
|
};
|
|
47242
|
-
deps.previewSessionManager = previewSessionManager;
|
|
47243
|
-
deps.previewProxyManager = previewProxyManager;
|
|
47244
|
-
deps.dashboardOrigin = dashboardOrigin;
|
|
47245
|
-
deps.shareOrigin = shareOrigin;
|
|
47246
48580
|
meshyNode.getLogger().info("configured node auth mode", {
|
|
47247
48581
|
authEnabled: authMetadata.enabled,
|
|
47248
48582
|
allowSameTenant: authMetadata.allowSameTenant,
|
|
@@ -47250,93 +48584,53 @@ async function main() {
|
|
|
47250
48584
|
mainTransportType: meshyNode.getTransportType(),
|
|
47251
48585
|
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
47252
48586
|
});
|
|
47253
|
-
await syncDashboardTransport("startup");
|
|
47254
|
-
|
|
47255
|
-
void (async () => {
|
|
47256
|
-
if (!meshyNode.hasPublishedNodeTunnel()) return;
|
|
47257
|
-
const healthy = await meshyNode.isPublishedNodeTunnelHealthy().catch(() => false);
|
|
47258
|
-
if (healthy) return;
|
|
47259
|
-
meshyNode.getLogger().warn("published node tunnel became unhealthy; restarting with stable id", {
|
|
47260
|
-
mainTransportType: meshyNode.getTransportType(),
|
|
47261
|
-
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
47262
|
-
});
|
|
47263
|
-
try {
|
|
47264
|
-
const endpoint = await meshyNode.restartPublishedNodeTunnel();
|
|
47265
|
-
meshyNode.getLogger().info("restarted published node tunnel", {
|
|
47266
|
-
endpoint,
|
|
47267
|
-
stableUrl: true,
|
|
47268
|
-
mainTransportType: meshyNode.getTransportType(),
|
|
47269
|
-
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
47270
|
-
});
|
|
47271
|
-
} catch (err) {
|
|
47272
|
-
meshyNode.getLogger().warn("failed to restart published node tunnel", {
|
|
47273
|
-
error: err instanceof Error ? err.message : String(err),
|
|
47274
|
-
mainTransportType: meshyNode.getTransportType(),
|
|
47275
|
-
sidecarEnabled: meshyNode.isDevTunnelEnabled()
|
|
47276
|
-
});
|
|
47277
|
-
}
|
|
47278
|
-
})();
|
|
47279
|
-
}, config.cluster.heartbeatInterval);
|
|
47280
|
-
const dashboardHealthTimer = setInterval(() => {
|
|
47281
|
-
void (async () => {
|
|
47282
|
-
if (!dashboardTransport) return;
|
|
47283
|
-
const healthy = await dashboardTransport.isHealthy().catch(() => false);
|
|
47284
|
-
if (healthy) return;
|
|
47285
|
-
meshyNode.getLogger().warn("dashboard tunnel became unhealthy; restarting with stable id", {
|
|
47286
|
-
port: config.node.port
|
|
47287
|
-
});
|
|
47288
|
-
await restartDashboardTransport("healthcheck");
|
|
47289
|
-
})();
|
|
47290
|
-
}, config.cluster.heartbeatInterval);
|
|
48587
|
+
await tunnelManager.syncDashboardTransport("startup");
|
|
48588
|
+
tunnelManager.startHealthChecks();
|
|
47291
48589
|
const app = createServer2(deps);
|
|
47292
48590
|
const server = app.listen(config.node.port, () => {
|
|
47293
48591
|
const self2 = meshyNode.getNodeRegistry().getSelf();
|
|
47294
|
-
const role = meshyNode.getElection().isLeader() ? "leader" : "follower";
|
|
47295
|
-
const term = meshyNode.getElection().getCurrentTerm();
|
|
47296
48592
|
const banner = formatBanner({
|
|
47297
48593
|
name: self2.name,
|
|
47298
|
-
role,
|
|
47299
|
-
term,
|
|
48594
|
+
role: meshyNode.getElection().isLeader() ? "leader" : "follower",
|
|
48595
|
+
term: meshyNode.getElection().getCurrentTerm(),
|
|
47300
48596
|
endpoint: self2.endpoint,
|
|
47301
48597
|
port: config.node.port,
|
|
47302
|
-
dashboardOrigin
|
|
48598
|
+
dashboardOrigin: tunnelManager.getDashboardOrigin()
|
|
47303
48599
|
});
|
|
47304
48600
|
console.log("");
|
|
47305
48601
|
console.log(banner);
|
|
47306
48602
|
console.log("");
|
|
47307
48603
|
});
|
|
47308
|
-
|
|
47309
|
-
|
|
47310
|
-
|
|
47311
|
-
|
|
47312
|
-
|
|
47313
|
-
|
|
47314
|
-
|
|
47315
|
-
|
|
47316
|
-
|
|
47317
|
-
|
|
47318
|
-
|
|
47319
|
-
|
|
47320
|
-
|
|
47321
|
-
|
|
47322
|
-
|
|
47323
|
-
|
|
47324
|
-
|
|
47325
|
-
|
|
47326
|
-
|
|
47327
|
-
|
|
47328
|
-
|
|
47329
|
-
|
|
48604
|
+
registerShutdownHandlers({
|
|
48605
|
+
server,
|
|
48606
|
+
meshyNode,
|
|
48607
|
+
tunnelManager
|
|
48608
|
+
});
|
|
48609
|
+
}
|
|
48610
|
+
|
|
48611
|
+
// src/main.ts
|
|
48612
|
+
function handleStartupFatalError(err) {
|
|
48613
|
+
let logPath;
|
|
48614
|
+
try {
|
|
48615
|
+
logPath = writeStartupFatalError(err);
|
|
48616
|
+
} catch (logErr) {
|
|
48617
|
+
console.error(`Failed to write startup error log: ${logErr instanceof Error ? logErr.message : String(logErr)}`);
|
|
48618
|
+
}
|
|
48619
|
+
console.error(formatFatalErrorForConsole(err));
|
|
48620
|
+
if (logPath) {
|
|
48621
|
+
console.error(`Details written to ${logPath}`);
|
|
48622
|
+
}
|
|
48623
|
+
process.exit(1);
|
|
48624
|
+
}
|
|
48625
|
+
async function main() {
|
|
48626
|
+
const exitCode = await runMeshyCli(process.argv.slice(2), { startNode });
|
|
48627
|
+
if (exitCode !== 0) {
|
|
48628
|
+
process.exit(exitCode);
|
|
47330
48629
|
}
|
|
47331
|
-
process.on("SIGINT", shutdown);
|
|
47332
|
-
process.on("SIGTERM", shutdown);
|
|
47333
48630
|
}
|
|
47334
48631
|
var isDirectRun = typeof process !== "undefined" && isDirectRunPath(process.argv[1]);
|
|
47335
48632
|
if (isDirectRun) {
|
|
47336
|
-
main().catch(
|
|
47337
|
-
console.error("Fatal error:", err);
|
|
47338
|
-
process.exit(1);
|
|
47339
|
-
});
|
|
48633
|
+
main().catch(handleStartupFatalError);
|
|
47340
48634
|
}
|
|
47341
48635
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47342
48636
|
0 && (module.exports = {
|
|
@@ -47344,10 +48638,14 @@ if (isDirectRun) {
|
|
|
47344
48638
|
DEFAULT_NODE_NAME,
|
|
47345
48639
|
DEFAULT_NODE_PORT,
|
|
47346
48640
|
applyStartMetadata,
|
|
48641
|
+
closeHttpServer,
|
|
47347
48642
|
createDefaultConfig,
|
|
47348
48643
|
createRuntimeDefaultConfig,
|
|
47349
48644
|
ensureStartupRequirements,
|
|
47350
48645
|
formatBanner,
|
|
48646
|
+
formatFatalErrorForConsole,
|
|
48647
|
+
formatFatalErrorForLog,
|
|
48648
|
+
formatHelp,
|
|
47351
48649
|
formatLoadedStartMetadata,
|
|
47352
48650
|
getDefaultNodeName,
|
|
47353
48651
|
isDirectRunPath,
|
|
@@ -47360,7 +48658,8 @@ if (isDirectRun) {
|
|
|
47360
48658
|
resolveStartupRequirementsMetadata,
|
|
47361
48659
|
shouldCollectStartOptions,
|
|
47362
48660
|
shouldPromptForStartOptions,
|
|
47363
|
-
shouldSkipStartupRequirementsCheck
|
|
48661
|
+
shouldSkipStartupRequirementsCheck,
|
|
48662
|
+
startNode
|
|
47364
48663
|
});
|
|
47365
48664
|
/*! Bundled license information:
|
|
47366
48665
|
|