meshy-node 0.3.3 → 0.3.5
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 +1 -1
- package/dashboard/assets/DashboardPage-DQjLt2wn.js +124 -0
- package/dashboard/assets/{DashboardShared-C9XLT05J.js → DashboardShared-B4I_eZZK.js} +6 -6
- package/dashboard/assets/{DiffTab-BBoqxtBo.js → DiffTab-BPE2fUnK.js} +3 -3
- package/dashboard/assets/{FilesTab-8j_HSIrt.js → FilesTab-CLLyWXEv.js} +8 -8
- package/dashboard/assets/PreviewTab-C1SWykXF.js +26 -0
- package/dashboard/assets/SharedConversationPage-CDFyo1wW.js +12 -0
- package/dashboard/assets/{file-DgdB9H7_.js → file-YGIDkO7j.js} +1 -1
- package/dashboard/assets/{folder-5L-FBUD2.js → folder-BNfC8Y62.js} +1 -1
- package/dashboard/assets/{index-D2dDklXI.js → index-Cpz4J5-T.js} +59 -59
- package/dashboard/assets/index-DvQBsfbb.css +1 -0
- package/dashboard/assets/input-BRIa-GWn.js +1 -0
- package/dashboard/index.html +2 -2
- package/main.cjs +1803 -769
- package/package.json +1 -1
- package/runtime-metadata.json +5 -5
- package/dashboard/assets/DashboardPage-vg1FNZ-b.js +0 -124
- package/dashboard/assets/PreviewTab-CcfSJBUg.js +0 -16
- package/dashboard/assets/SharedConversationPage-CNmEk_vb.js +0 -12
- package/dashboard/assets/index-XG2bTevi.css +0 -1
package/main.cjs
CHANGED
|
@@ -6629,8 +6629,8 @@ var require_node2 = __commonJS({
|
|
|
6629
6629
|
}
|
|
6630
6630
|
break;
|
|
6631
6631
|
case "FILE":
|
|
6632
|
-
var
|
|
6633
|
-
stream2 = new
|
|
6632
|
+
var fs22 = require("fs");
|
|
6633
|
+
stream2 = new fs22.SyncWriteStream(fd2, { autoClose: false });
|
|
6634
6634
|
stream2._type = "fs";
|
|
6635
6635
|
break;
|
|
6636
6636
|
case "PIPE":
|
|
@@ -10057,13 +10057,13 @@ var require_extend_node = __commonJS({
|
|
|
10057
10057
|
return length;
|
|
10058
10058
|
};
|
|
10059
10059
|
if (iconv.supportsStreams) {
|
|
10060
|
-
var
|
|
10061
|
-
original.ReadableSetEncoding =
|
|
10062
|
-
|
|
10060
|
+
var Readable3 = require("stream").Readable;
|
|
10061
|
+
original.ReadableSetEncoding = Readable3.prototype.setEncoding;
|
|
10062
|
+
Readable3.prototype.setEncoding = function setEncoding(enc, options) {
|
|
10063
10063
|
this._readableState.decoder = iconv.getDecoder(enc, options);
|
|
10064
10064
|
this._readableState.encoding = enc;
|
|
10065
10065
|
};
|
|
10066
|
-
|
|
10066
|
+
Readable3.prototype.collect = iconv._collect;
|
|
10067
10067
|
}
|
|
10068
10068
|
};
|
|
10069
10069
|
iconv.undoExtendNodeEncodings = function undoExtendNodeEncodings() {
|
|
@@ -10080,9 +10080,9 @@ var require_extend_node = __commonJS({
|
|
|
10080
10080
|
Buffer2.prototype.toString = original.BufferToString;
|
|
10081
10081
|
Buffer2.prototype.write = original.BufferWrite;
|
|
10082
10082
|
if (iconv.supportsStreams) {
|
|
10083
|
-
var
|
|
10084
|
-
|
|
10085
|
-
delete
|
|
10083
|
+
var Readable3 = require("stream").Readable;
|
|
10084
|
+
Readable3.prototype.setEncoding = original.ReadableSetEncoding;
|
|
10085
|
+
delete Readable3.prototype.collect;
|
|
10086
10086
|
}
|
|
10087
10087
|
original = void 0;
|
|
10088
10088
|
};
|
|
@@ -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(path23) {
|
|
19424
|
+
if (!path23 || typeof path23 !== "string") {
|
|
19425
19425
|
return false;
|
|
19426
19426
|
}
|
|
19427
|
-
var extension2 = extname3("x." +
|
|
19427
|
+
var extension2 = extname3("x." + path23).toLowerCase().substr(1);
|
|
19428
19428
|
if (!extension2) {
|
|
19429
19429
|
return false;
|
|
19430
19430
|
}
|
|
@@ -22624,8 +22624,8 @@ var require_escape_html = __commonJS({
|
|
|
22624
22624
|
"../../node_modules/.pnpm/escape-html@1.0.3/node_modules/escape-html/index.js"(exports2, module2) {
|
|
22625
22625
|
"use strict";
|
|
22626
22626
|
var matchHtmlRegExp = /["'&<>]/;
|
|
22627
|
-
module2.exports =
|
|
22628
|
-
function
|
|
22627
|
+
module2.exports = escapeHtml2;
|
|
22628
|
+
function escapeHtml2(string) {
|
|
22629
22629
|
var str = "" + string;
|
|
22630
22630
|
var match = matchHtmlRegExp.exec(str);
|
|
22631
22631
|
if (!match) {
|
|
@@ -22756,7 +22756,7 @@ var require_finalhandler = __commonJS({
|
|
|
22756
22756
|
"use strict";
|
|
22757
22757
|
var debug = require_src2()("finalhandler");
|
|
22758
22758
|
var encodeUrl = require_encodeurl();
|
|
22759
|
-
var
|
|
22759
|
+
var escapeHtml2 = require_escape_html();
|
|
22760
22760
|
var onFinished = require_on_finished();
|
|
22761
22761
|
var parseUrl = require_parseurl();
|
|
22762
22762
|
var statuses = require_statuses();
|
|
@@ -22768,7 +22768,7 @@ var require_finalhandler = __commonJS({
|
|
|
22768
22768
|
};
|
|
22769
22769
|
var isFinished = onFinished.isFinished;
|
|
22770
22770
|
function createHtmlDocument(message) {
|
|
22771
|
-
var body =
|
|
22771
|
+
var body = escapeHtml2(message).replace(NEWLINE_REGEXP, "<br>").replace(DOUBLE_SPACE_REGEXP, " ");
|
|
22772
22772
|
return '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>' + body + "</pre>\n</body>\n</html>\n";
|
|
22773
22773
|
}
|
|
22774
22774
|
module2.exports = finalhandler;
|
|
@@ -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(path23, 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 (path23 instanceof RegExp) {
|
|
22960
|
+
while (m = MATCHING_GROUP_REGEXP.exec(path23.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 path23;
|
|
22969
22969
|
}
|
|
22970
|
-
if (Array.isArray(
|
|
22971
|
-
|
|
22970
|
+
if (Array.isArray(path23)) {
|
|
22971
|
+
path23 = path23.map(function(value) {
|
|
22972
22972
|
return pathToRegexp(value, keys, options).source;
|
|
22973
22973
|
});
|
|
22974
|
-
return new RegExp(
|
|
22974
|
+
return new RegExp(path23.join("|"), flags);
|
|
22975
22975
|
}
|
|
22976
|
-
if (typeof
|
|
22976
|
+
if (typeof path23 !== "string") {
|
|
22977
22977
|
throw new TypeError("path must be a string, array of strings, or regular expression");
|
|
22978
22978
|
}
|
|
22979
|
-
|
|
22979
|
+
path23 = path23.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 += path23.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(path23)) {
|
|
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
|
+
path23 += strict ? "" : path23[path23.length - 1] === "/" ? "?" : "/?";
|
|
23039
23039
|
if (end) {
|
|
23040
|
-
|
|
23041
|
-
} else if (
|
|
23042
|
-
|
|
23040
|
+
path23 += "$";
|
|
23041
|
+
} else if (path23[path23.length - 1] !== "/") {
|
|
23042
|
+
path23 += lookahead ? "(?=/|$)" : "(?:/|$)";
|
|
23043
23043
|
}
|
|
23044
|
-
return new RegExp("^" +
|
|
23044
|
+
return new RegExp("^" + path23, 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(path23, options, fn) {
|
|
23058
23058
|
if (!(this instanceof Layer)) {
|
|
23059
|
-
return new Layer(
|
|
23059
|
+
return new Layer(path23, options, fn);
|
|
23060
23060
|
}
|
|
23061
|
-
debug("new %o",
|
|
23061
|
+
debug("new %o", path23);
|
|
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(path23, this.keys = [], opts);
|
|
23068
|
+
this.regexp.fast_star = path23 === "*";
|
|
23069
|
+
this.regexp.fast_slash = path23 === "/" && 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(path23) {
|
|
23094
23094
|
var match2;
|
|
23095
|
-
if (
|
|
23095
|
+
if (path23 != 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(path23) };
|
|
23103
|
+
this.path = path23;
|
|
23104
23104
|
return true;
|
|
23105
23105
|
}
|
|
23106
|
-
match2 = this.regexp.exec(
|
|
23106
|
+
match2 = this.regexp.exec(path23);
|
|
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(path23) {
|
|
23200
|
+
this.path = path23;
|
|
23201
23201
|
this.stack = [];
|
|
23202
|
-
debug("new %o",
|
|
23202
|
+
debug("new %o", path23);
|
|
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 path23 = getPathname(req);
|
|
23416
|
+
if (path23 == 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, path23);
|
|
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, path23);
|
|
23463
23463
|
}
|
|
23464
23464
|
sync = 0;
|
|
23465
23465
|
});
|
|
23466
23466
|
}
|
|
23467
|
-
function trim_prefix(layer, layerError, layerPath,
|
|
23467
|
+
function trim_prefix(layer, layerError, layerPath, path23) {
|
|
23468
23468
|
if (layerPath.length !== 0) {
|
|
23469
|
-
if (layerPath !==
|
|
23469
|
+
if (layerPath !== path23.slice(0, layerPath.length)) {
|
|
23470
23470
|
next(layerError);
|
|
23471
23471
|
return;
|
|
23472
23472
|
}
|
|
23473
|
-
var c =
|
|
23473
|
+
var c = path23[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 path23 = "/";
|
|
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
|
+
path23 = 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", path23, fn.name || "<anonymous>");
|
|
23572
|
+
var layer = new Layer(path23, {
|
|
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(path23) {
|
|
23583
|
+
var route2 = new Route(path23);
|
|
23584
|
+
var layer = new Layer(path23, {
|
|
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(path23) {
|
|
23595
|
+
var route = this.route(path23);
|
|
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, path23) {
|
|
23632
23632
|
try {
|
|
23633
|
-
return layer.match(
|
|
23633
|
+
return layer.match(path23);
|
|
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 dirname7 =
|
|
23754
|
-
var
|
|
23755
|
-
var extname3 =
|
|
23756
|
-
var
|
|
23757
|
-
var resolve14 =
|
|
23751
|
+
var path23 = require("path");
|
|
23752
|
+
var fs22 = require("fs");
|
|
23753
|
+
var dirname7 = path23.dirname;
|
|
23754
|
+
var basename5 = path23.basename;
|
|
23755
|
+
var extname3 = path23.extname;
|
|
23756
|
+
var join18 = path23.join;
|
|
23757
|
+
var resolve14 = path23.resolve;
|
|
23758
23758
|
module2.exports = View;
|
|
23759
23759
|
function View(name2, options) {
|
|
23760
23760
|
var opts = options || {};
|
|
@@ -23783,17 +23783,17 @@ 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 path24;
|
|
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 && !path24; i++) {
|
|
23790
23790
|
var root = roots[i];
|
|
23791
23791
|
var loc = resolve14(root, name2);
|
|
23792
23792
|
var dir = dirname7(loc);
|
|
23793
|
-
var file =
|
|
23794
|
-
|
|
23793
|
+
var file = basename5(loc);
|
|
23794
|
+
path24 = this.resolve(dir, file);
|
|
23795
23795
|
}
|
|
23796
|
-
return
|
|
23796
|
+
return path24;
|
|
23797
23797
|
};
|
|
23798
23798
|
View.prototype.render = function render(options, callback) {
|
|
23799
23799
|
debug('render "%s"', this.path);
|
|
@@ -23801,21 +23801,21 @@ var require_view = __commonJS({
|
|
|
23801
23801
|
};
|
|
23802
23802
|
View.prototype.resolve = function resolve15(dir, file) {
|
|
23803
23803
|
var ext = this.ext;
|
|
23804
|
-
var
|
|
23805
|
-
var stat = tryStat(
|
|
23804
|
+
var path24 = join18(dir, file);
|
|
23805
|
+
var stat = tryStat(path24);
|
|
23806
23806
|
if (stat && stat.isFile()) {
|
|
23807
|
-
return
|
|
23807
|
+
return path24;
|
|
23808
23808
|
}
|
|
23809
|
-
|
|
23810
|
-
stat = tryStat(
|
|
23809
|
+
path24 = join18(dir, basename5(file, ext), "index" + ext);
|
|
23810
|
+
stat = tryStat(path24);
|
|
23811
23811
|
if (stat && stat.isFile()) {
|
|
23812
|
-
return
|
|
23812
|
+
return path24;
|
|
23813
23813
|
}
|
|
23814
23814
|
};
|
|
23815
|
-
function tryStat(
|
|
23816
|
-
debug('stat "%s"',
|
|
23815
|
+
function tryStat(path24) {
|
|
23816
|
+
debug('stat "%s"', path24);
|
|
23817
23817
|
try {
|
|
23818
|
-
return
|
|
23818
|
+
return fs22.statSync(path24);
|
|
23819
23819
|
} catch (e) {
|
|
23820
23820
|
return void 0;
|
|
23821
23821
|
}
|
|
@@ -23829,7 +23829,7 @@ var require_content_disposition = __commonJS({
|
|
|
23829
23829
|
"use strict";
|
|
23830
23830
|
module2.exports = contentDisposition;
|
|
23831
23831
|
module2.exports.parse = parse;
|
|
23832
|
-
var
|
|
23832
|
+
var basename5 = require("path").basename;
|
|
23833
23833
|
var Buffer2 = require_safe_buffer().Buffer;
|
|
23834
23834
|
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g;
|
|
23835
23835
|
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/;
|
|
@@ -23865,9 +23865,9 @@ var require_content_disposition = __commonJS({
|
|
|
23865
23865
|
if (typeof fallback === "string" && NON_LATIN1_REGEXP.test(fallback)) {
|
|
23866
23866
|
throw new TypeError("fallback must be ISO-8859-1 string");
|
|
23867
23867
|
}
|
|
23868
|
-
var name2 =
|
|
23868
|
+
var name2 = basename5(filename);
|
|
23869
23869
|
var isQuotedString = TEXT_REGEXP.test(name2);
|
|
23870
|
-
var fallbackName = typeof fallback !== "string" ? fallback && getlatin1(name2) :
|
|
23870
|
+
var fallbackName = typeof fallback !== "string" ? fallback && getlatin1(name2) : basename5(fallback);
|
|
23871
23871
|
var hasFallback = typeof fallbackName === "string" && fallbackName !== name2;
|
|
23872
23872
|
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name2)) {
|
|
23873
23873
|
params["filename*"] = name2;
|
|
@@ -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 path23 = require("path");
|
|
24116
|
+
var fs22 = 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 = fs22.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(path24, fallback) {
|
|
24146
|
+
var ext = path24.replace(/^.*[\.\/\\]/, "").toLowerCase();
|
|
24147
24147
|
return this.types[ext] || fallback || this.default_type;
|
|
24148
24148
|
};
|
|
24149
24149
|
Mime.prototype.extension = function(mimeType) {
|
|
@@ -24253,36 +24253,36 @@ var require_send = __commonJS({
|
|
|
24253
24253
|
var deprecate = require_depd()("send");
|
|
24254
24254
|
var destroy2 = require_destroy();
|
|
24255
24255
|
var encodeUrl = require_encodeurl();
|
|
24256
|
-
var
|
|
24256
|
+
var escapeHtml2 = require_escape_html();
|
|
24257
24257
|
var etag = require_etag();
|
|
24258
24258
|
var fresh = require_fresh();
|
|
24259
|
-
var
|
|
24259
|
+
var fs22 = 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 path23 = 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 resolve14 =
|
|
24272
|
-
var sep4 =
|
|
24268
|
+
var extname3 = path23.extname;
|
|
24269
|
+
var join18 = path23.join;
|
|
24270
|
+
var normalize = path23.normalize;
|
|
24271
|
+
var resolve14 = path23.resolve;
|
|
24272
|
+
var sep4 = path23.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, path24, options) {
|
|
24279
|
+
return new SendStream(req, path24, options);
|
|
24280
24280
|
}
|
|
24281
|
-
function SendStream(req,
|
|
24281
|
+
function SendStream(req, path24, options) {
|
|
24282
24282
|
Stream.call(this);
|
|
24283
24283
|
var opts = options || {};
|
|
24284
24284
|
this.options = opts;
|
|
24285
|
-
this.path =
|
|
24285
|
+
this.path = path24;
|
|
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;
|
|
@@ -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 = resolve14(String(
|
|
24331
|
+
SendStream.prototype.root = function root(path24) {
|
|
24332
|
+
this._root = resolve14(String(path24));
|
|
24333
24333
|
debug("root %s", this._root);
|
|
24334
24334
|
return this;
|
|
24335
24335
|
};
|
|
@@ -24353,7 +24353,7 @@ var require_send = __commonJS({
|
|
|
24353
24353
|
}
|
|
24354
24354
|
var res = this.res;
|
|
24355
24355
|
var msg = statuses.message[status] || String(status);
|
|
24356
|
-
var doc = createHtmlDocument("Error",
|
|
24356
|
+
var doc = createHtmlDocument("Error", escapeHtml2(msg));
|
|
24357
24357
|
clearHeaders(res);
|
|
24358
24358
|
if (err && err.headers) {
|
|
24359
24359
|
setHeaders(res, err.headers);
|
|
@@ -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(path24) {
|
|
24446
24446
|
var res = this.res;
|
|
24447
24447
|
if (hasListeners(this, "directory")) {
|
|
24448
|
-
this.emit("directory", res,
|
|
24448
|
+
this.emit("directory", res, path24);
|
|
24449
24449
|
return;
|
|
24450
24450
|
}
|
|
24451
24451
|
if (this.hasTrailingSlash()) {
|
|
@@ -24453,7 +24453,7 @@ var require_send = __commonJS({
|
|
|
24453
24453
|
return;
|
|
24454
24454
|
}
|
|
24455
24455
|
var loc = encodeUrl(collapseLeadingSlashes(this.path + "/"));
|
|
24456
|
-
var doc = createHtmlDocument("Redirecting", "Redirecting to " +
|
|
24456
|
+
var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml2(loc));
|
|
24457
24457
|
res.statusCode = 301;
|
|
24458
24458
|
res.setHeader("Content-Type", "text/html; charset=UTF-8");
|
|
24459
24459
|
res.setHeader("Content-Length", Buffer.byteLength(doc));
|
|
@@ -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 path24 = decode(this.path);
|
|
24469
|
+
if (path24 === -1) {
|
|
24470
24470
|
this.error(400);
|
|
24471
24471
|
return res;
|
|
24472
24472
|
}
|
|
24473
|
-
if (~
|
|
24473
|
+
if (~path24.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 (path24) {
|
|
24480
|
+
path24 = normalize("." + sep4 + path24);
|
|
24481
24481
|
}
|
|
24482
|
-
if (UP_PATH_REGEXP.test(
|
|
24483
|
-
debug('malicious path "%s"',
|
|
24482
|
+
if (UP_PATH_REGEXP.test(path24)) {
|
|
24483
|
+
debug('malicious path "%s"', path24);
|
|
24484
24484
|
this.error(403);
|
|
24485
24485
|
return res;
|
|
24486
24486
|
}
|
|
24487
|
-
parts =
|
|
24488
|
-
|
|
24487
|
+
parts = path24.split(sep4);
|
|
24488
|
+
path24 = normalize(join18(root, path24));
|
|
24489
24489
|
} else {
|
|
24490
|
-
if (UP_PATH_REGEXP.test(
|
|
24491
|
-
debug('malicious path "%s"',
|
|
24490
|
+
if (UP_PATH_REGEXP.test(path24)) {
|
|
24491
|
+
debug('malicious path "%s"', path24);
|
|
24492
24492
|
this.error(403);
|
|
24493
24493
|
return res;
|
|
24494
24494
|
}
|
|
24495
|
-
parts = normalize(
|
|
24496
|
-
|
|
24495
|
+
parts = normalize(path24).split(sep4);
|
|
24496
|
+
path24 = resolve14(path24);
|
|
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, path24);
|
|
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(path24);
|
|
24518
24518
|
return res;
|
|
24519
24519
|
}
|
|
24520
|
-
this.sendFile(
|
|
24520
|
+
this.sendFile(path24);
|
|
24521
24521
|
return res;
|
|
24522
24522
|
};
|
|
24523
|
-
SendStream.prototype.send = function send2(
|
|
24523
|
+
SendStream.prototype.send = function send2(path24, 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"', path24);
|
|
24536
|
+
this.setHeader(path24, stat);
|
|
24537
|
+
this.type(path24);
|
|
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(path24, opts);
|
|
24587
24587
|
};
|
|
24588
|
-
SendStream.prototype.sendFile = function sendFile(
|
|
24588
|
+
SendStream.prototype.sendFile = function sendFile(path24) {
|
|
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"', path24);
|
|
24592
|
+
fs22.stat(path24, function onstat(err, stat) {
|
|
24593
|
+
if (err && err.code === "ENOENT" && !extname3(path24) && path24[path24.length - 1] !== sep4) {
|
|
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(path24);
|
|
24598
|
+
self2.emit("file", path24, stat);
|
|
24599
|
+
self2.send(path24, 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 = path24 + "." + self2._extensions[i++];
|
|
24606
24606
|
debug('stat "%s"', p);
|
|
24607
|
-
|
|
24607
|
+
fs22.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(path24) {
|
|
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 = join18(path24, self2._index[i]);
|
|
24624
24624
|
debug('stat "%s"', p);
|
|
24625
|
-
|
|
24625
|
+
fs22.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(path24, options) {
|
|
24635
24635
|
var self2 = this;
|
|
24636
24636
|
var res = this.res;
|
|
24637
|
-
var stream2 =
|
|
24637
|
+
var stream2 = fs22.createReadStream(path24, 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(path24) {
|
|
24653
24653
|
var res = this.res;
|
|
24654
24654
|
if (res.getHeader("Content-Type")) return;
|
|
24655
|
-
var type2 = mime.lookup(
|
|
24655
|
+
var type2 = mime.lookup(path24);
|
|
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(path24, stat) {
|
|
24665
24665
|
var res = this.res;
|
|
24666
|
-
this.emit("headers", res,
|
|
24666
|
+
this.emit("headers", res, path24, 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(path24) {
|
|
24726
24726
|
try {
|
|
24727
|
-
return decodeURIComponent(
|
|
24727
|
+
return decodeURIComponent(path24);
|
|
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(path23) {
|
|
25638
|
+
if ("/" === path23[0]) return true;
|
|
25639
|
+
if (":" === path23[1] && ("\\" === path23[2] || "/" === path23[2])) return true;
|
|
25640
|
+
if ("\\\\" === path23.substring(0, 2)) return true;
|
|
25641
25641
|
};
|
|
25642
25642
|
exports2.flatten = deprecate.function(
|
|
25643
25643
|
flatten,
|
|
@@ -25760,7 +25760,7 @@ var require_application = __commonJS({
|
|
|
25760
25760
|
"../../node_modules/.pnpm/express@4.22.1/node_modules/express/lib/application.js"(exports2, module2) {
|
|
25761
25761
|
"use strict";
|
|
25762
25762
|
var finalhandler = require_finalhandler();
|
|
25763
|
-
var
|
|
25763
|
+
var Router14 = require_router();
|
|
25764
25764
|
var methods = require_methods();
|
|
25765
25765
|
var middleware = require_init();
|
|
25766
25766
|
var query = require_query();
|
|
@@ -25825,7 +25825,7 @@ var require_application = __commonJS({
|
|
|
25825
25825
|
};
|
|
25826
25826
|
app.lazyrouter = function lazyrouter() {
|
|
25827
25827
|
if (!this._router) {
|
|
25828
|
-
this._router = new
|
|
25828
|
+
this._router = new Router14({
|
|
25829
25829
|
caseSensitive: this.enabled("case sensitive routing"),
|
|
25830
25830
|
strict: this.enabled("strict routing")
|
|
25831
25831
|
});
|
|
@@ -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 path23 = "/";
|
|
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
|
+
path23 = 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(path23, fn2);
|
|
25871
25871
|
}
|
|
25872
|
-
debug(".use app under %s",
|
|
25873
|
-
fn2.mountpath =
|
|
25872
|
+
debug(".use app under %s", path23);
|
|
25873
|
+
fn2.mountpath = path23;
|
|
25874
25874
|
fn2.parent = this;
|
|
25875
|
-
router.use(
|
|
25875
|
+
router.use(path23, 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(path23) {
|
|
25888
25888
|
this.lazyrouter();
|
|
25889
|
-
return this._router.route(
|
|
25889
|
+
return this._router.route(path23);
|
|
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 path23() {
|
|
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(path23) {
|
|
25957
25957
|
if (method === "get" && arguments.length === 1) {
|
|
25958
|
-
return this.set(
|
|
25958
|
+
return this.set(path23);
|
|
25959
25959
|
}
|
|
25960
25960
|
this.lazyrouter();
|
|
25961
|
-
var route = this._router.route(
|
|
25961
|
+
var route = this._router.route(path23);
|
|
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(path23) {
|
|
25967
25967
|
this.lazyrouter();
|
|
25968
|
-
var route = this._router.route(
|
|
25968
|
+
var route = this._router.route(path23);
|
|
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 path23() {
|
|
26728
26728
|
return parse(this).pathname;
|
|
26729
26729
|
});
|
|
26730
26730
|
defineGetter(req, "hostname", function hostname3() {
|
|
@@ -27043,11 +27043,11 @@ var require_response = __commonJS({
|
|
|
27043
27043
|
var createError = require_http_errors();
|
|
27044
27044
|
var deprecate = require_depd()("express");
|
|
27045
27045
|
var encodeUrl = require_encodeurl();
|
|
27046
|
-
var
|
|
27046
|
+
var escapeHtml2 = require_escape_html();
|
|
27047
27047
|
var http3 = require("http");
|
|
27048
27048
|
var isAbsolute4 = require_utils2().isAbsolute;
|
|
27049
27049
|
var onFinished = require_on_finished();
|
|
27050
|
-
var
|
|
27050
|
+
var path23 = 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 = path23.extname;
|
|
27060
27060
|
var mime = send.mime;
|
|
27061
|
-
var resolve14 =
|
|
27061
|
+
var resolve14 = path23.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(path24, 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 (!path24) {
|
|
27245
27245
|
throw new TypeError("path argument is required to res.sendFile");
|
|
27246
27246
|
}
|
|
27247
|
-
if (typeof
|
|
27247
|
+
if (typeof path24 !== "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(path24)) {
|
|
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(path24);
|
|
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(path24, 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, path24, 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(path24, 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 || path24)
|
|
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 ? resolve14(
|
|
27320
|
+
var fullPath = !opts.root ? resolve14(path24) : path24;
|
|
27321
27321
|
return this.sendFile(fullPath, opts, done);
|
|
27322
27322
|
};
|
|
27323
27323
|
res.contentType = res.type = function contentType(type) {
|
|
@@ -27449,7 +27449,7 @@ var require_response = __commonJS({
|
|
|
27449
27449
|
body = statuses.message[status] + ". Redirecting to " + address;
|
|
27450
27450
|
},
|
|
27451
27451
|
html: function() {
|
|
27452
|
-
var u =
|
|
27452
|
+
var u = escapeHtml2(address);
|
|
27453
27453
|
body = "<p>" + statuses.message[status] + ". Redirecting to " + u + "</p>";
|
|
27454
27454
|
},
|
|
27455
27455
|
default: function() {
|
|
@@ -27581,7 +27581,7 @@ var require_serve_static = __commonJS({
|
|
|
27581
27581
|
"../../node_modules/.pnpm/serve-static@1.16.3/node_modules/serve-static/index.js"(exports2, module2) {
|
|
27582
27582
|
"use strict";
|
|
27583
27583
|
var encodeUrl = require_encodeurl();
|
|
27584
|
-
var
|
|
27584
|
+
var escapeHtml2 = require_escape_html();
|
|
27585
27585
|
var parseUrl = require_parseurl();
|
|
27586
27586
|
var resolve14 = require("path").resolve;
|
|
27587
27587
|
var send = require_send();
|
|
@@ -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 path23 = parseUrl(req).pathname;
|
|
27622
|
+
if (path23 === "/" && originalUrl.pathname.substr(-1) !== "/") {
|
|
27623
|
+
path23 = "";
|
|
27624
27624
|
}
|
|
27625
|
-
var stream = send(req,
|
|
27625
|
+
var stream = send(req, path23, opts);
|
|
27626
27626
|
stream.on("directory", onDirectory);
|
|
27627
27627
|
if (setHeaders) {
|
|
27628
27628
|
stream.on("headers", setHeaders);
|
|
@@ -27668,7 +27668,7 @@ var require_serve_static = __commonJS({
|
|
|
27668
27668
|
originalUrl.path = null;
|
|
27669
27669
|
originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + "/");
|
|
27670
27670
|
var loc = encodeUrl(url.format(originalUrl));
|
|
27671
|
-
var doc = createHtmlDocument("Redirecting", "Redirecting to " +
|
|
27671
|
+
var doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml2(loc));
|
|
27672
27672
|
res.statusCode = 301;
|
|
27673
27673
|
res.setHeader("Content-Type", "text/html; charset=UTF-8");
|
|
27674
27674
|
res.setHeader("Content-Length", Buffer.byteLength(doc));
|
|
@@ -27690,7 +27690,7 @@ var require_express = __commonJS({
|
|
|
27690
27690
|
var mixin = require_merge_descriptors();
|
|
27691
27691
|
var proto = require_application();
|
|
27692
27692
|
var Route = require_route();
|
|
27693
|
-
var
|
|
27693
|
+
var Router14 = require_router();
|
|
27694
27694
|
var req = require_request();
|
|
27695
27695
|
var res = require_response();
|
|
27696
27696
|
exports2 = module2.exports = createApplication;
|
|
@@ -27713,7 +27713,7 @@ var require_express = __commonJS({
|
|
|
27713
27713
|
exports2.request = req;
|
|
27714
27714
|
exports2.response = res;
|
|
27715
27715
|
exports2.Route = Route;
|
|
27716
|
-
exports2.Router =
|
|
27716
|
+
exports2.Router = Router14;
|
|
27717
27717
|
exports2.json = bodyParser.json;
|
|
27718
27718
|
exports2.query = require_query();
|
|
27719
27719
|
exports2.raw = bodyParser.raw;
|
|
@@ -32265,11 +32265,11 @@ function persistNodeStartupTransport(storagePath, transport) {
|
|
|
32265
32265
|
transport
|
|
32266
32266
|
});
|
|
32267
32267
|
}
|
|
32268
|
-
function persistNodeStartupJoin(storagePath,
|
|
32268
|
+
function persistNodeStartupJoin(storagePath, join18) {
|
|
32269
32269
|
const startup = resolveNodeStartupMetadata(storagePath);
|
|
32270
32270
|
persistNodeStartupMetadata(storagePath, {
|
|
32271
32271
|
...startup,
|
|
32272
|
-
join:
|
|
32272
|
+
join: join18
|
|
32273
32273
|
});
|
|
32274
32274
|
}
|
|
32275
32275
|
function resolvePersistedDevTunnelId(storagePath, kind) {
|
|
@@ -33266,19 +33266,19 @@ async function fetchWithTimeout(url, init, timeoutMs = DEFAULT_NODE_REQUEST_TIME
|
|
|
33266
33266
|
cleanup();
|
|
33267
33267
|
}
|
|
33268
33268
|
}
|
|
33269
|
-
async function fetchNodeWithFallback(node,
|
|
33269
|
+
async function fetchNodeWithFallback(node, path23, init, timeoutMs = DEFAULT_NODE_REQUEST_TIMEOUT_MS, trace, options) {
|
|
33270
33270
|
let lastError;
|
|
33271
33271
|
const endpoints = getNodeRequestEndpoints(node, options);
|
|
33272
33272
|
for (const [index, endpoint] of endpoints.entries()) {
|
|
33273
33273
|
const attempt = index + 1;
|
|
33274
|
-
trace?.onAttempt?.({ attempt, endpoint, path:
|
|
33274
|
+
trace?.onAttempt?.({ attempt, endpoint, path: path23, timeoutMs, totalEndpoints: endpoints.length });
|
|
33275
33275
|
try {
|
|
33276
|
-
const response = await fetchWithTimeout(`${endpoint}${
|
|
33277
|
-
trace?.onResponse?.({ attempt, endpoint, path:
|
|
33276
|
+
const response = await fetchWithTimeout(`${endpoint}${path23}`, init, timeoutMs);
|
|
33277
|
+
trace?.onResponse?.({ attempt, endpoint, path: path23, response, timeoutMs, totalEndpoints: endpoints.length });
|
|
33278
33278
|
return { endpoint, response };
|
|
33279
33279
|
} catch (error) {
|
|
33280
33280
|
lastError = error;
|
|
33281
|
-
trace?.onError?.({ attempt, endpoint, error, path:
|
|
33281
|
+
trace?.onError?.({ attempt, endpoint, error, path: path23, timeoutMs, totalEndpoints: endpoints.length });
|
|
33282
33282
|
}
|
|
33283
33283
|
}
|
|
33284
33284
|
throw lastError instanceof Error ? lastError : new Error("No reachable node endpoint");
|
|
@@ -33847,6 +33847,7 @@ var TaskEngine = class {
|
|
|
33847
33847
|
}
|
|
33848
33848
|
/** Tracks which node a task was previously assigned to, for retry preference. */
|
|
33849
33849
|
previousAssignments = /* @__PURE__ */ new Map();
|
|
33850
|
+
deletedTaskIds = /* @__PURE__ */ new Set();
|
|
33850
33851
|
// ── Task CRUD ────────────────────────────────────────────────────────
|
|
33851
33852
|
createTask(input) {
|
|
33852
33853
|
if (!input.title) {
|
|
@@ -33901,6 +33902,9 @@ var TaskEngine = class {
|
|
|
33901
33902
|
let created = 0;
|
|
33902
33903
|
let updated = 0;
|
|
33903
33904
|
for (const task of tasks) {
|
|
33905
|
+
if (this.deletedTaskIds.has(task.id)) {
|
|
33906
|
+
continue;
|
|
33907
|
+
}
|
|
33904
33908
|
const existing = this.store.getTask(task.id);
|
|
33905
33909
|
if (!existing) {
|
|
33906
33910
|
this.store.createTask(task);
|
|
@@ -33962,6 +33966,7 @@ var TaskEngine = class {
|
|
|
33962
33966
|
const deleted = this.store.deleteTask(id);
|
|
33963
33967
|
if (!deleted) return false;
|
|
33964
33968
|
this.previousAssignments.delete(id);
|
|
33969
|
+
this.deletedTaskIds.add(id);
|
|
33965
33970
|
if (this.logDir) {
|
|
33966
33971
|
const logFile = path4.join(this.logDir, `${id}.jsonl`);
|
|
33967
33972
|
try {
|
|
@@ -35321,9 +35326,9 @@ var DataRouter = class {
|
|
|
35321
35326
|
/**
|
|
35322
35327
|
* Returns true if the request should be proxied to the leader.
|
|
35323
35328
|
*/
|
|
35324
|
-
shouldProxy(method,
|
|
35329
|
+
shouldProxy(method, path23) {
|
|
35325
35330
|
if (this.election.isLeader()) return false;
|
|
35326
|
-
if (this.isExcludedPath(
|
|
35331
|
+
if (this.isExcludedPath(path23)) return false;
|
|
35327
35332
|
if (method.toUpperCase() === "GET") return false;
|
|
35328
35333
|
return WRITE_METHODS.has(method.toUpperCase());
|
|
35329
35334
|
}
|
|
@@ -35427,8 +35432,8 @@ var DataRouter = class {
|
|
|
35427
35432
|
};
|
|
35428
35433
|
}
|
|
35429
35434
|
// ── Helpers ───────────────────────────────────────────────────────────
|
|
35430
|
-
isExcludedPath(
|
|
35431
|
-
return EXCLUDED_PATH_PREFIXES.some((prefix) =>
|
|
35435
|
+
isExcludedPath(path23) {
|
|
35436
|
+
return EXCLUDED_PATH_PREFIXES.some((prefix) => path23.startsWith(prefix)) || EXCLUDED_PATH_SUFFIXES.some((suffix) => path23.endsWith(suffix));
|
|
35432
35437
|
}
|
|
35433
35438
|
};
|
|
35434
35439
|
|
|
@@ -36197,14 +36202,51 @@ var import_node_child_process3 = require("child_process");
|
|
|
36197
36202
|
// ../../packages/core/src/agents/cli-invocations.ts
|
|
36198
36203
|
var fs8 = __toESM(require("fs"), 1);
|
|
36199
36204
|
var path8 = __toESM(require("path"), 1);
|
|
36205
|
+
var WINDOWS_CLAUDE_NATIVE_PACKAGES = {
|
|
36206
|
+
x64: "@anthropic-ai/claude-code-win32-x64",
|
|
36207
|
+
arm64: "@anthropic-ai/claude-code-win32-arm64"
|
|
36208
|
+
};
|
|
36209
|
+
function getPathEntries() {
|
|
36210
|
+
return (process.env.PATH ?? process.env.Path ?? process.env.path ?? "").split(path8.delimiter).filter(Boolean);
|
|
36211
|
+
}
|
|
36212
|
+
function isWindowsExecutable(filePath) {
|
|
36213
|
+
let fd = null;
|
|
36214
|
+
try {
|
|
36215
|
+
fd = fs8.openSync(filePath, "r");
|
|
36216
|
+
const signature = Buffer.alloc(2);
|
|
36217
|
+
return fs8.readSync(fd, signature, 0, signature.length, 0) === signature.length && signature.toString("ascii") === "MZ";
|
|
36218
|
+
} catch {
|
|
36219
|
+
return false;
|
|
36220
|
+
} finally {
|
|
36221
|
+
if (fd !== null) fs8.closeSync(fd);
|
|
36222
|
+
}
|
|
36223
|
+
}
|
|
36224
|
+
function getWindowsClaudePackageBinaryPath(npmBinDir) {
|
|
36225
|
+
const binaryPath = path8.join(npmBinDir, "node_modules", "@anthropic-ai", "claude-code", "bin", "claude.exe");
|
|
36226
|
+
return isWindowsExecutable(binaryPath) ? binaryPath : null;
|
|
36227
|
+
}
|
|
36228
|
+
function getWindowsClaudeNativePath(npmBinDir) {
|
|
36229
|
+
const packageName = WINDOWS_CLAUDE_NATIVE_PACKAGES[process.arch];
|
|
36230
|
+
if (!packageName) return null;
|
|
36231
|
+
const nativePath = path8.join(npmBinDir, "node_modules", ...packageName.split("/"), "claude.exe");
|
|
36232
|
+
return isWindowsExecutable(nativePath) ? nativePath : null;
|
|
36233
|
+
}
|
|
36200
36234
|
function resolveClaudeInvocation() {
|
|
36201
36235
|
if (process.platform !== "win32") {
|
|
36202
36236
|
return { command: "claude", argsPrefix: [] };
|
|
36203
36237
|
}
|
|
36204
|
-
const pathEntries = (
|
|
36238
|
+
const pathEntries = getPathEntries();
|
|
36205
36239
|
for (const entry of pathEntries) {
|
|
36206
36240
|
const shimPath = path8.join(entry, "claude.cmd");
|
|
36207
36241
|
if (!fs8.existsSync(shimPath)) continue;
|
|
36242
|
+
const packageBinaryPath = getWindowsClaudePackageBinaryPath(entry);
|
|
36243
|
+
if (packageBinaryPath) {
|
|
36244
|
+
return { command: packageBinaryPath, argsPrefix: [] };
|
|
36245
|
+
}
|
|
36246
|
+
const nativePath = getWindowsClaudeNativePath(entry);
|
|
36247
|
+
if (nativePath) {
|
|
36248
|
+
return { command: nativePath, argsPrefix: [] };
|
|
36249
|
+
}
|
|
36208
36250
|
const cliPath = path8.join(entry, "node_modules", "@anthropic-ai", "claude-code", "cli.js");
|
|
36209
36251
|
if (fs8.existsSync(cliPath)) {
|
|
36210
36252
|
return {
|
|
@@ -36212,6 +36254,13 @@ function resolveClaudeInvocation() {
|
|
|
36212
36254
|
argsPrefix: [cliPath]
|
|
36213
36255
|
};
|
|
36214
36256
|
}
|
|
36257
|
+
const wrapperPath = path8.join(entry, "node_modules", "@anthropic-ai", "claude-code", "cli-wrapper.cjs");
|
|
36258
|
+
if (fs8.existsSync(wrapperPath)) {
|
|
36259
|
+
return {
|
|
36260
|
+
command: process.execPath,
|
|
36261
|
+
argsPrefix: [wrapperPath]
|
|
36262
|
+
};
|
|
36263
|
+
}
|
|
36215
36264
|
}
|
|
36216
36265
|
return { command: "claude", argsPrefix: [] };
|
|
36217
36266
|
}
|
|
@@ -36219,7 +36268,7 @@ function resolveCodexInvocation() {
|
|
|
36219
36268
|
if (process.platform !== "win32") {
|
|
36220
36269
|
return { command: "codex", argsPrefix: [] };
|
|
36221
36270
|
}
|
|
36222
|
-
const pathEntries = (
|
|
36271
|
+
const pathEntries = getPathEntries();
|
|
36223
36272
|
for (const entry of pathEntries) {
|
|
36224
36273
|
const shimPath = path8.join(entry, "codex.cmd");
|
|
36225
36274
|
if (!fs8.existsSync(shimPath)) continue;
|
|
@@ -37107,6 +37156,7 @@ var LEGACY_FILES = [
|
|
|
37107
37156
|
"nodes.json",
|
|
37108
37157
|
"tasks.json",
|
|
37109
37158
|
"shares.json",
|
|
37159
|
+
"node-operations.json",
|
|
37110
37160
|
"election.json"
|
|
37111
37161
|
];
|
|
37112
37162
|
var LEGACY_DIRS = ["logs", "task-logs"];
|
|
@@ -37471,6 +37521,12 @@ async function handleLocalNodeMessage(deps, message) {
|
|
|
37471
37521
|
error: error instanceof Error ? error.message : String(error)
|
|
37472
37522
|
});
|
|
37473
37523
|
}
|
|
37524
|
+
return;
|
|
37525
|
+
}
|
|
37526
|
+
if (message.kind === "task.delete") {
|
|
37527
|
+
const payload = message.payload;
|
|
37528
|
+
if (!payload.taskId) return;
|
|
37529
|
+
deps.taskEngine.deleteTask(payload.taskId);
|
|
37474
37530
|
}
|
|
37475
37531
|
}
|
|
37476
37532
|
|
|
@@ -39205,8 +39261,8 @@ function getErrorMap() {
|
|
|
39205
39261
|
|
|
39206
39262
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
39207
39263
|
var makeIssue = (params) => {
|
|
39208
|
-
const { data, path:
|
|
39209
|
-
const fullPath = [...
|
|
39264
|
+
const { data, path: path23, errorMaps, issueData } = params;
|
|
39265
|
+
const fullPath = [...path23, ...issueData.path || []];
|
|
39210
39266
|
const fullIssue = {
|
|
39211
39267
|
...issueData,
|
|
39212
39268
|
path: fullPath
|
|
@@ -39322,11 +39378,11 @@ var errorUtil;
|
|
|
39322
39378
|
|
|
39323
39379
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
39324
39380
|
var ParseInputLazyPath = class {
|
|
39325
|
-
constructor(parent, value,
|
|
39381
|
+
constructor(parent, value, path23, key) {
|
|
39326
39382
|
this._cachedPath = [];
|
|
39327
39383
|
this.parent = parent;
|
|
39328
39384
|
this.data = value;
|
|
39329
|
-
this._path =
|
|
39385
|
+
this._path = path23;
|
|
39330
39386
|
this._key = key;
|
|
39331
39387
|
}
|
|
39332
39388
|
get path() {
|
|
@@ -43219,16 +43275,17 @@ var TaskOutputContentQuery = external_exports.object({
|
|
|
43219
43275
|
});
|
|
43220
43276
|
var TaskOutputDownloadQuery = TaskOutputContentQuery;
|
|
43221
43277
|
var TaskPreviewSessionBody = external_exports.object({
|
|
43222
|
-
path: external_exports.string().min(1).optional()
|
|
43278
|
+
path: external_exports.string().min(1).optional(),
|
|
43279
|
+
port: external_exports.coerce.number().int().min(1).max(65535).optional()
|
|
43223
43280
|
});
|
|
43224
43281
|
var BatchTaskIdsBody = external_exports.object({
|
|
43225
43282
|
ids: external_exports.array(external_exports.string().min(1)).min(1).max(50)
|
|
43226
43283
|
});
|
|
43227
43284
|
|
|
43228
43285
|
// ../../packages/api/src/app/server.ts
|
|
43229
|
-
var
|
|
43230
|
-
var
|
|
43231
|
-
var
|
|
43286
|
+
var path20 = __toESM(require("path"), 1);
|
|
43287
|
+
var fs19 = __toESM(require("fs"), 1);
|
|
43288
|
+
var import_express14 = __toESM(require_express2(), 1);
|
|
43232
43289
|
|
|
43233
43290
|
// ../../packages/api/src/middleware/auth.ts
|
|
43234
43291
|
var SKIP_AUTH_PATHS = ["/api/system/health"];
|
|
@@ -43354,8 +43411,91 @@ function createAuthMiddleware(config) {
|
|
|
43354
43411
|
}
|
|
43355
43412
|
|
|
43356
43413
|
// ../../packages/api/src/middleware/routing.ts
|
|
43357
|
-
function
|
|
43358
|
-
return dataRouter
|
|
43414
|
+
function isRoutingMiddlewareDeps(input) {
|
|
43415
|
+
return "dataRouter" in input;
|
|
43416
|
+
}
|
|
43417
|
+
function decodePathSegment(value) {
|
|
43418
|
+
try {
|
|
43419
|
+
return decodeURIComponent(value);
|
|
43420
|
+
} catch {
|
|
43421
|
+
return value;
|
|
43422
|
+
}
|
|
43423
|
+
}
|
|
43424
|
+
function getSingleTaskDeleteId(path23) {
|
|
43425
|
+
const match = /^\/api\/tasks\/([^/]+)$/.exec(path23);
|
|
43426
|
+
return match ? decodePathSegment(match[1]) : null;
|
|
43427
|
+
}
|
|
43428
|
+
function getSuccessfulBatchDeleteIds(body) {
|
|
43429
|
+
if (!body || typeof body !== "object" || !Array.isArray(body.results)) {
|
|
43430
|
+
return [];
|
|
43431
|
+
}
|
|
43432
|
+
return body.results.flatMap((result) => {
|
|
43433
|
+
if (!result || typeof result !== "object") return [];
|
|
43434
|
+
const item = result;
|
|
43435
|
+
return item.ok === true && typeof item.id === "string" ? [item.id] : [];
|
|
43436
|
+
});
|
|
43437
|
+
}
|
|
43438
|
+
function getProxiedDeleteIds(req, result) {
|
|
43439
|
+
if (result.status < 200 || result.status >= 300) {
|
|
43440
|
+
return [];
|
|
43441
|
+
}
|
|
43442
|
+
const method = req.method.toUpperCase();
|
|
43443
|
+
if (method === "DELETE") {
|
|
43444
|
+
const taskId = getSingleTaskDeleteId(req.path);
|
|
43445
|
+
return taskId ? [taskId] : [];
|
|
43446
|
+
}
|
|
43447
|
+
if (method === "POST" && req.path === "/api/tasks/batch/delete") {
|
|
43448
|
+
return getSuccessfulBatchDeleteIds(result.body);
|
|
43449
|
+
}
|
|
43450
|
+
return [];
|
|
43451
|
+
}
|
|
43452
|
+
function evictLocalTaskMirrors(taskEngine, logger27, taskIds) {
|
|
43453
|
+
if (!taskEngine || taskIds.length === 0) return;
|
|
43454
|
+
for (const taskId of taskIds) {
|
|
43455
|
+
try {
|
|
43456
|
+
taskEngine.deleteTask(taskId);
|
|
43457
|
+
} catch (err) {
|
|
43458
|
+
logger27?.child("routing")?.warn("failed to evict follower-local task mirror after proxied delete", {
|
|
43459
|
+
taskId,
|
|
43460
|
+
error: err instanceof Error ? err.message : String(err)
|
|
43461
|
+
});
|
|
43462
|
+
}
|
|
43463
|
+
}
|
|
43464
|
+
}
|
|
43465
|
+
function createRoutingMiddleware(input) {
|
|
43466
|
+
const deps = isRoutingMiddlewareDeps(input) ? input : { dataRouter: input };
|
|
43467
|
+
const { dataRouter, taskEngine, logger: logger27 } = deps;
|
|
43468
|
+
return async (req, res, next) => {
|
|
43469
|
+
if (!dataRouter.shouldProxy(req.method, req.path)) {
|
|
43470
|
+
next();
|
|
43471
|
+
return;
|
|
43472
|
+
}
|
|
43473
|
+
const leaderEndpoint = dataRouter.getLeaderEndpoint();
|
|
43474
|
+
if (!leaderEndpoint) {
|
|
43475
|
+
res.status(503).json({
|
|
43476
|
+
error: { code: "NO_LEADER", message: "No leader available" }
|
|
43477
|
+
});
|
|
43478
|
+
return;
|
|
43479
|
+
}
|
|
43480
|
+
try {
|
|
43481
|
+
const result = await dataRouter.proxyToLeader(req);
|
|
43482
|
+
evictLocalTaskMirrors(taskEngine, logger27, getProxiedDeleteIds(req, result));
|
|
43483
|
+
for (const [key, value] of Object.entries(result.headers)) {
|
|
43484
|
+
res.setHeader(key, value);
|
|
43485
|
+
}
|
|
43486
|
+
res.status(result.status).json(result.body);
|
|
43487
|
+
} catch (err) {
|
|
43488
|
+
if (err instanceof MeshyError) {
|
|
43489
|
+
res.status(err.statusCode).json({
|
|
43490
|
+
error: { code: err.code, message: err.message }
|
|
43491
|
+
});
|
|
43492
|
+
return;
|
|
43493
|
+
}
|
|
43494
|
+
res.status(502).json({
|
|
43495
|
+
error: { code: "NODE_OFFLINE", message: "Leader unreachable" }
|
|
43496
|
+
});
|
|
43497
|
+
}
|
|
43498
|
+
};
|
|
43359
43499
|
}
|
|
43360
43500
|
|
|
43361
43501
|
// ../../packages/api/src/middleware/error.ts
|
|
@@ -43906,9 +44046,33 @@ function detectHtmlEntries(root) {
|
|
|
43906
44046
|
}
|
|
43907
44047
|
return entries;
|
|
43908
44048
|
}
|
|
44049
|
+
function detectMarkdownEntries(root) {
|
|
44050
|
+
const entries = [];
|
|
44051
|
+
try {
|
|
44052
|
+
const topLevel = fs14.readdirSync(root, { withFileTypes: true });
|
|
44053
|
+
for (const f of topLevel) {
|
|
44054
|
+
if (f.isFile() && !f.name.startsWith(".") && /\.mdx?$/i.test(f.name)) {
|
|
44055
|
+
entries.push({ path: f.name, label: f.name });
|
|
44056
|
+
}
|
|
44057
|
+
}
|
|
44058
|
+
const subdirs = topLevel.filter((e) => e.isDirectory() && !e.name.startsWith("."));
|
|
44059
|
+
for (const dir of subdirs) {
|
|
44060
|
+
for (const fileName of ["README.md", "readme.md"]) {
|
|
44061
|
+
const readmePath = path15.join(root, dir.name, fileName);
|
|
44062
|
+
if (fs14.existsSync(readmePath)) {
|
|
44063
|
+
entries.push({ path: `${dir.name}/${fileName}`, label: `${dir.name}/${fileName}` });
|
|
44064
|
+
break;
|
|
44065
|
+
}
|
|
44066
|
+
}
|
|
44067
|
+
}
|
|
44068
|
+
} catch {
|
|
44069
|
+
}
|
|
44070
|
+
return entries;
|
|
44071
|
+
}
|
|
43909
44072
|
function getOutputSummary(root) {
|
|
43910
44073
|
const rootName = path15.basename(root);
|
|
43911
44074
|
const htmlEntries = detectHtmlEntries(root);
|
|
44075
|
+
const markdownEntries = detectMarkdownEntries(root);
|
|
43912
44076
|
let fileCount;
|
|
43913
44077
|
try {
|
|
43914
44078
|
const entries = fs14.readdirSync(root, { withFileTypes: true });
|
|
@@ -43921,6 +44085,7 @@ function getOutputSummary(root) {
|
|
|
43921
44085
|
rootName,
|
|
43922
44086
|
fileCount,
|
|
43923
44087
|
htmlEntries,
|
|
44088
|
+
markdownEntries,
|
|
43924
44089
|
git: null
|
|
43925
44090
|
// filled in by Git diff API later
|
|
43926
44091
|
};
|
|
@@ -44295,6 +44460,577 @@ function computeParentPath(rootPath, currentPath, useAbsolute) {
|
|
|
44295
44460
|
return segments.length === 0 ? "." : segments.join("/");
|
|
44296
44461
|
}
|
|
44297
44462
|
|
|
44463
|
+
// ../../packages/api/src/node/node-operation-service.ts
|
|
44464
|
+
var fs15 = __toESM(require("fs"), 1);
|
|
44465
|
+
var path17 = __toESM(require("path"), 1);
|
|
44466
|
+
var import_node_crypto7 = require("crypto");
|
|
44467
|
+
|
|
44468
|
+
// ../../packages/api/src/node/agent-upgrade-service.ts
|
|
44469
|
+
var import_node_child_process9 = require("child_process");
|
|
44470
|
+
|
|
44471
|
+
// ../../packages/api/src/app/system-info.ts
|
|
44472
|
+
var os6 = __toESM(require("os"), 1);
|
|
44473
|
+
var import_node_child_process8 = require("child_process");
|
|
44474
|
+
var RUNTIME_TOOLS = [
|
|
44475
|
+
{ id: "claude", label: "Claude Code", command: "claude", packageName: "@anthropic-ai/claude-code" },
|
|
44476
|
+
{ id: "codex", label: "Codex", command: "codex", packageName: "@openai/codex" }
|
|
44477
|
+
];
|
|
44478
|
+
var runtimeToolUpdateCache = /* @__PURE__ */ new Map();
|
|
44479
|
+
function clearRuntimeToolUpdateCache(packageName) {
|
|
44480
|
+
if (packageName) {
|
|
44481
|
+
runtimeToolUpdateCache.delete(packageName);
|
|
44482
|
+
return;
|
|
44483
|
+
}
|
|
44484
|
+
runtimeToolUpdateCache.clear();
|
|
44485
|
+
}
|
|
44486
|
+
function runRuntimeToolCommand(command, args, platform2) {
|
|
44487
|
+
const result = (0, import_node_child_process8.spawnSync)(command, args, {
|
|
44488
|
+
encoding: "utf-8",
|
|
44489
|
+
shell: platform2 === "win32" && command !== "where",
|
|
44490
|
+
windowsHide: true,
|
|
44491
|
+
timeout: 2500
|
|
44492
|
+
});
|
|
44493
|
+
return {
|
|
44494
|
+
status: result.status,
|
|
44495
|
+
stdout: typeof result.stdout === "string" ? result.stdout : "",
|
|
44496
|
+
stderr: typeof result.stderr === "string" ? result.stderr : "",
|
|
44497
|
+
error: result.error?.message ?? null
|
|
44498
|
+
};
|
|
44499
|
+
}
|
|
44500
|
+
function normalizeOutput(output) {
|
|
44501
|
+
if (!output) {
|
|
44502
|
+
return null;
|
|
44503
|
+
}
|
|
44504
|
+
const firstLine = output.split(/\r?\n/).map((line) => line.trim()).find(Boolean);
|
|
44505
|
+
return firstLine ?? null;
|
|
44506
|
+
}
|
|
44507
|
+
function formatLocalDate(date) {
|
|
44508
|
+
const year = date.getFullYear();
|
|
44509
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
44510
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
44511
|
+
return `${year}-${month}-${day}`;
|
|
44512
|
+
}
|
|
44513
|
+
function resolveCommandPath(command, commandRunner, platform2) {
|
|
44514
|
+
const lookupCommand = platform2 === "win32" ? "where" : "which";
|
|
44515
|
+
const result = commandRunner(lookupCommand, [command]);
|
|
44516
|
+
if (result.status === 0) {
|
|
44517
|
+
return { path: normalizeOutput(result.stdout) };
|
|
44518
|
+
}
|
|
44519
|
+
return {
|
|
44520
|
+
path: null,
|
|
44521
|
+
detail: normalizeOutput(result.stderr) ?? result.error ?? null
|
|
44522
|
+
};
|
|
44523
|
+
}
|
|
44524
|
+
function extractSemver(value) {
|
|
44525
|
+
return value?.match(/\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?/)?.[0] ?? null;
|
|
44526
|
+
}
|
|
44527
|
+
function normalizePackageVersion(output) {
|
|
44528
|
+
if (!output) return null;
|
|
44529
|
+
const trimmed = output.trim();
|
|
44530
|
+
try {
|
|
44531
|
+
const parsed = JSON.parse(trimmed);
|
|
44532
|
+
if (typeof parsed === "string") {
|
|
44533
|
+
return parsed.trim() || null;
|
|
44534
|
+
}
|
|
44535
|
+
} catch {
|
|
44536
|
+
}
|
|
44537
|
+
return normalizeOutput(trimmed);
|
|
44538
|
+
}
|
|
44539
|
+
function normalizeInstalledPackageVersion(output, packageName) {
|
|
44540
|
+
if (!output) return null;
|
|
44541
|
+
const trimmed = output.trim();
|
|
44542
|
+
try {
|
|
44543
|
+
const parsed = JSON.parse(trimmed);
|
|
44544
|
+
const version2 = parsed.dependencies?.[packageName]?.version;
|
|
44545
|
+
if (typeof version2 === "string") {
|
|
44546
|
+
return version2.trim() || null;
|
|
44547
|
+
}
|
|
44548
|
+
} catch {
|
|
44549
|
+
}
|
|
44550
|
+
return extractSemver(normalizeOutput(trimmed));
|
|
44551
|
+
}
|
|
44552
|
+
function resolveInstalledPackageVersion(definition, commandRunner) {
|
|
44553
|
+
const result = commandRunner("npm", ["list", "-g", definition.packageName, "--depth=0", "--json"]);
|
|
44554
|
+
return normalizeInstalledPackageVersion(result.stdout ?? null, definition.packageName);
|
|
44555
|
+
}
|
|
44556
|
+
function compareSemver(left, right) {
|
|
44557
|
+
const leftParts = left.split(/[.-]/).map((part) => Number.parseInt(part, 10));
|
|
44558
|
+
const rightParts = right.split(/[.-]/).map((part) => Number.parseInt(part, 10));
|
|
44559
|
+
for (let index = 0; index < 3; index += 1) {
|
|
44560
|
+
const delta = (leftParts[index] || 0) - (rightParts[index] || 0);
|
|
44561
|
+
if (delta !== 0) return delta;
|
|
44562
|
+
}
|
|
44563
|
+
return 0;
|
|
44564
|
+
}
|
|
44565
|
+
function checkToolUpdate(definition, installedVersion, checkedAt, commandRunner, checkedOn, updateCache) {
|
|
44566
|
+
const currentVersion = extractSemver(installedVersion);
|
|
44567
|
+
const cached = updateCache.get(definition.packageName);
|
|
44568
|
+
let latestVersion = cached?.latestVersion ?? null;
|
|
44569
|
+
let detail = cached?.detail ?? null;
|
|
44570
|
+
let updateCheckedAt = cached?.checkedAt ?? checkedAt;
|
|
44571
|
+
if (cached?.checkedOn !== checkedOn) {
|
|
44572
|
+
const latestResult = commandRunner("npm", ["view", definition.packageName, "version", "--json"]);
|
|
44573
|
+
latestVersion = latestResult.status === 0 ? normalizePackageVersion(latestResult.stdout ?? null) : null;
|
|
44574
|
+
detail = latestResult.status === 0 ? null : normalizeOutput(latestResult.stderr) ?? latestResult.error ?? "Update check failed";
|
|
44575
|
+
updateCheckedAt = checkedAt;
|
|
44576
|
+
updateCache.set(definition.packageName, {
|
|
44577
|
+
checkedOn,
|
|
44578
|
+
checkedAt,
|
|
44579
|
+
latestVersion,
|
|
44580
|
+
detail
|
|
44581
|
+
});
|
|
44582
|
+
}
|
|
44583
|
+
return {
|
|
44584
|
+
packageName: definition.packageName,
|
|
44585
|
+
currentVersion,
|
|
44586
|
+
latestVersion,
|
|
44587
|
+
updateAvailable: Boolean(currentVersion && latestVersion && compareSemver(latestVersion, currentVersion) > 0),
|
|
44588
|
+
checkedAt: updateCheckedAt,
|
|
44589
|
+
detail
|
|
44590
|
+
};
|
|
44591
|
+
}
|
|
44592
|
+
function inspectTool(definition, commandRunner, checkedAt, checkedOn, updateCache, platform2) {
|
|
44593
|
+
const resolved = resolveCommandPath(definition.command, commandRunner, platform2);
|
|
44594
|
+
if (!resolved.path) {
|
|
44595
|
+
return {
|
|
44596
|
+
id: definition.id,
|
|
44597
|
+
label: definition.label,
|
|
44598
|
+
command: definition.command,
|
|
44599
|
+
available: false,
|
|
44600
|
+
path: null,
|
|
44601
|
+
version: null,
|
|
44602
|
+
checkedAt,
|
|
44603
|
+
detail: resolved.detail ?? "Command not found on PATH",
|
|
44604
|
+
update: checkToolUpdate(definition, null, checkedAt, commandRunner, checkedOn, updateCache)
|
|
44605
|
+
};
|
|
44606
|
+
}
|
|
44607
|
+
const versionResult = commandRunner(definition.command, ["--version"]);
|
|
44608
|
+
const commandVersion = normalizeOutput(versionResult.stdout) ?? normalizeOutput(versionResult.stderr);
|
|
44609
|
+
const version2 = extractSemver(commandVersion) ? commandVersion : resolveInstalledPackageVersion(definition, commandRunner);
|
|
44610
|
+
const detail = versionResult.status === 0 ? null : normalizeOutput(versionResult.stderr) ?? versionResult.error ?? "Version check failed";
|
|
44611
|
+
return {
|
|
44612
|
+
id: definition.id,
|
|
44613
|
+
label: definition.label,
|
|
44614
|
+
command: definition.command,
|
|
44615
|
+
available: true,
|
|
44616
|
+
path: resolved.path,
|
|
44617
|
+
version: version2,
|
|
44618
|
+
checkedAt,
|
|
44619
|
+
detail,
|
|
44620
|
+
update: checkToolUpdate(definition, version2, checkedAt, commandRunner, checkedOn, updateCache)
|
|
44621
|
+
};
|
|
44622
|
+
}
|
|
44623
|
+
function inspectRuntimeTools(options = {}) {
|
|
44624
|
+
const platform2 = options.platform ?? process.platform;
|
|
44625
|
+
const commandRunner = options.commandRunner ?? ((command, args) => runRuntimeToolCommand(command, args, platform2));
|
|
44626
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
44627
|
+
const checkedAt = now.toISOString();
|
|
44628
|
+
const checkedOn = formatLocalDate(now);
|
|
44629
|
+
const updateCache = options.updateCache ?? runtimeToolUpdateCache;
|
|
44630
|
+
return RUNTIME_TOOLS.map((definition) => inspectTool(definition, commandRunner, checkedAt, checkedOn, updateCache, platform2));
|
|
44631
|
+
}
|
|
44632
|
+
function getOsSnapshot() {
|
|
44633
|
+
const cpus2 = os6.cpus();
|
|
44634
|
+
return {
|
|
44635
|
+
platform: os6.platform(),
|
|
44636
|
+
release: os6.release(),
|
|
44637
|
+
arch: os6.arch(),
|
|
44638
|
+
hostname: os6.hostname(),
|
|
44639
|
+
cpuModel: cpus2[0]?.model ?? null,
|
|
44640
|
+
cpuCount: cpus2.length,
|
|
44641
|
+
totalMemoryBytes: os6.totalmem(),
|
|
44642
|
+
freeMemoryBytes: os6.freemem()
|
|
44643
|
+
};
|
|
44644
|
+
}
|
|
44645
|
+
function buildNodeSettingsSnapshot(options) {
|
|
44646
|
+
const uptime = process.uptime();
|
|
44647
|
+
const runtimeMetadata = options.runtimeMetadata;
|
|
44648
|
+
const agents = (options.inspectRuntimeTools?.() ?? inspectRuntimeTools()).map((agent) => ({
|
|
44649
|
+
...agent,
|
|
44650
|
+
metadataStatus: runtimeMetadata?.components?.[agent.id]?.status ?? null
|
|
44651
|
+
}));
|
|
44652
|
+
return {
|
|
44653
|
+
collectedAt: Date.now(),
|
|
44654
|
+
version: runtimeMetadata?.packageVersion ?? "0.1.0",
|
|
44655
|
+
packageName: runtimeMetadata?.packageName ?? "meshy",
|
|
44656
|
+
uptime,
|
|
44657
|
+
auth: options.auth,
|
|
44658
|
+
os: getOsSnapshot(),
|
|
44659
|
+
runtime: {
|
|
44660
|
+
nodeVersion: process.version,
|
|
44661
|
+
pid: process.pid,
|
|
44662
|
+
startedAt: Date.now() - Math.floor(uptime * 1e3),
|
|
44663
|
+
cwd: process.cwd(),
|
|
44664
|
+
workDir: options.workDir ?? null,
|
|
44665
|
+
storagePath: options.storagePath ?? null,
|
|
44666
|
+
localDashboardOrigin: options.localDashboardOrigin ?? null
|
|
44667
|
+
},
|
|
44668
|
+
agents,
|
|
44669
|
+
startupRequirements: {
|
|
44670
|
+
lastCheckedAt: runtimeMetadata?.startupRequirementsLastCheckedAt,
|
|
44671
|
+
lastCheckedOn: runtimeMetadata?.startupRequirementsLastCheckedOn,
|
|
44672
|
+
components: runtimeMetadata?.components ?? {}
|
|
44673
|
+
},
|
|
44674
|
+
components: runtimeMetadata?.components ?? {},
|
|
44675
|
+
repository: runtimeMetadata?.repository ?? {},
|
|
44676
|
+
packages: runtimeMetadata?.packages ?? {}
|
|
44677
|
+
};
|
|
44678
|
+
}
|
|
44679
|
+
|
|
44680
|
+
// ../../packages/api/src/node/agent-upgrade-service.ts
|
|
44681
|
+
var AGENT_PACKAGES = {
|
|
44682
|
+
claude: "@anthropic-ai/claude-code",
|
|
44683
|
+
codex: "@openai/codex"
|
|
44684
|
+
};
|
|
44685
|
+
var OUTPUT_LIMIT = 4e3;
|
|
44686
|
+
function summarizeOutput(value) {
|
|
44687
|
+
const text = value ?? "";
|
|
44688
|
+
return text.length > OUTPUT_LIMIT ? `${text.slice(0, OUTPUT_LIMIT)}\u2026` : text;
|
|
44689
|
+
}
|
|
44690
|
+
function defaultCommandRunner(command, args) {
|
|
44691
|
+
const result = (0, import_node_child_process9.spawnSync)(command, args, {
|
|
44692
|
+
encoding: "utf-8",
|
|
44693
|
+
shell: process.platform === "win32",
|
|
44694
|
+
windowsHide: true,
|
|
44695
|
+
timeout: 18e4
|
|
44696
|
+
});
|
|
44697
|
+
return {
|
|
44698
|
+
status: result.status,
|
|
44699
|
+
stdout: typeof result.stdout === "string" ? result.stdout : "",
|
|
44700
|
+
stderr: typeof result.stderr === "string" ? result.stderr : "",
|
|
44701
|
+
error: result.error?.message ?? null
|
|
44702
|
+
};
|
|
44703
|
+
}
|
|
44704
|
+
function isRuntimeAgentId(value) {
|
|
44705
|
+
return value === "claude" || value === "codex";
|
|
44706
|
+
}
|
|
44707
|
+
function buildUpgradeArgs(agent, packageName) {
|
|
44708
|
+
const args = ["install", "-g", `${packageName}@latest`];
|
|
44709
|
+
if (agent === "claude") {
|
|
44710
|
+
args.push("--include=optional", "--ignore-scripts=false");
|
|
44711
|
+
}
|
|
44712
|
+
return args;
|
|
44713
|
+
}
|
|
44714
|
+
function upgradeRuntimeAgent(agent, options = {}) {
|
|
44715
|
+
const packageName = AGENT_PACKAGES[agent];
|
|
44716
|
+
if (!packageName) {
|
|
44717
|
+
throw new MeshyError("VALIDATION_ERROR", `Unsupported upgrade agent: ${agent}`, 400);
|
|
44718
|
+
}
|
|
44719
|
+
const command = "npm";
|
|
44720
|
+
const args = buildUpgradeArgs(agent, packageName);
|
|
44721
|
+
const result = (options.commandRunner ?? defaultCommandRunner)(command, args);
|
|
44722
|
+
const ok = result.status === 0 && !result.error;
|
|
44723
|
+
if (ok) {
|
|
44724
|
+
clearRuntimeToolUpdateCache(packageName);
|
|
44725
|
+
}
|
|
44726
|
+
const detail = result.error ?? (summarizeOutput(result.stderr) || "Agent upgrade failed");
|
|
44727
|
+
return {
|
|
44728
|
+
ok,
|
|
44729
|
+
agent,
|
|
44730
|
+
packageName,
|
|
44731
|
+
command,
|
|
44732
|
+
args,
|
|
44733
|
+
status: result.status,
|
|
44734
|
+
stdout: summarizeOutput(result.stdout),
|
|
44735
|
+
stderr: summarizeOutput(result.stderr),
|
|
44736
|
+
detail: ok ? null : detail
|
|
44737
|
+
};
|
|
44738
|
+
}
|
|
44739
|
+
function upgradeRuntimeAgentForDeps(deps, agent) {
|
|
44740
|
+
const result = deps.upgradeRuntimeAgent?.(agent) ?? upgradeRuntimeAgent(agent);
|
|
44741
|
+
if (result.ok) {
|
|
44742
|
+
const settingsSnapshot = deps.refreshSettingsSnapshot?.();
|
|
44743
|
+
if (settingsSnapshot) {
|
|
44744
|
+
deps.nodeRegistry.updateSettingsSnapshot(deps.nodeRegistry.getSelf().id, settingsSnapshot);
|
|
44745
|
+
return { ...result, settingsSnapshot };
|
|
44746
|
+
}
|
|
44747
|
+
}
|
|
44748
|
+
return result;
|
|
44749
|
+
}
|
|
44750
|
+
|
|
44751
|
+
// ../../packages/api/src/node/node-operation-service.ts
|
|
44752
|
+
var NodeOperationFailure = class extends Error {
|
|
44753
|
+
constructor(message, result) {
|
|
44754
|
+
super(message);
|
|
44755
|
+
this.result = result;
|
|
44756
|
+
}
|
|
44757
|
+
};
|
|
44758
|
+
var InMemoryNodeOperationStore = class {
|
|
44759
|
+
operations = /* @__PURE__ */ new Map();
|
|
44760
|
+
get(id) {
|
|
44761
|
+
const operation = this.operations.get(id);
|
|
44762
|
+
return operation ? clone2(operation) : null;
|
|
44763
|
+
}
|
|
44764
|
+
list(filter = {}) {
|
|
44765
|
+
return Array.from(this.operations.values()).filter((operation) => matchesFilter(operation, filter)).sort((a, b) => b.createdAt - a.createdAt).map((operation) => clone2(operation));
|
|
44766
|
+
}
|
|
44767
|
+
upsert(operation) {
|
|
44768
|
+
const copy = clone2(operation);
|
|
44769
|
+
this.operations.set(copy.id, copy);
|
|
44770
|
+
return clone2(copy);
|
|
44771
|
+
}
|
|
44772
|
+
update(id, updates) {
|
|
44773
|
+
const current = this.operations.get(id);
|
|
44774
|
+
if (!current) return null;
|
|
44775
|
+
const next = { ...current, ...clone2(updates), id, createdAt: current.createdAt };
|
|
44776
|
+
this.operations.set(id, next);
|
|
44777
|
+
return clone2(next);
|
|
44778
|
+
}
|
|
44779
|
+
};
|
|
44780
|
+
var FileNodeOperationStore = class {
|
|
44781
|
+
constructor(storagePath) {
|
|
44782
|
+
this.storagePath = storagePath;
|
|
44783
|
+
}
|
|
44784
|
+
operations = /* @__PURE__ */ new Map();
|
|
44785
|
+
loaded = false;
|
|
44786
|
+
get(id) {
|
|
44787
|
+
this.load();
|
|
44788
|
+
const operation = this.operations.get(id);
|
|
44789
|
+
return operation ? clone2(operation) : null;
|
|
44790
|
+
}
|
|
44791
|
+
list(filter = {}) {
|
|
44792
|
+
this.load();
|
|
44793
|
+
return Array.from(this.operations.values()).filter((operation) => matchesFilter(operation, filter)).sort((a, b) => b.createdAt - a.createdAt).map((operation) => clone2(operation));
|
|
44794
|
+
}
|
|
44795
|
+
upsert(operation) {
|
|
44796
|
+
this.load();
|
|
44797
|
+
const copy = clone2(operation);
|
|
44798
|
+
this.operations.set(copy.id, copy);
|
|
44799
|
+
this.persist();
|
|
44800
|
+
return clone2(copy);
|
|
44801
|
+
}
|
|
44802
|
+
update(id, updates) {
|
|
44803
|
+
this.load();
|
|
44804
|
+
const current = this.operations.get(id);
|
|
44805
|
+
if (!current) return null;
|
|
44806
|
+
const next = { ...current, ...clone2(updates), id, createdAt: current.createdAt };
|
|
44807
|
+
this.operations.set(id, next);
|
|
44808
|
+
this.persist();
|
|
44809
|
+
return clone2(next);
|
|
44810
|
+
}
|
|
44811
|
+
load() {
|
|
44812
|
+
if (this.loaded) return;
|
|
44813
|
+
this.loaded = true;
|
|
44814
|
+
if (!fs15.existsSync(this.filePath)) return;
|
|
44815
|
+
const raw = JSON.parse(fs15.readFileSync(this.filePath, "utf-8"));
|
|
44816
|
+
const entries = Array.isArray(raw) ? raw : Object.values(raw);
|
|
44817
|
+
for (const entry of entries) {
|
|
44818
|
+
if (isNodeOperation(entry)) {
|
|
44819
|
+
this.operations.set(entry.id, clone2(entry));
|
|
44820
|
+
}
|
|
44821
|
+
}
|
|
44822
|
+
}
|
|
44823
|
+
persist() {
|
|
44824
|
+
fs15.mkdirSync(this.storagePath, { recursive: true });
|
|
44825
|
+
const body = JSON.stringify(Object.fromEntries(this.operations), null, 2);
|
|
44826
|
+
const tmpPath = `${this.filePath}.tmp`;
|
|
44827
|
+
fs15.writeFileSync(tmpPath, body, "utf-8");
|
|
44828
|
+
fs15.renameSync(tmpPath, this.filePath);
|
|
44829
|
+
}
|
|
44830
|
+
get filePath() {
|
|
44831
|
+
return path17.join(this.storagePath, "node-operations.json");
|
|
44832
|
+
}
|
|
44833
|
+
};
|
|
44834
|
+
var NodeOperationService = class {
|
|
44835
|
+
constructor(deps, store) {
|
|
44836
|
+
this.deps = deps;
|
|
44837
|
+
this.store = store;
|
|
44838
|
+
this.registerHandler("agent.upgrade", runAgentUpgradeOperation);
|
|
44839
|
+
this.registerHandler("workdir.branch-create", runWorkDirBranchCreateOperation);
|
|
44840
|
+
}
|
|
44841
|
+
handlers = /* @__PURE__ */ new Map();
|
|
44842
|
+
registerHandler(kind, handler) {
|
|
44843
|
+
this.handlers.set(kind, handler);
|
|
44844
|
+
}
|
|
44845
|
+
create(kind, nodeId, payload) {
|
|
44846
|
+
const now = Date.now();
|
|
44847
|
+
const operation = {
|
|
44848
|
+
id: (0, import_node_crypto7.randomUUID)(),
|
|
44849
|
+
kind,
|
|
44850
|
+
nodeId,
|
|
44851
|
+
requestedByNodeId: this.deps.nodeRegistry.getSelf().id,
|
|
44852
|
+
status: "queued",
|
|
44853
|
+
payload,
|
|
44854
|
+
createdAt: now,
|
|
44855
|
+
updatedAt: now
|
|
44856
|
+
};
|
|
44857
|
+
const saved = this.store.upsert(operation);
|
|
44858
|
+
this.deps.eventBus.emit("node.operation.created", { operation: saved });
|
|
44859
|
+
return saved;
|
|
44860
|
+
}
|
|
44861
|
+
get(id) {
|
|
44862
|
+
return this.store.get(id);
|
|
44863
|
+
}
|
|
44864
|
+
list(filter) {
|
|
44865
|
+
return this.store.list(filter);
|
|
44866
|
+
}
|
|
44867
|
+
accept(operation) {
|
|
44868
|
+
const current = this.store.get(operation.id);
|
|
44869
|
+
if (current) {
|
|
44870
|
+
if (current.status === "queued") this.scheduleRun(current.id);
|
|
44871
|
+
return current;
|
|
44872
|
+
}
|
|
44873
|
+
const saved = this.store.upsert({ ...operation, status: "queued", updatedAt: Date.now() });
|
|
44874
|
+
this.deps.eventBus.emit("node.operation.created", { operation: saved });
|
|
44875
|
+
this.scheduleRun(saved.id);
|
|
44876
|
+
return saved;
|
|
44877
|
+
}
|
|
44878
|
+
runLocal(id) {
|
|
44879
|
+
this.scheduleRun(id);
|
|
44880
|
+
}
|
|
44881
|
+
applyRemoteUpdate(operation) {
|
|
44882
|
+
const current = this.store.get(operation.id);
|
|
44883
|
+
const saved = this.store.upsert(current ? { ...current, ...operation } : operation);
|
|
44884
|
+
this.applyOperationSideEffects(saved);
|
|
44885
|
+
this.deps.eventBus.emit("node.operation.updated", { operation: saved });
|
|
44886
|
+
return saved;
|
|
44887
|
+
}
|
|
44888
|
+
markFailed(id, error) {
|
|
44889
|
+
return this.update(id, {
|
|
44890
|
+
status: "failed",
|
|
44891
|
+
error,
|
|
44892
|
+
completedAt: Date.now()
|
|
44893
|
+
});
|
|
44894
|
+
}
|
|
44895
|
+
scheduleRun(id) {
|
|
44896
|
+
setTimeout(() => {
|
|
44897
|
+
void this.run(id);
|
|
44898
|
+
}, 0);
|
|
44899
|
+
}
|
|
44900
|
+
async run(id) {
|
|
44901
|
+
const operation = this.store.get(id);
|
|
44902
|
+
if (!operation || operation.status !== "queued") return;
|
|
44903
|
+
const running = this.update(id, { status: "running", startedAt: Date.now() });
|
|
44904
|
+
if (!running) return;
|
|
44905
|
+
try {
|
|
44906
|
+
const handler = this.handlers.get(running.kind);
|
|
44907
|
+
if (!handler) throw new Error(`No node operation handler registered for kind: ${running.kind}`);
|
|
44908
|
+
const result = await handler(running, this.deps);
|
|
44909
|
+
this.update(id, { status: "succeeded", result, completedAt: Date.now() });
|
|
44910
|
+
} catch (err) {
|
|
44911
|
+
this.update(id, {
|
|
44912
|
+
status: "failed",
|
|
44913
|
+
result: err instanceof NodeOperationFailure ? err.result : void 0,
|
|
44914
|
+
error: err instanceof Error ? err.message : String(err),
|
|
44915
|
+
completedAt: Date.now()
|
|
44916
|
+
});
|
|
44917
|
+
}
|
|
44918
|
+
}
|
|
44919
|
+
update(id, updates) {
|
|
44920
|
+
const saved = this.store.update(id, { ...updates, updatedAt: Date.now() });
|
|
44921
|
+
if (!saved) return null;
|
|
44922
|
+
this.applyOperationSideEffects(saved);
|
|
44923
|
+
this.deps.eventBus.emit("node.operation.updated", { operation: saved });
|
|
44924
|
+
void this.reportToLeader(saved);
|
|
44925
|
+
return saved;
|
|
44926
|
+
}
|
|
44927
|
+
applyOperationSideEffects(operation) {
|
|
44928
|
+
if (operation.kind !== "agent.upgrade" || operation.status !== "succeeded") return;
|
|
44929
|
+
const settingsSnapshot = readSettingsSnapshot(operation.result);
|
|
44930
|
+
if (settingsSnapshot) {
|
|
44931
|
+
this.deps.nodeRegistry.updateSettingsSnapshot(operation.nodeId, settingsSnapshot);
|
|
44932
|
+
}
|
|
44933
|
+
}
|
|
44934
|
+
async reportToLeader(operation) {
|
|
44935
|
+
if (this.deps.nodeRegistry.isLeader()) return;
|
|
44936
|
+
const leaderEndpoint = this.deps.nodeRegistry.getLeaderEndpoint?.();
|
|
44937
|
+
if (!leaderEndpoint) return;
|
|
44938
|
+
try {
|
|
44939
|
+
await fetch(`${leaderEndpoint}/api/worker/node-operations/${operation.id}`, applyRequestAuthHeaders({
|
|
44940
|
+
method: "POST",
|
|
44941
|
+
headers: { "Content-Type": "application/json" },
|
|
44942
|
+
body: JSON.stringify(operation)
|
|
44943
|
+
}));
|
|
44944
|
+
} catch (err) {
|
|
44945
|
+
this.deps.logger.child("node-operation").warn("failed to report node operation update to leader", {
|
|
44946
|
+
operationId: operation.id,
|
|
44947
|
+
kind: operation.kind,
|
|
44948
|
+
error: err instanceof Error ? err.message : String(err)
|
|
44949
|
+
});
|
|
44950
|
+
}
|
|
44951
|
+
}
|
|
44952
|
+
};
|
|
44953
|
+
function getNodeOperationService(deps) {
|
|
44954
|
+
if (deps.nodeOperationService) return deps.nodeOperationService;
|
|
44955
|
+
const store = deps.nodeOperationStore ?? (deps.storagePath ? new FileNodeOperationStore(deps.storagePath) : new InMemoryNodeOperationStore());
|
|
44956
|
+
const service = new NodeOperationService(deps, store);
|
|
44957
|
+
deps.nodeOperationStore = store;
|
|
44958
|
+
deps.nodeOperationService = service;
|
|
44959
|
+
return service;
|
|
44960
|
+
}
|
|
44961
|
+
async function dispatchNodeOperation(deps, operation, node) {
|
|
44962
|
+
const message = createNodeMessage("node.operation.execute", { operation });
|
|
44963
|
+
const heartbeat = deps.heartbeat;
|
|
44964
|
+
if (heartbeat.canPushToNode?.(node.id) === false) {
|
|
44965
|
+
if (!heartbeat.enqueueNodeMessage) throw new Error(`Cannot queue node operation for ${node.id}`);
|
|
44966
|
+
heartbeat.enqueueNodeMessage(node.id, message);
|
|
44967
|
+
return;
|
|
44968
|
+
}
|
|
44969
|
+
const client = new NodeMessageClient({
|
|
44970
|
+
heartbeat: heartbeat.enqueueNodeMessage ? { enqueueNodeMessage: heartbeat.enqueueNodeMessage.bind(heartbeat) } : void 0,
|
|
44971
|
+
logger: deps.logger
|
|
44972
|
+
});
|
|
44973
|
+
await client.send(node, message);
|
|
44974
|
+
}
|
|
44975
|
+
function runAgentUpgradeOperation(operation, deps) {
|
|
44976
|
+
const agent = readPayloadString(operation, "agent");
|
|
44977
|
+
if (!isRuntimeAgentId(agent)) throw new Error(`Unsupported upgrade agent: ${agent}`);
|
|
44978
|
+
const result = upgradeRuntimeAgentForDeps(deps, agent);
|
|
44979
|
+
if (!result.ok) {
|
|
44980
|
+
throw new NodeOperationFailure(result.detail ?? `${agent} upgrade failed`, result);
|
|
44981
|
+
}
|
|
44982
|
+
return result;
|
|
44983
|
+
}
|
|
44984
|
+
function runWorkDirBranchCreateOperation(operation, deps) {
|
|
44985
|
+
const self2 = deps.nodeRegistry.getSelf();
|
|
44986
|
+
return createLocalNodeWorkDirBranch(
|
|
44987
|
+
self2.id,
|
|
44988
|
+
self2.workDir ?? deps.workDir,
|
|
44989
|
+
readPayloadString(operation, "path") || ".",
|
|
44990
|
+
{
|
|
44991
|
+
branchName: readPayloadString(operation, "branchName"),
|
|
44992
|
+
startPoint: readPayloadString(operation, "startPoint"),
|
|
44993
|
+
limit: readPayloadNumber(operation, "limit", 20),
|
|
44994
|
+
offset: readPayloadNumber(operation, "offset", 0),
|
|
44995
|
+
allowAbsolute: readPayloadBoolean(operation, "allowAbsolute", true)
|
|
44996
|
+
}
|
|
44997
|
+
);
|
|
44998
|
+
}
|
|
44999
|
+
function readPayloadString(operation, key) {
|
|
45000
|
+
const payload = operation.payload;
|
|
45001
|
+
if (!payload || typeof payload !== "object") return "";
|
|
45002
|
+
const value = payload[key];
|
|
45003
|
+
return typeof value === "string" ? value : "";
|
|
45004
|
+
}
|
|
45005
|
+
function readPayloadNumber(operation, key, fallback) {
|
|
45006
|
+
const payload = operation.payload;
|
|
45007
|
+
if (!payload || typeof payload !== "object") return fallback;
|
|
45008
|
+
const value = payload[key];
|
|
45009
|
+
return typeof value === "number" ? value : fallback;
|
|
45010
|
+
}
|
|
45011
|
+
function readPayloadBoolean(operation, key, fallback) {
|
|
45012
|
+
const payload = operation.payload;
|
|
45013
|
+
if (!payload || typeof payload !== "object") return fallback;
|
|
45014
|
+
const value = payload[key];
|
|
45015
|
+
return typeof value === "boolean" ? value : fallback;
|
|
45016
|
+
}
|
|
45017
|
+
function readSettingsSnapshot(value) {
|
|
45018
|
+
if (!value || typeof value !== "object") return void 0;
|
|
45019
|
+
const snapshot = value.settingsSnapshot;
|
|
45020
|
+
return snapshot && typeof snapshot === "object" ? snapshot : void 0;
|
|
45021
|
+
}
|
|
45022
|
+
function matchesFilter(operation, filter) {
|
|
45023
|
+
return (!filter.nodeId || operation.nodeId === filter.nodeId) && (!filter.status || operation.status === filter.status) && (!filter.kind || operation.kind === filter.kind);
|
|
45024
|
+
}
|
|
45025
|
+
function isNodeOperation(value) {
|
|
45026
|
+
if (!value || typeof value !== "object") return false;
|
|
45027
|
+
const record = value;
|
|
45028
|
+
return typeof record.id === "string" && typeof record.kind === "string" && typeof record.nodeId === "string" && typeof record.status === "string" && typeof record.createdAt === "number" && typeof record.updatedAt === "number";
|
|
45029
|
+
}
|
|
45030
|
+
function clone2(value) {
|
|
45031
|
+
return JSON.parse(JSON.stringify(value));
|
|
45032
|
+
}
|
|
45033
|
+
|
|
44298
45034
|
// ../../packages/api/src/routes/node-workdir.ts
|
|
44299
45035
|
function sendLocalNodeWorkDirTree(req, res, nodeId, options = {}) {
|
|
44300
45036
|
const query = NodeWorkDirTreeQuery.parse(req.query);
|
|
@@ -44366,29 +45102,45 @@ function sendLocalNodeWorkDirBranchInfo(req, res, nodeId, options = {}) {
|
|
|
44366
45102
|
}
|
|
44367
45103
|
));
|
|
44368
45104
|
}
|
|
44369
|
-
function
|
|
45105
|
+
async function sendNodeWorkDirBranchCreateOperation(req, res, nodeId) {
|
|
44370
45106
|
const body = CreateNodeWorkDirBranchBody.parse(req.body);
|
|
44371
|
-
const
|
|
44372
|
-
const self2 = nodeRegistry.getSelf();
|
|
44373
|
-
|
|
45107
|
+
const deps = req.app.locals.deps;
|
|
45108
|
+
const self2 = deps.nodeRegistry.getSelf();
|
|
45109
|
+
const isSelf = nodeId === self2.id;
|
|
45110
|
+
if (!isSelf && !deps.election.isLeader()) {
|
|
45111
|
+
throw new MeshyError("NOT_LEADER", "Only the leader can create branches on other nodes", 403);
|
|
45112
|
+
}
|
|
45113
|
+
const node = isSelf ? self2 : deps.nodeRegistry.getNode(nodeId);
|
|
45114
|
+
if (!node) {
|
|
44374
45115
|
throw new MeshyError("NODE_NOT_FOUND", `Node ${nodeId} not found`, 404);
|
|
44375
45116
|
}
|
|
44376
|
-
|
|
44377
|
-
|
|
44378
|
-
|
|
44379
|
-
body.
|
|
44380
|
-
|
|
44381
|
-
|
|
44382
|
-
|
|
44383
|
-
|
|
44384
|
-
|
|
44385
|
-
|
|
45117
|
+
const payload = {
|
|
45118
|
+
path: body.path,
|
|
45119
|
+
branchName: body.branchName,
|
|
45120
|
+
startPoint: body.startPoint,
|
|
45121
|
+
limit: body.limit,
|
|
45122
|
+
offset: body.offset,
|
|
45123
|
+
allowAbsolute: body.allowAbsolute
|
|
45124
|
+
};
|
|
45125
|
+
const operations = getNodeOperationService(deps);
|
|
45126
|
+
const operation = operations.create("workdir.branch-create", nodeId, payload);
|
|
45127
|
+
if (isSelf) {
|
|
45128
|
+
operations.runLocal(operation.id);
|
|
45129
|
+
} else {
|
|
45130
|
+
try {
|
|
45131
|
+
await dispatchNodeOperation(deps, operation, node);
|
|
45132
|
+
} catch (err) {
|
|
45133
|
+
operations.markFailed(operation.id, err instanceof Error ? err.message : String(err));
|
|
45134
|
+
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} to create a git branch`, 502);
|
|
44386
45135
|
}
|
|
44387
|
-
|
|
45136
|
+
}
|
|
45137
|
+
res.status(202).json(operation);
|
|
44388
45138
|
}
|
|
44389
45139
|
|
|
44390
45140
|
// ../../packages/api/src/tasks/task-route-utils.ts
|
|
44391
|
-
var
|
|
45141
|
+
var fs16 = __toESM(require("fs"), 1);
|
|
45142
|
+
var import_node_stream2 = require("stream");
|
|
45143
|
+
var import_promises5 = require("stream/promises");
|
|
44392
45144
|
|
|
44393
45145
|
// ../../packages/api/src/node/node-message-compat.ts
|
|
44394
45146
|
var LEGACY_KIND_BY_NODE_MESSAGE = {
|
|
@@ -44440,10 +45192,10 @@ function readLocalTaskLogs(engineRegistry, taskId, after, agent) {
|
|
|
44440
45192
|
throw new MeshyError("VALIDATION_ERROR", `Engine not registered for agent: ${agent}`, 400);
|
|
44441
45193
|
}
|
|
44442
45194
|
const logPath = engine.getLogPath(taskId);
|
|
44443
|
-
if (!
|
|
45195
|
+
if (!fs16.existsSync(logPath)) {
|
|
44444
45196
|
return { logs: [], total: 0 };
|
|
44445
45197
|
}
|
|
44446
|
-
const content =
|
|
45198
|
+
const content = fs16.readFileSync(logPath, "utf-8");
|
|
44447
45199
|
const allLines = content.trim().split("\n").filter(Boolean);
|
|
44448
45200
|
const logs = [];
|
|
44449
45201
|
for (let i = after; i < allLines.length; i++) {
|
|
@@ -44621,10 +45373,27 @@ async function sendProxyResponse(res, proxyRes) {
|
|
|
44621
45373
|
const contentType = proxyRes.headers.get("content-type");
|
|
44622
45374
|
const contentDisposition = proxyRes.headers.get("content-disposition");
|
|
44623
45375
|
const cacheControl = proxyRes.headers.get("cache-control");
|
|
44624
|
-
const body = Buffer.from(await proxyRes.arrayBuffer());
|
|
44625
45376
|
if (contentType) res.setHeader("Content-Type", contentType);
|
|
44626
45377
|
if (contentDisposition) res.setHeader("Content-Disposition", contentDisposition);
|
|
44627
45378
|
if (cacheControl) res.setHeader("Cache-Control", cacheControl);
|
|
45379
|
+
if (contentType?.split(";")[0]?.trim().toLowerCase() === "text/event-stream") {
|
|
45380
|
+
if (!cacheControl) res.setHeader("Cache-Control", "no-cache");
|
|
45381
|
+
res.status(proxyRes.status);
|
|
45382
|
+
res.flushHeaders();
|
|
45383
|
+
if (!proxyRes.body) {
|
|
45384
|
+
res.end();
|
|
45385
|
+
return;
|
|
45386
|
+
}
|
|
45387
|
+
try {
|
|
45388
|
+
await (0, import_promises5.pipeline)(import_node_stream2.Readable.fromWeb(proxyRes.body), res);
|
|
45389
|
+
} catch (error) {
|
|
45390
|
+
if (!res.destroyed && !res.writableEnded) {
|
|
45391
|
+
throw error;
|
|
45392
|
+
}
|
|
45393
|
+
}
|
|
45394
|
+
return;
|
|
45395
|
+
}
|
|
45396
|
+
const body = Buffer.from(await proxyRes.arrayBuffer());
|
|
44628
45397
|
res.status(proxyRes.status).send(body);
|
|
44629
45398
|
}
|
|
44630
45399
|
async function maybeProxyReadToLeader(req, res, options = {}) {
|
|
@@ -44725,49 +45494,193 @@ function cancelTaskOnCurrentNode(deps, taskId, options = {}) {
|
|
|
44725
45494
|
}
|
|
44726
45495
|
|
|
44727
45496
|
// ../../packages/api/src/tasks/task-output-service.ts
|
|
44728
|
-
var
|
|
44729
|
-
var
|
|
45497
|
+
var fs18 = __toESM(require("fs"), 1);
|
|
45498
|
+
var path19 = __toESM(require("path"), 1);
|
|
44730
45499
|
|
|
44731
45500
|
// ../../packages/api/src/preview/preview-server.ts
|
|
44732
45501
|
var crypto3 = __toESM(require("crypto"), 1);
|
|
44733
|
-
var
|
|
44734
|
-
var
|
|
45502
|
+
var fs17 = __toESM(require("fs"), 1);
|
|
45503
|
+
var path18 = __toESM(require("path"), 1);
|
|
44735
45504
|
var http2 = __toESM(require("http"), 1);
|
|
45505
|
+
var import_node_stream3 = require("stream");
|
|
45506
|
+
var import_promises6 = require("stream/promises");
|
|
45507
|
+
|
|
45508
|
+
// ../../packages/api/src/preview/preview-request.ts
|
|
45509
|
+
var PREVIEW_AUTHORIZATION_HEADER = "x-meshy-preview-authorization";
|
|
45510
|
+
var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
45511
|
+
"connection",
|
|
45512
|
+
"keep-alive",
|
|
45513
|
+
"proxy-authenticate",
|
|
45514
|
+
"proxy-authorization",
|
|
45515
|
+
"te",
|
|
45516
|
+
"trailer",
|
|
45517
|
+
"transfer-encoding",
|
|
45518
|
+
"upgrade"
|
|
45519
|
+
]);
|
|
45520
|
+
function isReadOnlyPreviewMethod(method) {
|
|
45521
|
+
const normalizedMethod = method?.toUpperCase() ?? "GET";
|
|
45522
|
+
return normalizedMethod === "GET" || normalizedMethod === "HEAD";
|
|
45523
|
+
}
|
|
45524
|
+
function methodAllowsRequestBody(method) {
|
|
45525
|
+
return !isReadOnlyPreviewMethod(method);
|
|
45526
|
+
}
|
|
45527
|
+
function toArrayBuffer(value) {
|
|
45528
|
+
const copy = new Uint8Array(value.byteLength);
|
|
45529
|
+
copy.set(value);
|
|
45530
|
+
return copy.buffer;
|
|
45531
|
+
}
|
|
45532
|
+
function getParsedRequestBody(req) {
|
|
45533
|
+
const body = req.body;
|
|
45534
|
+
if (body === void 0) {
|
|
45535
|
+
return void 0;
|
|
45536
|
+
}
|
|
45537
|
+
if (typeof body === "string" || body instanceof URLSearchParams || body instanceof Blob || body instanceof FormData) {
|
|
45538
|
+
return body;
|
|
45539
|
+
}
|
|
45540
|
+
if (Buffer.isBuffer(body)) {
|
|
45541
|
+
return toArrayBuffer(body);
|
|
45542
|
+
}
|
|
45543
|
+
if (body instanceof Uint8Array) {
|
|
45544
|
+
return toArrayBuffer(body);
|
|
45545
|
+
}
|
|
45546
|
+
return JSON.stringify(body);
|
|
45547
|
+
}
|
|
45548
|
+
async function readPreviewRequestBody(req) {
|
|
45549
|
+
if (!req || !methodAllowsRequestBody(req.method)) {
|
|
45550
|
+
return void 0;
|
|
45551
|
+
}
|
|
45552
|
+
const parsedBody = getParsedRequestBody(req);
|
|
45553
|
+
if (parsedBody !== void 0) {
|
|
45554
|
+
return parsedBody;
|
|
45555
|
+
}
|
|
45556
|
+
const chunks = [];
|
|
45557
|
+
for await (const chunk of req) {
|
|
45558
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
45559
|
+
}
|
|
45560
|
+
return chunks.length > 0 ? toArrayBuffer(Buffer.concat(chunks)) : void 0;
|
|
45561
|
+
}
|
|
45562
|
+
function buildServiceProxyHeaders(req) {
|
|
45563
|
+
const headers = {};
|
|
45564
|
+
if (!req) {
|
|
45565
|
+
return headers;
|
|
45566
|
+
}
|
|
45567
|
+
let previewAuthorization;
|
|
45568
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
45569
|
+
const normalizedKey = key.toLowerCase();
|
|
45570
|
+
if (HOP_BY_HOP_HEADERS.has(normalizedKey) || normalizedKey === "host" || normalizedKey === "content-length" || normalizedKey === "forwarded" || normalizedKey === "x-real-ip" || normalizedKey.startsWith("x-forwarded-") || normalizedKey === MESHY_AUTHORIZATION_HEADER) {
|
|
45571
|
+
continue;
|
|
45572
|
+
}
|
|
45573
|
+
if (normalizedKey === PREVIEW_AUTHORIZATION_HEADER) {
|
|
45574
|
+
previewAuthorization = Array.isArray(value) ? value[0] : value;
|
|
45575
|
+
continue;
|
|
45576
|
+
}
|
|
45577
|
+
if (Array.isArray(value)) {
|
|
45578
|
+
headers[key] = value.join(", ");
|
|
45579
|
+
} else if (typeof value === "string") {
|
|
45580
|
+
headers[key] = value;
|
|
45581
|
+
}
|
|
45582
|
+
}
|
|
45583
|
+
if (previewAuthorization && !headers.authorization) {
|
|
45584
|
+
headers.authorization = previewAuthorization;
|
|
45585
|
+
}
|
|
45586
|
+
return headers;
|
|
45587
|
+
}
|
|
45588
|
+
function buildPreviewWorkerProxyHeaders(req) {
|
|
45589
|
+
const headers = {};
|
|
45590
|
+
let previewAuthorization;
|
|
45591
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
45592
|
+
const normalizedKey = key.toLowerCase();
|
|
45593
|
+
if (HOP_BY_HOP_HEADERS.has(normalizedKey) || normalizedKey === "host" || normalizedKey === "content-length" || normalizedKey === MESHY_AUTHORIZATION_HEADER || normalizedKey === PREVIEW_AUTHORIZATION_HEADER) {
|
|
45594
|
+
continue;
|
|
45595
|
+
}
|
|
45596
|
+
if (normalizedKey === "authorization") {
|
|
45597
|
+
previewAuthorization = Array.isArray(value) ? value[0] : value;
|
|
45598
|
+
continue;
|
|
45599
|
+
}
|
|
45600
|
+
if (Array.isArray(value)) {
|
|
45601
|
+
headers[key] = value.join(", ");
|
|
45602
|
+
} else if (typeof value === "string") {
|
|
45603
|
+
headers[key] = value;
|
|
45604
|
+
}
|
|
45605
|
+
}
|
|
45606
|
+
if (previewAuthorization) {
|
|
45607
|
+
headers[PREVIEW_AUTHORIZATION_HEADER] = previewAuthorization;
|
|
45608
|
+
}
|
|
45609
|
+
return headers;
|
|
45610
|
+
}
|
|
45611
|
+
|
|
45612
|
+
// ../../packages/api/src/preview/preview-server.ts
|
|
44736
45613
|
function resolvePreviewPath(rootPath, relativePath) {
|
|
44737
45614
|
const sanitizedPath = relativePath.replace(/\\/g, "/");
|
|
44738
|
-
const resolvedPath =
|
|
44739
|
-
const normalizedRoot =
|
|
44740
|
-
if (!resolvedPath.startsWith(normalizedRoot +
|
|
45615
|
+
const resolvedPath = path18.resolve(rootPath, sanitizedPath);
|
|
45616
|
+
const normalizedRoot = path18.resolve(rootPath);
|
|
45617
|
+
if (!resolvedPath.startsWith(normalizedRoot + path18.sep) && resolvedPath !== normalizedRoot) {
|
|
44741
45618
|
throw new Error("Invalid preview path");
|
|
44742
45619
|
}
|
|
44743
45620
|
return {
|
|
44744
45621
|
absolutePath: resolvedPath,
|
|
44745
|
-
normalizedPath:
|
|
45622
|
+
normalizedPath: path18.relative(normalizedRoot, resolvedPath).split(path18.sep).join("/")
|
|
44746
45623
|
};
|
|
44747
45624
|
}
|
|
44748
45625
|
function resolvePreviewEntryPath(rootPath, entryPath) {
|
|
44749
45626
|
const { absolutePath, normalizedPath } = resolvePreviewPath(rootPath, entryPath ?? "index.html");
|
|
44750
|
-
if (!
|
|
45627
|
+
if (!fs17.existsSync(absolutePath) || !fs17.statSync(absolutePath).isFile()) {
|
|
44751
45628
|
throw new Error("Preview entry not found");
|
|
44752
45629
|
}
|
|
44753
45630
|
return normalizedPath;
|
|
44754
45631
|
}
|
|
45632
|
+
function normalizeServiceEntryPath(entryPath) {
|
|
45633
|
+
if (!entryPath || entryPath === "/") {
|
|
45634
|
+
return "";
|
|
45635
|
+
}
|
|
45636
|
+
return entryPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
45637
|
+
}
|
|
45638
|
+
function assertPreviewServicePort(port) {
|
|
45639
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
45640
|
+
throw new Error("Invalid preview service port");
|
|
45641
|
+
}
|
|
45642
|
+
return port;
|
|
45643
|
+
}
|
|
44755
45644
|
function buildPreviewUrl(origin, session) {
|
|
45645
|
+
return buildPreviewRouteUrl(origin, "preview", session);
|
|
45646
|
+
}
|
|
45647
|
+
function buildPreviewOpenUrl(origin, session) {
|
|
45648
|
+
return buildPreviewRouteUrl(origin, "preview-open", session);
|
|
45649
|
+
}
|
|
45650
|
+
function buildPreviewRouteUrl(origin, route, session) {
|
|
44756
45651
|
const encodedEntryPath = session.entryPath.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
|
|
44757
|
-
|
|
45652
|
+
const suffix = encodedEntryPath.length > 0 ? `/${encodedEntryPath}` : session.kind === "service" ? "/" : "";
|
|
45653
|
+
return `${origin.replace(/\/+$/, "")}/${route}/${session.token}${suffix}`;
|
|
44758
45654
|
}
|
|
44759
45655
|
var DEFAULT_TTL_MS = 15 * 60 * 1e3;
|
|
44760
45656
|
var PreviewSessionManager = class {
|
|
44761
45657
|
sessions = /* @__PURE__ */ new Map();
|
|
44762
45658
|
create(options) {
|
|
44763
45659
|
const token = crypto3.randomBytes(32).toString("hex");
|
|
45660
|
+
const expiresAt = Date.now() + (options.ttlMs ?? DEFAULT_TTL_MS);
|
|
45661
|
+
if (options.port !== void 0) {
|
|
45662
|
+
const session2 = {
|
|
45663
|
+
token,
|
|
45664
|
+
taskId: options.taskId,
|
|
45665
|
+
kind: "service",
|
|
45666
|
+
port: assertPreviewServicePort(options.port),
|
|
45667
|
+
entryPath: normalizeServiceEntryPath(options.entryPath),
|
|
45668
|
+
expiresAt
|
|
45669
|
+
};
|
|
45670
|
+
this.sessions.set(token, session2);
|
|
45671
|
+
return session2;
|
|
45672
|
+
}
|
|
45673
|
+
if (!options.rootPath) {
|
|
45674
|
+
throw new Error("Preview root path is required");
|
|
45675
|
+
}
|
|
44764
45676
|
const entryPath = resolvePreviewEntryPath(options.rootPath, options.entryPath);
|
|
44765
45677
|
const session = {
|
|
44766
45678
|
token,
|
|
44767
45679
|
taskId: options.taskId,
|
|
45680
|
+
kind: "file",
|
|
44768
45681
|
rootPath: options.rootPath,
|
|
44769
45682
|
entryPath,
|
|
44770
|
-
expiresAt
|
|
45683
|
+
expiresAt
|
|
44771
45684
|
};
|
|
44772
45685
|
this.sessions.set(token, session);
|
|
44773
45686
|
return session;
|
|
@@ -44808,19 +45721,357 @@ var MIME_MAP2 = {
|
|
|
44808
45721
|
".woff2": "font/woff2",
|
|
44809
45722
|
".ttf": "font/ttf",
|
|
44810
45723
|
".eot": "application/vnd.ms-fontobject",
|
|
44811
|
-
".pdf": "application/pdf"
|
|
45724
|
+
".pdf": "application/pdf",
|
|
45725
|
+
".md": "text/markdown",
|
|
45726
|
+
".mdx": "text/markdown"
|
|
44812
45727
|
};
|
|
44813
45728
|
function getMime(filePath) {
|
|
44814
|
-
return MIME_MAP2[
|
|
45729
|
+
return MIME_MAP2[path18.extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
45730
|
+
}
|
|
45731
|
+
function escapeHtml(value) {
|
|
45732
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
45733
|
+
}
|
|
45734
|
+
function renderInlineMarkdown(value) {
|
|
45735
|
+
let rendered = escapeHtml(value);
|
|
45736
|
+
rendered = rendered.replace(/!\[([^\]]*)]\(([^\s)]+)\)/g, '<img alt="$1" src="$2">');
|
|
45737
|
+
rendered = rendered.replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/\[([^\]]+)]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" rel="noreferrer noopener" target="_blank">$1</a>');
|
|
45738
|
+
return rendered;
|
|
45739
|
+
}
|
|
45740
|
+
function renderMarkdownBody(markdown) {
|
|
45741
|
+
const lines = markdown.replace(/\r\n/g, "\n").split("\n");
|
|
45742
|
+
const blocks = [];
|
|
45743
|
+
let paragraph = [];
|
|
45744
|
+
let listItems = [];
|
|
45745
|
+
let codeLines = null;
|
|
45746
|
+
const flushParagraph = () => {
|
|
45747
|
+
if (paragraph.length === 0) return;
|
|
45748
|
+
blocks.push(`<p>${renderInlineMarkdown(paragraph.join(" "))}</p>`);
|
|
45749
|
+
paragraph = [];
|
|
45750
|
+
};
|
|
45751
|
+
const flushList = () => {
|
|
45752
|
+
if (listItems.length === 0) return;
|
|
45753
|
+
blocks.push(`<ul>${listItems.map((item) => `<li>${renderInlineMarkdown(item)}</li>`).join("")}</ul>`);
|
|
45754
|
+
listItems = [];
|
|
45755
|
+
};
|
|
45756
|
+
for (const line of lines) {
|
|
45757
|
+
if (line.trim().startsWith("```")) {
|
|
45758
|
+
if (codeLines) {
|
|
45759
|
+
blocks.push(`<pre><code>${escapeHtml(codeLines.join("\n"))}</code></pre>`);
|
|
45760
|
+
codeLines = null;
|
|
45761
|
+
} else {
|
|
45762
|
+
flushParagraph();
|
|
45763
|
+
flushList();
|
|
45764
|
+
codeLines = [];
|
|
45765
|
+
}
|
|
45766
|
+
continue;
|
|
45767
|
+
}
|
|
45768
|
+
if (codeLines) {
|
|
45769
|
+
codeLines.push(line);
|
|
45770
|
+
continue;
|
|
45771
|
+
}
|
|
45772
|
+
const trimmed = line.trim();
|
|
45773
|
+
if (!trimmed) {
|
|
45774
|
+
flushParagraph();
|
|
45775
|
+
flushList();
|
|
45776
|
+
continue;
|
|
45777
|
+
}
|
|
45778
|
+
const heading = trimmed.match(/^(#{1,6})\s+(.+)$/);
|
|
45779
|
+
if (heading) {
|
|
45780
|
+
flushParagraph();
|
|
45781
|
+
flushList();
|
|
45782
|
+
const level = heading[1].length;
|
|
45783
|
+
blocks.push(`<h${level}>${renderInlineMarkdown(heading[2])}</h${level}>`);
|
|
45784
|
+
continue;
|
|
45785
|
+
}
|
|
45786
|
+
const listItem = trimmed.match(/^[-*]\s+(.+)$/);
|
|
45787
|
+
if (listItem) {
|
|
45788
|
+
flushParagraph();
|
|
45789
|
+
listItems.push(listItem[1]);
|
|
45790
|
+
continue;
|
|
45791
|
+
}
|
|
45792
|
+
flushList();
|
|
45793
|
+
paragraph.push(trimmed);
|
|
45794
|
+
}
|
|
45795
|
+
if (codeLines) {
|
|
45796
|
+
blocks.push(`<pre><code>${escapeHtml(codeLines.join("\n"))}</code></pre>`);
|
|
45797
|
+
}
|
|
45798
|
+
flushParagraph();
|
|
45799
|
+
flushList();
|
|
45800
|
+
return blocks.join("\n");
|
|
45801
|
+
}
|
|
45802
|
+
function renderMarkdownDocument(markdown, title) {
|
|
45803
|
+
const body = renderMarkdownBody(markdown);
|
|
45804
|
+
return Buffer.from(`<!doctype html>
|
|
45805
|
+
<html>
|
|
45806
|
+
<head>
|
|
45807
|
+
<meta charset="utf-8">
|
|
45808
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
45809
|
+
<title>${escapeHtml(title)}</title>
|
|
45810
|
+
<style>
|
|
45811
|
+
body { box-sizing: border-box; max-width: 860px; margin: 0 auto; padding: 32px; color: #111827; font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
45812
|
+
h1, h2, h3, h4, h5, h6 { line-height: 1.25; margin: 1.5em 0 0.5em; }
|
|
45813
|
+
h1 { border-bottom: 1px solid #e5e7eb; padding-bottom: 0.3em; }
|
|
45814
|
+
pre { overflow: auto; border-radius: 8px; background: #111827; color: #f9fafb; padding: 16px; }
|
|
45815
|
+
code { border-radius: 4px; background: #f3f4f6; padding: 0.1em 0.25em; }
|
|
45816
|
+
pre code { background: transparent; padding: 0; }
|
|
45817
|
+
img { max-width: 100%; }
|
|
45818
|
+
a { color: #2563eb; }
|
|
45819
|
+
</style>
|
|
45820
|
+
</head>
|
|
45821
|
+
<body>
|
|
45822
|
+
${body}
|
|
45823
|
+
</body>
|
|
45824
|
+
</html>`, "utf8");
|
|
45825
|
+
}
|
|
45826
|
+
function splitPreviewPathAndSearch(value) {
|
|
45827
|
+
const marker = value.indexOf("?");
|
|
45828
|
+
if (marker === -1) {
|
|
45829
|
+
return { pathname: value, search: "" };
|
|
45830
|
+
}
|
|
45831
|
+
return { pathname: value.slice(0, marker), search: value.slice(marker) };
|
|
45832
|
+
}
|
|
45833
|
+
function decodePreviewPathname(pathname) {
|
|
45834
|
+
return pathname ? decodeURIComponent(pathname) : "";
|
|
45835
|
+
}
|
|
45836
|
+
function normalizeServiceRequestPath(pathname) {
|
|
45837
|
+
const normalized = pathname.replace(/\\/g, "/");
|
|
45838
|
+
if (!normalized || normalized === "/") {
|
|
45839
|
+
return "/";
|
|
45840
|
+
}
|
|
45841
|
+
return `/${normalized.replace(/^\/+/, "")}`;
|
|
45842
|
+
}
|
|
45843
|
+
function rewriteServiceRootRelativeUrls(value, token) {
|
|
45844
|
+
const previewRoot = `/preview/${token}/`;
|
|
45845
|
+
return value.replace(/\b(src|href|action)=(['"])\/(?!\/|preview\/)/gi, `$1=$2${previewRoot}`).replace(/url\((['"]?)\/(?!\/|preview\/)/gi, `url($1${previewRoot}`).replace(/\bimport\((['"])\/(?!\/|preview\/)/gi, `import($1${previewRoot}`).replace(/\bfrom\s+(['"])\/(?!\/|preview\/)/gi, `from $1${previewRoot}`).replace(/(['"])\/(assets\/[^'"]+)\1/g, `$1${previewRoot}$2$1`);
|
|
45846
|
+
}
|
|
45847
|
+
function escapeHtmlAttribute(value) {
|
|
45848
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
45849
|
+
}
|
|
45850
|
+
function buildServicePreviewBridge(token) {
|
|
45851
|
+
const previewRoot = `/preview/${token}/`;
|
|
45852
|
+
const previewBase = previewRoot.replace(/\/$/, "");
|
|
45853
|
+
const script = [
|
|
45854
|
+
"(()=>{",
|
|
45855
|
+
"if(window.top===window)return;",
|
|
45856
|
+
`const previewBase=${JSON.stringify(previewBase)};`,
|
|
45857
|
+
`const previewRoot=${JSON.stringify(previewRoot)};`,
|
|
45858
|
+
"const rewritePreviewRequestUrl=(value)=>{",
|
|
45859
|
+
"if(value==null)return value;",
|
|
45860
|
+
"let raw;",
|
|
45861
|
+
'try{raw=value instanceof URL?value.href:typeof value==="string"?value:value&&typeof value.url==="string"?value.url:undefined;}catch{return value;}',
|
|
45862
|
+
"if(!raw)return value;",
|
|
45863
|
+
"let url;",
|
|
45864
|
+
"try{url=new URL(raw,window.location.href);}catch{return value;}",
|
|
45865
|
+
"if(url.origin!==window.location.origin)return value;",
|
|
45866
|
+
'if(url.pathname===previewBase||url.pathname.startsWith(previewRoot)||url.pathname.startsWith("/preview-open/"))return value;',
|
|
45867
|
+
'return previewRoot+url.pathname.replace(/^\\/+/,"")+url.search+url.hash;',
|
|
45868
|
+
"};",
|
|
45869
|
+
"const rewritePreviewRequestInput=(input)=>{",
|
|
45870
|
+
"const next=rewritePreviewRequestUrl(input);",
|
|
45871
|
+
"if(next===input)return input;",
|
|
45872
|
+
'if(typeof Request==="function"&&input instanceof Request)return new Request(next,input);',
|
|
45873
|
+
"return next;",
|
|
45874
|
+
"};",
|
|
45875
|
+
"const originalFetch=window.fetch;",
|
|
45876
|
+
'if(typeof originalFetch==="function")window.fetch=(input,init)=>originalFetch.call(window,rewritePreviewRequestInput(input),init);',
|
|
45877
|
+
"const XHR=window.XMLHttpRequest;",
|
|
45878
|
+
"if(XHR&&XHR.prototype){const open=XHR.prototype.open;XMLHttpRequest.prototype.open=function(method,url,...rest){return open.call(this,method,rewritePreviewRequestUrl(url),...rest);};}",
|
|
45879
|
+
"const OriginalEventSource=window.EventSource;",
|
|
45880
|
+
'if(typeof OriginalEventSource==="function"){window.EventSource=function(url,config){return new OriginalEventSource(rewritePreviewRequestUrl(url),config);};window.EventSource.prototype=OriginalEventSource.prototype;}',
|
|
45881
|
+
"const currentPath=window.location.pathname;",
|
|
45882
|
+
"if(currentPath===previewBase||currentPath.startsWith(previewRoot)){",
|
|
45883
|
+
"const suffix=currentPath===previewBase?'':currentPath.slice(previewRoot.length);",
|
|
45884
|
+
"const servicePath=suffix?'/' + suffix:'/';",
|
|
45885
|
+
"window.history.replaceState(window.history.state,'',servicePath+window.location.search+window.location.hash);",
|
|
45886
|
+
"}",
|
|
45887
|
+
"})();"
|
|
45888
|
+
].join("");
|
|
45889
|
+
return `<base data-meshy-preview-base href="${escapeHtmlAttribute(previewRoot)}"><script data-meshy-preview-bridge>${script}</script>`;
|
|
45890
|
+
}
|
|
45891
|
+
function injectServicePreviewBridge(value, token) {
|
|
45892
|
+
const bridge = buildServicePreviewBridge(token);
|
|
45893
|
+
const headPattern = /<head(?:\s[^>]*)?>/i;
|
|
45894
|
+
if (headPattern.test(value)) {
|
|
45895
|
+
return value.replace(headPattern, (match) => `${match}${bridge}`);
|
|
45896
|
+
}
|
|
45897
|
+
const htmlPattern = /<html(?:\s[^>]*)?>/i;
|
|
45898
|
+
if (htmlPattern.test(value)) {
|
|
45899
|
+
return value.replace(htmlPattern, (match) => `${match}<head>${bridge}</head>`);
|
|
45900
|
+
}
|
|
45901
|
+
return `${bridge}${value}`;
|
|
45902
|
+
}
|
|
45903
|
+
function normalizeContentType(contentType) {
|
|
45904
|
+
return contentType?.split(";")[0]?.trim().toLowerCase();
|
|
45905
|
+
}
|
|
45906
|
+
function isServiceHtmlContentType(contentType) {
|
|
45907
|
+
return normalizeContentType(contentType) === "text/html";
|
|
45908
|
+
}
|
|
45909
|
+
function isServiceEventStreamContentType(contentType) {
|
|
45910
|
+
return normalizeContentType(contentType) === "text/event-stream";
|
|
45911
|
+
}
|
|
45912
|
+
function isServiceJavaScriptContentType(normalizedType) {
|
|
45913
|
+
return normalizedType === "text/javascript" || normalizedType === "application/javascript" || normalizedType === "application/x-javascript";
|
|
45914
|
+
}
|
|
45915
|
+
function rewriteServiceJavaScriptRuntimeUrls(value, token) {
|
|
45916
|
+
if (!value.includes("__vite__mapDeps")) {
|
|
45917
|
+
return value;
|
|
45918
|
+
}
|
|
45919
|
+
const previewRoot = `/preview/${token}/`;
|
|
45920
|
+
return value.replace(
|
|
45921
|
+
/return\s*(['"])\/\1\s*\+\s*([A-Za-z_$][\w$]*)/g,
|
|
45922
|
+
(_match, quote, argumentName) => `return${quote}${previewRoot}${quote}+${argumentName}`
|
|
45923
|
+
);
|
|
45924
|
+
}
|
|
45925
|
+
function rewriteServiceResponseContent(content, contentType, token) {
|
|
45926
|
+
const normalizedType = normalizeContentType(contentType);
|
|
45927
|
+
if (normalizedType !== "text/html" && normalizedType !== "text/css" && !isServiceJavaScriptContentType(normalizedType)) {
|
|
45928
|
+
return content;
|
|
45929
|
+
}
|
|
45930
|
+
const source = content.toString("utf8");
|
|
45931
|
+
const bridged = normalizedType === "text/html" ? injectServicePreviewBridge(source, token) : source;
|
|
45932
|
+
const rewritten = rewriteServiceRootRelativeUrls(bridged, token);
|
|
45933
|
+
return Buffer.from(
|
|
45934
|
+
isServiceJavaScriptContentType(normalizedType) ? rewriteServiceJavaScriptRuntimeUrls(rewritten, token) : rewritten,
|
|
45935
|
+
"utf8"
|
|
45936
|
+
);
|
|
44815
45937
|
}
|
|
44816
|
-
function
|
|
45938
|
+
function rewriteServiceRedirectLocation(value, session) {
|
|
45939
|
+
const previewRoot = `/preview/${session.token}`;
|
|
45940
|
+
if (value.startsWith("/preview/")) {
|
|
45941
|
+
return value;
|
|
45942
|
+
}
|
|
45943
|
+
if (value.startsWith("/")) {
|
|
45944
|
+
return `${previewRoot}${value}`;
|
|
45945
|
+
}
|
|
45946
|
+
try {
|
|
45947
|
+
const url = new URL(value);
|
|
45948
|
+
const isLocalService = (url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "[::1]") && url.port === String(session.port);
|
|
45949
|
+
if (isLocalService) {
|
|
45950
|
+
return `${previewRoot}${url.pathname}${url.search}${url.hash}`;
|
|
45951
|
+
}
|
|
45952
|
+
} catch {
|
|
45953
|
+
}
|
|
45954
|
+
return value;
|
|
45955
|
+
}
|
|
45956
|
+
function buildServiceResponseHeaders(upstream, session, isHtml) {
|
|
45957
|
+
const headers = {};
|
|
45958
|
+
upstream.headers.forEach((value, key) => {
|
|
45959
|
+
const normalizedKey = key.toLowerCase();
|
|
45960
|
+
if (HOP_BY_HOP_HEADERS.has(normalizedKey) || normalizedKey === "content-length" || normalizedKey === "content-encoding" || isHtml && normalizedKey === "content-security-policy" || isHtml && normalizedKey === "content-security-policy-report-only" || isHtml && normalizedKey === "x-frame-options") {
|
|
45961
|
+
return;
|
|
45962
|
+
}
|
|
45963
|
+
if (normalizedKey === "location") {
|
|
45964
|
+
headers[key] = rewriteServiceRedirectLocation(value, session);
|
|
45965
|
+
return;
|
|
45966
|
+
}
|
|
45967
|
+
headers[key] = value;
|
|
45968
|
+
});
|
|
45969
|
+
if (typeof headers["cache-control"] !== "string") {
|
|
45970
|
+
headers["cache-control"] = "no-cache";
|
|
45971
|
+
}
|
|
45972
|
+
return headers;
|
|
45973
|
+
}
|
|
45974
|
+
async function pipeServiceResponseBody(upstream, res) {
|
|
45975
|
+
if (!upstream.body) {
|
|
45976
|
+
res.end();
|
|
45977
|
+
return;
|
|
45978
|
+
}
|
|
45979
|
+
try {
|
|
45980
|
+
await (0, import_promises6.pipeline)(import_node_stream3.Readable.fromWeb(upstream.body), res);
|
|
45981
|
+
} catch (error) {
|
|
45982
|
+
if (!res.destroyed && !res.writableEnded) {
|
|
45983
|
+
throw error;
|
|
45984
|
+
}
|
|
45985
|
+
}
|
|
45986
|
+
}
|
|
45987
|
+
async function sendServicePreviewResponse(session, requestedPath, req, res) {
|
|
45988
|
+
const { pathname, search } = splitPreviewPathAndSearch(requestedPath ?? session.entryPath);
|
|
45989
|
+
const decodedPathname = decodePreviewPathname(pathname);
|
|
45990
|
+
const targetPath = normalizeServiceRequestPath(decodedPathname || session.entryPath);
|
|
45991
|
+
const targetUrl = `http://127.0.0.1:${session.port}${targetPath}${search}`;
|
|
45992
|
+
let upstream;
|
|
45993
|
+
try {
|
|
45994
|
+
const body = await readPreviewRequestBody(req);
|
|
45995
|
+
upstream = await fetch(targetUrl, {
|
|
45996
|
+
method: req?.method ?? "GET",
|
|
45997
|
+
headers: buildServiceProxyHeaders(req),
|
|
45998
|
+
...body !== void 0 ? { body } : {},
|
|
45999
|
+
redirect: "manual"
|
|
46000
|
+
});
|
|
46001
|
+
} catch {
|
|
46002
|
+
res.writeHead(502, { "Content-Type": "text/plain" });
|
|
46003
|
+
res.end("Preview service unavailable");
|
|
46004
|
+
return;
|
|
46005
|
+
}
|
|
46006
|
+
const upstreamContentType = upstream.headers.get("content-type");
|
|
46007
|
+
const isHtml = isServiceHtmlContentType(upstreamContentType);
|
|
46008
|
+
const headers = buildServiceResponseHeaders(upstream, session, isHtml);
|
|
46009
|
+
if (isServiceEventStreamContentType(upstreamContentType)) {
|
|
46010
|
+
res.writeHead(upstream.status, headers);
|
|
46011
|
+
await pipeServiceResponseBody(upstream, res);
|
|
46012
|
+
return;
|
|
46013
|
+
}
|
|
46014
|
+
const content = rewriteServiceResponseContent(Buffer.from(await upstream.arrayBuffer()), upstreamContentType, session.token);
|
|
46015
|
+
headers["content-length"] = content.length;
|
|
46016
|
+
res.writeHead(upstream.status, headers);
|
|
46017
|
+
res.end(content);
|
|
46018
|
+
}
|
|
46019
|
+
function buildPreviewUrlForRequest(token, requestedPath, session) {
|
|
46020
|
+
const { pathname, search } = splitPreviewPathAndSearch(requestedPath ?? session.entryPath);
|
|
46021
|
+
const entryPath = pathname ? decodePreviewPathname(pathname) : session.entryPath;
|
|
46022
|
+
return `${buildPreviewUrl("", { token, entryPath, kind: session.kind })}${search}`;
|
|
46023
|
+
}
|
|
46024
|
+
function renderPreviewOpenDocument(previewUrl) {
|
|
46025
|
+
const safePreviewUrl = escapeHtmlAttribute(previewUrl);
|
|
46026
|
+
return Buffer.from(`<!doctype html>
|
|
46027
|
+
<html>
|
|
46028
|
+
<head>
|
|
46029
|
+
<meta charset="utf-8">
|
|
46030
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
46031
|
+
<title>Preview</title>
|
|
46032
|
+
<style>
|
|
46033
|
+
html, body { width: 100%; height: 100%; margin: 0; background: #fff; }
|
|
46034
|
+
iframe { display: block; width: 100%; height: 100%; border: 0; }
|
|
46035
|
+
</style>
|
|
46036
|
+
</head>
|
|
46037
|
+
<body>
|
|
46038
|
+
<iframe src="${safePreviewUrl}" title="Preview"></iframe>
|
|
46039
|
+
</body>
|
|
46040
|
+
</html>`, "utf8");
|
|
46041
|
+
}
|
|
46042
|
+
function sendPreviewOpenResponse(sessionManager, token, requestedPath, res) {
|
|
44817
46043
|
const session = sessionManager.get(token);
|
|
44818
46044
|
if (!session) {
|
|
44819
46045
|
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
44820
46046
|
res.end("Invalid or expired preview token");
|
|
44821
46047
|
return;
|
|
44822
46048
|
}
|
|
44823
|
-
const
|
|
46049
|
+
const content = renderPreviewOpenDocument(buildPreviewUrlForRequest(token, requestedPath, session));
|
|
46050
|
+
res.writeHead(200, {
|
|
46051
|
+
"Content-Type": "text/html",
|
|
46052
|
+
"Content-Length": content.length,
|
|
46053
|
+
"Cache-Control": "no-cache"
|
|
46054
|
+
});
|
|
46055
|
+
res.end(content);
|
|
46056
|
+
}
|
|
46057
|
+
async function sendPreviewAssetResponse(sessionManager, token, requestedPath, res, req) {
|
|
46058
|
+
const session = sessionManager.get(token);
|
|
46059
|
+
if (!session) {
|
|
46060
|
+
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
46061
|
+
res.end("Invalid or expired preview token");
|
|
46062
|
+
return;
|
|
46063
|
+
}
|
|
46064
|
+
if (session.kind === "service") {
|
|
46065
|
+
await sendServicePreviewResponse(session, requestedPath, req, res);
|
|
46066
|
+
return;
|
|
46067
|
+
}
|
|
46068
|
+
if (!isReadOnlyPreviewMethod(req?.method)) {
|
|
46069
|
+
res.writeHead(405, { "Content-Type": "text/plain" });
|
|
46070
|
+
res.end("Method not allowed");
|
|
46071
|
+
return;
|
|
46072
|
+
}
|
|
46073
|
+
const { pathname } = splitPreviewPathAndSearch(requestedPath ?? session.entryPath);
|
|
46074
|
+
const resolvedRequestedPath = pathname ? decodePreviewPathname(pathname) : session.entryPath;
|
|
44824
46075
|
let resolved;
|
|
44825
46076
|
try {
|
|
44826
46077
|
resolved = resolvePreviewPath(session.rootPath, resolvedRequestedPath).absolutePath;
|
|
@@ -44829,13 +46080,14 @@ function sendPreviewAssetResponse(sessionManager, token, requestedPath, res) {
|
|
|
44829
46080
|
res.end("Invalid path");
|
|
44830
46081
|
return;
|
|
44831
46082
|
}
|
|
44832
|
-
if (!
|
|
46083
|
+
if (!fs17.existsSync(resolved) || !fs17.statSync(resolved).isFile()) {
|
|
44833
46084
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
44834
46085
|
res.end("File not found");
|
|
44835
46086
|
return;
|
|
44836
46087
|
}
|
|
44837
|
-
const
|
|
44838
|
-
const
|
|
46088
|
+
const ext = path18.extname(resolved).toLowerCase();
|
|
46089
|
+
const mime = ext === ".md" || ext === ".mdx" ? "text/html" : getMime(resolved);
|
|
46090
|
+
const content = ext === ".md" || ext === ".mdx" ? renderMarkdownDocument(fs17.readFileSync(resolved, "utf8"), path18.basename(resolved)) : fs17.readFileSync(resolved);
|
|
44839
46091
|
res.writeHead(200, {
|
|
44840
46092
|
"Content-Type": mime,
|
|
44841
46093
|
"Content-Length": content.length,
|
|
@@ -44843,14 +46095,20 @@ function sendPreviewAssetResponse(sessionManager, token, requestedPath, res) {
|
|
|
44843
46095
|
});
|
|
44844
46096
|
res.end(content);
|
|
44845
46097
|
}
|
|
44846
|
-
function handlePreviewRequest(sessionManager, req, res) {
|
|
46098
|
+
async function handlePreviewRequest(sessionManager, req, res) {
|
|
44847
46099
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
44848
|
-
if (!url.pathname.startsWith("/preview/")) {
|
|
46100
|
+
if (!url.pathname.startsWith("/preview/") && !url.pathname.startsWith("/preview-open/")) {
|
|
44849
46101
|
return false;
|
|
44850
46102
|
}
|
|
44851
|
-
|
|
44852
|
-
|
|
44853
|
-
|
|
46103
|
+
const openMatch = url.pathname.match(/^\/preview-open\/([a-f0-9]+)(?:\/(.*))?$/i);
|
|
46104
|
+
if (openMatch?.[1]) {
|
|
46105
|
+
if (!isReadOnlyPreviewMethod(req.method)) {
|
|
46106
|
+
res.writeHead(405, { "Content-Type": "text/plain" });
|
|
46107
|
+
res.end("Method not allowed");
|
|
46108
|
+
return true;
|
|
46109
|
+
}
|
|
46110
|
+
const requestedPath2 = openMatch[2];
|
|
46111
|
+
sendPreviewOpenResponse(sessionManager, openMatch[1], requestedPath2 ? `${requestedPath2}${url.search}` : url.search || void 0, res);
|
|
44854
46112
|
return true;
|
|
44855
46113
|
}
|
|
44856
46114
|
const match = url.pathname.match(/^\/preview\/([a-f0-9]+)(?:\/(.*))?$/i);
|
|
@@ -44860,7 +46118,8 @@ function handlePreviewRequest(sessionManager, req, res) {
|
|
|
44860
46118
|
res.end("Preview not found");
|
|
44861
46119
|
return true;
|
|
44862
46120
|
}
|
|
44863
|
-
|
|
46121
|
+
const requestedPath = match?.[2];
|
|
46122
|
+
await sendPreviewAssetResponse(sessionManager, token, requestedPath ? `${requestedPath}${url.search}` : url.search || void 0, res, req);
|
|
44864
46123
|
return true;
|
|
44865
46124
|
}
|
|
44866
46125
|
|
|
@@ -44925,15 +46184,30 @@ function createPreviewAssetProxyTrace(log2, token, nodeId, requestPath, proxyPat
|
|
|
44925
46184
|
};
|
|
44926
46185
|
}
|
|
44927
46186
|
function parsePreviewRequest(previewUrl) {
|
|
44928
|
-
const
|
|
44929
|
-
const match = pathname.match(/^\/preview\/([a-f0-9]+)(?:\/(.*))?$/i);
|
|
46187
|
+
const url = new URL(previewUrl, "http://localhost");
|
|
46188
|
+
const match = url.pathname.match(/^\/preview\/([a-f0-9]+)(?:\/(.*))?$/i);
|
|
46189
|
+
const token = match?.[1];
|
|
46190
|
+
if (!token) {
|
|
46191
|
+
return null;
|
|
46192
|
+
}
|
|
46193
|
+
const requestedPath = match?.[2];
|
|
46194
|
+
return {
|
|
46195
|
+
token,
|
|
46196
|
+
requestedPath: requestedPath ? `${requestedPath}${url.search}` : url.search || void 0
|
|
46197
|
+
};
|
|
46198
|
+
}
|
|
46199
|
+
function parsePreviewOpenRequest(previewUrl) {
|
|
46200
|
+
const url = new URL(previewUrl, "http://localhost");
|
|
46201
|
+
const match = url.pathname.match(/^\/preview-open\/([a-f0-9]+)(?:\/(.*))?$/i);
|
|
44930
46202
|
const token = match?.[1];
|
|
44931
46203
|
if (!token) {
|
|
44932
46204
|
return null;
|
|
44933
46205
|
}
|
|
46206
|
+
const requestedPath = match?.[2];
|
|
46207
|
+
const suffix = requestedPath !== void 0 ? `/${requestedPath}` : "";
|
|
44934
46208
|
return {
|
|
44935
46209
|
token,
|
|
44936
|
-
|
|
46210
|
+
previewUrl: `/preview/${token}${suffix}${url.search}`
|
|
44937
46211
|
};
|
|
44938
46212
|
}
|
|
44939
46213
|
function extractPreviewToken(previewUrl) {
|
|
@@ -44942,7 +46216,7 @@ function extractPreviewToken(previewUrl) {
|
|
|
44942
46216
|
function buildPreviewAssetProxyPath(token, requestedPath) {
|
|
44943
46217
|
const search = new URLSearchParams({ token });
|
|
44944
46218
|
if (requestedPath) {
|
|
44945
|
-
search.set("path",
|
|
46219
|
+
search.set("path", requestedPath);
|
|
44946
46220
|
}
|
|
44947
46221
|
return `/api/worker/preview-asset?${search.toString()}`;
|
|
44948
46222
|
}
|
|
@@ -44981,12 +46255,34 @@ function rewritePreviewSessionPayloadForProxy(manager, payload, nodeId) {
|
|
|
44981
46255
|
...payload,
|
|
44982
46256
|
previewUrl: buildPreviewUrl("", {
|
|
44983
46257
|
token,
|
|
44984
|
-
entryPath: payload.entryPath
|
|
44985
|
-
|
|
46258
|
+
entryPath: payload.entryPath,
|
|
46259
|
+
kind: payload.kind
|
|
46260
|
+
}),
|
|
46261
|
+
...payload.kind === "service" || payload.openUrl ? {
|
|
46262
|
+
openUrl: buildPreviewOpenUrl("", {
|
|
46263
|
+
token,
|
|
46264
|
+
entryPath: payload.entryPath,
|
|
46265
|
+
kind: payload.kind
|
|
46266
|
+
})
|
|
46267
|
+
} : {}
|
|
44986
46268
|
};
|
|
44987
46269
|
}
|
|
44988
46270
|
async function handlePreviewProxyRequest(manager, nodeRegistry, logger27, req, res) {
|
|
44989
46271
|
const requestPath = req.originalUrl ?? req.url;
|
|
46272
|
+
const previewOpenRequest = parsePreviewOpenRequest(requestPath);
|
|
46273
|
+
if (previewOpenRequest) {
|
|
46274
|
+
const session2 = manager.get(previewOpenRequest.token);
|
|
46275
|
+
if (!session2) {
|
|
46276
|
+
return false;
|
|
46277
|
+
}
|
|
46278
|
+
const content = renderPreviewOpenDocument(previewOpenRequest.previewUrl);
|
|
46279
|
+
res.status(200).set({
|
|
46280
|
+
"Content-Type": "text/html",
|
|
46281
|
+
"Content-Length": String(content.length),
|
|
46282
|
+
"Cache-Control": "no-cache"
|
|
46283
|
+
}).send(content);
|
|
46284
|
+
return true;
|
|
46285
|
+
}
|
|
44990
46286
|
const previewRequest = parsePreviewRequest(requestPath);
|
|
44991
46287
|
if (!previewRequest) {
|
|
44992
46288
|
return false;
|
|
@@ -45002,10 +46298,15 @@ async function handlePreviewProxyRequest(manager, nodeRegistry, logger27, req, r
|
|
|
45002
46298
|
const previewLog = logger27.child("preview-proxy");
|
|
45003
46299
|
const proxyPath = buildPreviewAssetProxyPath(previewRequest.token, previewRequest.requestedPath);
|
|
45004
46300
|
try {
|
|
46301
|
+
const body = await readPreviewRequestBody(req);
|
|
45005
46302
|
const { endpoint, response } = await fetchNodeWithFallback(
|
|
45006
46303
|
node,
|
|
45007
46304
|
proxyPath,
|
|
45008
|
-
|
|
46305
|
+
{
|
|
46306
|
+
method: req.method,
|
|
46307
|
+
headers: buildPreviewWorkerProxyHeaders(req),
|
|
46308
|
+
...body !== void 0 ? { body } : {}
|
|
46309
|
+
},
|
|
45009
46310
|
PREVIEW_ASSET_PROXY_TIMEOUT_MS,
|
|
45010
46311
|
createPreviewAssetProxyTrace(previewLog, previewRequest.token, session.nodeId, requestPath, proxyPath),
|
|
45011
46312
|
{ preferPublicEndpoint: true }
|
|
@@ -45108,13 +46409,13 @@ function getLocalTaskOutputDownload(taskEngine, taskId, filePath) {
|
|
|
45108
46409
|
const rootPath = getTaskOutputRoot(taskEngine, taskId);
|
|
45109
46410
|
try {
|
|
45110
46411
|
const absolutePath = resolveOutputPath(rootPath, filePath);
|
|
45111
|
-
if (!
|
|
46412
|
+
if (!fs18.existsSync(absolutePath) || !fs18.statSync(absolutePath).isFile()) {
|
|
45112
46413
|
throw new MeshyError("TASK_NOT_FOUND", `File not found: ${filePath}`, 404);
|
|
45113
46414
|
}
|
|
45114
46415
|
const { mimeType } = classifyFile(absolutePath);
|
|
45115
|
-
const fileName =
|
|
46416
|
+
const fileName = path19.basename(absolutePath).replace(/"/g, "");
|
|
45116
46417
|
return {
|
|
45117
|
-
content:
|
|
46418
|
+
content: fs18.readFileSync(absolutePath),
|
|
45118
46419
|
headers: {
|
|
45119
46420
|
"Content-Type": mimeType,
|
|
45120
46421
|
"Content-Disposition": `inline; filename="${fileName}"`,
|
|
@@ -45135,16 +46436,21 @@ function getLocalTaskOutputDiff(taskEngine, taskId) {
|
|
|
45135
46436
|
const rootPath = getTaskOutputRoot(taskEngine, taskId);
|
|
45136
46437
|
return getGitDiff(rootPath);
|
|
45137
46438
|
}
|
|
45138
|
-
async function createPreviewSessionPayload(deps, taskId,
|
|
46439
|
+
async function createPreviewSessionPayload(deps, taskId, optionsOrPath, requestOrigin) {
|
|
45139
46440
|
const previewManager = deps.previewSessionManager;
|
|
45140
46441
|
if (!previewManager) {
|
|
45141
46442
|
throw new MeshyError("VALIDATION_ERROR", "Preview not available on this node", 400);
|
|
45142
46443
|
}
|
|
45143
|
-
const
|
|
45144
|
-
|
|
46444
|
+
const options = typeof optionsOrPath === "string" ? { path: optionsOrPath } : optionsOrPath ?? {};
|
|
46445
|
+
getTask(deps.taskEngine, taskId);
|
|
46446
|
+
const session = options.port !== void 0 ? previewManager.create({
|
|
45145
46447
|
taskId,
|
|
45146
|
-
|
|
45147
|
-
entryPath
|
|
46448
|
+
port: options.port,
|
|
46449
|
+
entryPath: options.path
|
|
46450
|
+
}) : previewManager.create({
|
|
46451
|
+
taskId,
|
|
46452
|
+
rootPath: getTaskOutputRoot(deps.taskEngine, taskId),
|
|
46453
|
+
entryPath: options.path
|
|
45148
46454
|
});
|
|
45149
46455
|
const origin = requestOrigin ?? deps.dashboardOrigin ?? deps.localDashboardOrigin;
|
|
45150
46456
|
if (!origin) {
|
|
@@ -45152,293 +46458,13 @@ async function createPreviewSessionPayload(deps, taskId, entryPath, requestOrigi
|
|
|
45152
46458
|
}
|
|
45153
46459
|
return {
|
|
45154
46460
|
previewUrl: buildPreviewUrl(origin, session),
|
|
46461
|
+
...session.kind === "service" ? { openUrl: buildPreviewOpenUrl(origin, session) } : {},
|
|
45155
46462
|
expiresAt: session.expiresAt,
|
|
45156
|
-
entryPath: session.entryPath
|
|
45157
|
-
|
|
45158
|
-
}
|
|
45159
|
-
|
|
45160
|
-
// ../../packages/api/src/node/agent-upgrade-service.ts
|
|
45161
|
-
var import_node_child_process9 = require("child_process");
|
|
45162
|
-
|
|
45163
|
-
// ../../packages/api/src/app/system-info.ts
|
|
45164
|
-
var os6 = __toESM(require("os"), 1);
|
|
45165
|
-
var import_node_child_process8 = require("child_process");
|
|
45166
|
-
var RUNTIME_TOOLS = [
|
|
45167
|
-
{ id: "claude", label: "Claude Code", command: "claude", packageName: "@anthropic-ai/claude-code" },
|
|
45168
|
-
{ id: "codex", label: "Codex", command: "codex", packageName: "@openai/codex" }
|
|
45169
|
-
];
|
|
45170
|
-
var runtimeToolUpdateCache = /* @__PURE__ */ new Map();
|
|
45171
|
-
function clearRuntimeToolUpdateCache(packageName) {
|
|
45172
|
-
if (packageName) {
|
|
45173
|
-
runtimeToolUpdateCache.delete(packageName);
|
|
45174
|
-
return;
|
|
45175
|
-
}
|
|
45176
|
-
runtimeToolUpdateCache.clear();
|
|
45177
|
-
}
|
|
45178
|
-
function runRuntimeToolCommand(command, args, platform2) {
|
|
45179
|
-
const result = (0, import_node_child_process8.spawnSync)(command, args, {
|
|
45180
|
-
encoding: "utf-8",
|
|
45181
|
-
shell: platform2 === "win32" && command !== "where",
|
|
45182
|
-
windowsHide: true,
|
|
45183
|
-
timeout: 2500
|
|
45184
|
-
});
|
|
45185
|
-
return {
|
|
45186
|
-
status: result.status,
|
|
45187
|
-
stdout: typeof result.stdout === "string" ? result.stdout : "",
|
|
45188
|
-
stderr: typeof result.stderr === "string" ? result.stderr : "",
|
|
45189
|
-
error: result.error?.message ?? null
|
|
45190
|
-
};
|
|
45191
|
-
}
|
|
45192
|
-
function normalizeOutput(output) {
|
|
45193
|
-
if (!output) {
|
|
45194
|
-
return null;
|
|
45195
|
-
}
|
|
45196
|
-
const firstLine = output.split(/\r?\n/).map((line) => line.trim()).find(Boolean);
|
|
45197
|
-
return firstLine ?? null;
|
|
45198
|
-
}
|
|
45199
|
-
function formatLocalDate(date) {
|
|
45200
|
-
const year = date.getFullYear();
|
|
45201
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
45202
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
45203
|
-
return `${year}-${month}-${day}`;
|
|
45204
|
-
}
|
|
45205
|
-
function resolveCommandPath(command, commandRunner, platform2) {
|
|
45206
|
-
const lookupCommand = platform2 === "win32" ? "where" : "which";
|
|
45207
|
-
const result = commandRunner(lookupCommand, [command]);
|
|
45208
|
-
if (result.status === 0) {
|
|
45209
|
-
return { path: normalizeOutput(result.stdout) };
|
|
45210
|
-
}
|
|
45211
|
-
return {
|
|
45212
|
-
path: null,
|
|
45213
|
-
detail: normalizeOutput(result.stderr) ?? result.error ?? null
|
|
45214
|
-
};
|
|
45215
|
-
}
|
|
45216
|
-
function extractSemver(value) {
|
|
45217
|
-
return value?.match(/\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?/)?.[0] ?? null;
|
|
45218
|
-
}
|
|
45219
|
-
function normalizePackageVersion(output) {
|
|
45220
|
-
if (!output) return null;
|
|
45221
|
-
const trimmed = output.trim();
|
|
45222
|
-
try {
|
|
45223
|
-
const parsed = JSON.parse(trimmed);
|
|
45224
|
-
if (typeof parsed === "string") {
|
|
45225
|
-
return parsed.trim() || null;
|
|
45226
|
-
}
|
|
45227
|
-
} catch {
|
|
45228
|
-
}
|
|
45229
|
-
return normalizeOutput(trimmed);
|
|
45230
|
-
}
|
|
45231
|
-
function normalizeInstalledPackageVersion(output, packageName) {
|
|
45232
|
-
if (!output) return null;
|
|
45233
|
-
const trimmed = output.trim();
|
|
45234
|
-
try {
|
|
45235
|
-
const parsed = JSON.parse(trimmed);
|
|
45236
|
-
const version2 = parsed.dependencies?.[packageName]?.version;
|
|
45237
|
-
if (typeof version2 === "string") {
|
|
45238
|
-
return version2.trim() || null;
|
|
45239
|
-
}
|
|
45240
|
-
} catch {
|
|
45241
|
-
}
|
|
45242
|
-
return extractSemver(normalizeOutput(trimmed));
|
|
45243
|
-
}
|
|
45244
|
-
function resolveInstalledPackageVersion(definition, commandRunner) {
|
|
45245
|
-
const result = commandRunner("npm", ["list", "-g", definition.packageName, "--depth=0", "--json"]);
|
|
45246
|
-
return normalizeInstalledPackageVersion(result.stdout ?? null, definition.packageName);
|
|
45247
|
-
}
|
|
45248
|
-
function compareSemver(left, right) {
|
|
45249
|
-
const leftParts = left.split(/[.-]/).map((part) => Number.parseInt(part, 10));
|
|
45250
|
-
const rightParts = right.split(/[.-]/).map((part) => Number.parseInt(part, 10));
|
|
45251
|
-
for (let index = 0; index < 3; index += 1) {
|
|
45252
|
-
const delta = (leftParts[index] || 0) - (rightParts[index] || 0);
|
|
45253
|
-
if (delta !== 0) return delta;
|
|
45254
|
-
}
|
|
45255
|
-
return 0;
|
|
45256
|
-
}
|
|
45257
|
-
function checkToolUpdate(definition, installedVersion, checkedAt, commandRunner, checkedOn, updateCache) {
|
|
45258
|
-
const currentVersion = extractSemver(installedVersion);
|
|
45259
|
-
const cached = updateCache.get(definition.packageName);
|
|
45260
|
-
let latestVersion = cached?.latestVersion ?? null;
|
|
45261
|
-
let detail = cached?.detail ?? null;
|
|
45262
|
-
let updateCheckedAt = cached?.checkedAt ?? checkedAt;
|
|
45263
|
-
if (cached?.checkedOn !== checkedOn) {
|
|
45264
|
-
const latestResult = commandRunner("npm", ["view", definition.packageName, "version", "--json"]);
|
|
45265
|
-
latestVersion = latestResult.status === 0 ? normalizePackageVersion(latestResult.stdout ?? null) : null;
|
|
45266
|
-
detail = latestResult.status === 0 ? null : normalizeOutput(latestResult.stderr) ?? latestResult.error ?? "Update check failed";
|
|
45267
|
-
updateCheckedAt = checkedAt;
|
|
45268
|
-
updateCache.set(definition.packageName, {
|
|
45269
|
-
checkedOn,
|
|
45270
|
-
checkedAt,
|
|
45271
|
-
latestVersion,
|
|
45272
|
-
detail
|
|
45273
|
-
});
|
|
45274
|
-
}
|
|
45275
|
-
return {
|
|
45276
|
-
packageName: definition.packageName,
|
|
45277
|
-
currentVersion,
|
|
45278
|
-
latestVersion,
|
|
45279
|
-
updateAvailable: Boolean(currentVersion && latestVersion && compareSemver(latestVersion, currentVersion) > 0),
|
|
45280
|
-
checkedAt: updateCheckedAt,
|
|
45281
|
-
detail
|
|
45282
|
-
};
|
|
45283
|
-
}
|
|
45284
|
-
function inspectTool(definition, commandRunner, checkedAt, checkedOn, updateCache, platform2) {
|
|
45285
|
-
const resolved = resolveCommandPath(definition.command, commandRunner, platform2);
|
|
45286
|
-
if (!resolved.path) {
|
|
45287
|
-
return {
|
|
45288
|
-
id: definition.id,
|
|
45289
|
-
label: definition.label,
|
|
45290
|
-
command: definition.command,
|
|
45291
|
-
available: false,
|
|
45292
|
-
path: null,
|
|
45293
|
-
version: null,
|
|
45294
|
-
checkedAt,
|
|
45295
|
-
detail: resolved.detail ?? "Command not found on PATH",
|
|
45296
|
-
update: checkToolUpdate(definition, null, checkedAt, commandRunner, checkedOn, updateCache)
|
|
45297
|
-
};
|
|
45298
|
-
}
|
|
45299
|
-
const versionResult = commandRunner(definition.command, ["--version"]);
|
|
45300
|
-
const commandVersion = normalizeOutput(versionResult.stdout) ?? normalizeOutput(versionResult.stderr);
|
|
45301
|
-
const version2 = extractSemver(commandVersion) ? commandVersion : resolveInstalledPackageVersion(definition, commandRunner);
|
|
45302
|
-
const detail = versionResult.status === 0 ? null : normalizeOutput(versionResult.stderr) ?? versionResult.error ?? "Version check failed";
|
|
45303
|
-
return {
|
|
45304
|
-
id: definition.id,
|
|
45305
|
-
label: definition.label,
|
|
45306
|
-
command: definition.command,
|
|
45307
|
-
available: true,
|
|
45308
|
-
path: resolved.path,
|
|
45309
|
-
version: version2,
|
|
45310
|
-
checkedAt,
|
|
45311
|
-
detail,
|
|
45312
|
-
update: checkToolUpdate(definition, version2, checkedAt, commandRunner, checkedOn, updateCache)
|
|
45313
|
-
};
|
|
45314
|
-
}
|
|
45315
|
-
function inspectRuntimeTools(options = {}) {
|
|
45316
|
-
const platform2 = options.platform ?? process.platform;
|
|
45317
|
-
const commandRunner = options.commandRunner ?? ((command, args) => runRuntimeToolCommand(command, args, platform2));
|
|
45318
|
-
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
45319
|
-
const checkedAt = now.toISOString();
|
|
45320
|
-
const checkedOn = formatLocalDate(now);
|
|
45321
|
-
const updateCache = options.updateCache ?? runtimeToolUpdateCache;
|
|
45322
|
-
return RUNTIME_TOOLS.map((definition) => inspectTool(definition, commandRunner, checkedAt, checkedOn, updateCache, platform2));
|
|
45323
|
-
}
|
|
45324
|
-
function getOsSnapshot() {
|
|
45325
|
-
const cpus2 = os6.cpus();
|
|
45326
|
-
return {
|
|
45327
|
-
platform: os6.platform(),
|
|
45328
|
-
release: os6.release(),
|
|
45329
|
-
arch: os6.arch(),
|
|
45330
|
-
hostname: os6.hostname(),
|
|
45331
|
-
cpuModel: cpus2[0]?.model ?? null,
|
|
45332
|
-
cpuCount: cpus2.length,
|
|
45333
|
-
totalMemoryBytes: os6.totalmem(),
|
|
45334
|
-
freeMemoryBytes: os6.freemem()
|
|
45335
|
-
};
|
|
45336
|
-
}
|
|
45337
|
-
function buildNodeSettingsSnapshot(options) {
|
|
45338
|
-
const uptime = process.uptime();
|
|
45339
|
-
const runtimeMetadata = options.runtimeMetadata;
|
|
45340
|
-
const agents = (options.inspectRuntimeTools?.() ?? inspectRuntimeTools()).map((agent) => ({
|
|
45341
|
-
...agent,
|
|
45342
|
-
metadataStatus: runtimeMetadata?.components?.[agent.id]?.status ?? null
|
|
45343
|
-
}));
|
|
45344
|
-
return {
|
|
45345
|
-
collectedAt: Date.now(),
|
|
45346
|
-
version: runtimeMetadata?.packageVersion ?? "0.1.0",
|
|
45347
|
-
packageName: runtimeMetadata?.packageName ?? "meshy",
|
|
45348
|
-
uptime,
|
|
45349
|
-
auth: options.auth,
|
|
45350
|
-
os: getOsSnapshot(),
|
|
45351
|
-
runtime: {
|
|
45352
|
-
nodeVersion: process.version,
|
|
45353
|
-
pid: process.pid,
|
|
45354
|
-
startedAt: Date.now() - Math.floor(uptime * 1e3),
|
|
45355
|
-
cwd: process.cwd(),
|
|
45356
|
-
workDir: options.workDir ?? null,
|
|
45357
|
-
storagePath: options.storagePath ?? null,
|
|
45358
|
-
localDashboardOrigin: options.localDashboardOrigin ?? null
|
|
45359
|
-
},
|
|
45360
|
-
agents,
|
|
45361
|
-
startupRequirements: {
|
|
45362
|
-
lastCheckedAt: runtimeMetadata?.startupRequirementsLastCheckedAt,
|
|
45363
|
-
lastCheckedOn: runtimeMetadata?.startupRequirementsLastCheckedOn,
|
|
45364
|
-
components: runtimeMetadata?.components ?? {}
|
|
45365
|
-
},
|
|
45366
|
-
components: runtimeMetadata?.components ?? {},
|
|
45367
|
-
repository: runtimeMetadata?.repository ?? {},
|
|
45368
|
-
packages: runtimeMetadata?.packages ?? {}
|
|
45369
|
-
};
|
|
45370
|
-
}
|
|
45371
|
-
|
|
45372
|
-
// ../../packages/api/src/node/agent-upgrade-service.ts
|
|
45373
|
-
var AGENT_PACKAGES = {
|
|
45374
|
-
claude: "@anthropic-ai/claude-code",
|
|
45375
|
-
codex: "@openai/codex"
|
|
45376
|
-
};
|
|
45377
|
-
var OUTPUT_LIMIT = 4e3;
|
|
45378
|
-
function summarizeOutput(value) {
|
|
45379
|
-
const text = value ?? "";
|
|
45380
|
-
return text.length > OUTPUT_LIMIT ? `${text.slice(0, OUTPUT_LIMIT)}\u2026` : text;
|
|
45381
|
-
}
|
|
45382
|
-
function defaultCommandRunner(command, args) {
|
|
45383
|
-
const result = (0, import_node_child_process9.spawnSync)(command, args, {
|
|
45384
|
-
encoding: "utf-8",
|
|
45385
|
-
shell: process.platform === "win32",
|
|
45386
|
-
windowsHide: true,
|
|
45387
|
-
timeout: 18e4
|
|
45388
|
-
});
|
|
45389
|
-
return {
|
|
45390
|
-
status: result.status,
|
|
45391
|
-
stdout: typeof result.stdout === "string" ? result.stdout : "",
|
|
45392
|
-
stderr: typeof result.stderr === "string" ? result.stderr : "",
|
|
45393
|
-
error: result.error?.message ?? null
|
|
45394
|
-
};
|
|
45395
|
-
}
|
|
45396
|
-
function isRuntimeAgentId(value) {
|
|
45397
|
-
return value === "claude" || value === "codex";
|
|
45398
|
-
}
|
|
45399
|
-
function buildUpgradeArgs(agent, packageName) {
|
|
45400
|
-
const args = ["install", "-g", `${packageName}@latest`];
|
|
45401
|
-
if (agent === "claude") {
|
|
45402
|
-
args.push("--include=optional", "--ignore-scripts=false");
|
|
45403
|
-
}
|
|
45404
|
-
return args;
|
|
45405
|
-
}
|
|
45406
|
-
function upgradeRuntimeAgent(agent, options = {}) {
|
|
45407
|
-
const packageName = AGENT_PACKAGES[agent];
|
|
45408
|
-
if (!packageName) {
|
|
45409
|
-
throw new MeshyError("VALIDATION_ERROR", `Unsupported upgrade agent: ${agent}`, 400);
|
|
45410
|
-
}
|
|
45411
|
-
const command = "npm";
|
|
45412
|
-
const args = buildUpgradeArgs(agent, packageName);
|
|
45413
|
-
const result = (options.commandRunner ?? defaultCommandRunner)(command, args);
|
|
45414
|
-
const ok = result.status === 0 && !result.error;
|
|
45415
|
-
if (ok) {
|
|
45416
|
-
clearRuntimeToolUpdateCache(packageName);
|
|
45417
|
-
}
|
|
45418
|
-
const detail = result.error ?? (summarizeOutput(result.stderr) || "Agent upgrade failed");
|
|
45419
|
-
return {
|
|
45420
|
-
ok,
|
|
45421
|
-
agent,
|
|
45422
|
-
packageName,
|
|
45423
|
-
command,
|
|
45424
|
-
args,
|
|
45425
|
-
status: result.status,
|
|
45426
|
-
stdout: summarizeOutput(result.stdout),
|
|
45427
|
-
stderr: summarizeOutput(result.stderr),
|
|
45428
|
-
detail: ok ? null : detail
|
|
46463
|
+
entryPath: session.entryPath,
|
|
46464
|
+
kind: session.kind,
|
|
46465
|
+
...session.kind === "service" ? { port: session.port } : {}
|
|
45429
46466
|
};
|
|
45430
46467
|
}
|
|
45431
|
-
function upgradeRuntimeAgentForDeps(deps, agent) {
|
|
45432
|
-
const result = deps.upgradeRuntimeAgent?.(agent) ?? upgradeRuntimeAgent(agent);
|
|
45433
|
-
if (result.ok) {
|
|
45434
|
-
const settingsSnapshot = deps.refreshSettingsSnapshot?.();
|
|
45435
|
-
if (settingsSnapshot) {
|
|
45436
|
-
deps.nodeRegistry.updateSettingsSnapshot(deps.nodeRegistry.getSelf().id, settingsSnapshot);
|
|
45437
|
-
return { ...result, settingsSnapshot };
|
|
45438
|
-
}
|
|
45439
|
-
}
|
|
45440
|
-
return result;
|
|
45441
|
-
}
|
|
45442
46468
|
|
|
45443
46469
|
// ../../packages/api/src/node/worker-control.ts
|
|
45444
46470
|
function jsonResponse(requestId, statusCode, body) {
|
|
@@ -45607,6 +46633,15 @@ async function executeWorkerControlRequest(deps, request) {
|
|
|
45607
46633
|
response = jsonResponse(request.id, 200, upgradeRuntimeAgentForDeps(deps, agent));
|
|
45608
46634
|
break;
|
|
45609
46635
|
}
|
|
46636
|
+
case "node.operation.execute": {
|
|
46637
|
+
const operation = payloadValue(request, "operation", null);
|
|
46638
|
+
if (!operation || typeof operation !== "object") {
|
|
46639
|
+
throw new MeshyError("VALIDATION_ERROR", "node.operation.execute requires an operation payload", 400);
|
|
46640
|
+
}
|
|
46641
|
+
const accepted = getNodeOperationService(deps).accept(operation);
|
|
46642
|
+
response = jsonResponse(request.id, 202, { operationId: accepted.id, accepted: true });
|
|
46643
|
+
break;
|
|
46644
|
+
}
|
|
45610
46645
|
case "task.cancel": {
|
|
45611
46646
|
const taskId = payloadValue(request, "taskId", "");
|
|
45612
46647
|
const result = cancelTaskOnCurrentNode({
|
|
@@ -45627,6 +46662,17 @@ async function executeWorkerControlRequest(deps, request) {
|
|
|
45627
46662
|
});
|
|
45628
46663
|
break;
|
|
45629
46664
|
}
|
|
46665
|
+
case "task.delete": {
|
|
46666
|
+
const taskId = payloadValue(request, "taskId", "");
|
|
46667
|
+
const deleted = deps.taskEngine.deleteTask(taskId);
|
|
46668
|
+
response = jsonResponse(request.id, 200, {
|
|
46669
|
+
ok: true,
|
|
46670
|
+
taskId,
|
|
46671
|
+
deleted,
|
|
46672
|
+
missing: !deleted
|
|
46673
|
+
});
|
|
46674
|
+
break;
|
|
46675
|
+
}
|
|
45630
46676
|
case "task.logs": {
|
|
45631
46677
|
const taskId = payloadValue(request, "taskId", "");
|
|
45632
46678
|
const task = deps.taskEngine.getTask(taskId);
|
|
@@ -45675,10 +46721,15 @@ async function executeWorkerControlRequest(deps, request) {
|
|
|
45675
46721
|
break;
|
|
45676
46722
|
}
|
|
45677
46723
|
case "task.preview.create": {
|
|
46724
|
+
const previewPath = payloadValue(request, "path", void 0);
|
|
46725
|
+
const previewPort = payloadValue(request, "port", void 0);
|
|
45678
46726
|
response = jsonResponse(
|
|
45679
46727
|
request.id,
|
|
45680
46728
|
200,
|
|
45681
|
-
await createPreviewSessionPayload(deps, payloadValue(request, "taskId", ""),
|
|
46729
|
+
await createPreviewSessionPayload(deps, payloadValue(request, "taskId", ""), {
|
|
46730
|
+
path: typeof previewPath === "string" ? previewPath : void 0,
|
|
46731
|
+
port: typeof previewPort === "number" ? previewPort : void 0
|
|
46732
|
+
})
|
|
45682
46733
|
);
|
|
45683
46734
|
break;
|
|
45684
46735
|
}
|
|
@@ -45751,58 +46802,10 @@ function sendLocalNodeNativeSessions(req, res, nodeId, options = {}) {
|
|
|
45751
46802
|
}
|
|
45752
46803
|
|
|
45753
46804
|
// ../../packages/api/src/routes/node-agent-upgrade.ts
|
|
45754
|
-
function isRecord5(value) {
|
|
45755
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45756
|
-
}
|
|
45757
|
-
function readSettingsSnapshot(value) {
|
|
45758
|
-
if (!isRecord5(value)) return void 0;
|
|
45759
|
-
const snapshot = value.settingsSnapshot;
|
|
45760
|
-
if (!isRecord5(snapshot)) return void 0;
|
|
45761
|
-
return snapshot;
|
|
45762
|
-
}
|
|
45763
|
-
function applySyncedSettingsSnapshot(deps, nodeId, body) {
|
|
45764
|
-
const settingsSnapshot = readSettingsSnapshot(body);
|
|
45765
|
-
if (settingsSnapshot) {
|
|
45766
|
-
deps.nodeRegistry.updateSettingsSnapshot(nodeId, settingsSnapshot);
|
|
45767
|
-
}
|
|
45768
|
-
}
|
|
45769
46805
|
function parseAgent(value) {
|
|
45770
46806
|
if (isRuntimeAgentId(value)) return value;
|
|
45771
46807
|
throw new MeshyError("VALIDATION_ERROR", `Unsupported upgrade agent: ${value}`, 400);
|
|
45772
46808
|
}
|
|
45773
|
-
function upgradeSelfNode(deps, nodeId, agent) {
|
|
45774
|
-
const result = upgradeRuntimeAgentForDeps(deps, agent);
|
|
45775
|
-
applySyncedSettingsSnapshot(deps, nodeId, result);
|
|
45776
|
-
return result;
|
|
45777
|
-
}
|
|
45778
|
-
async function fallbackUpgrade(deps, res, nodeId, agent) {
|
|
45779
|
-
if (!canRequestNodeMessage(deps.heartbeat)) {
|
|
45780
|
-
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} to upgrade ${agent}`, 502);
|
|
45781
|
-
}
|
|
45782
|
-
const controlResponse = await requestFallbackNodeMessage(
|
|
45783
|
-
deps.heartbeat,
|
|
45784
|
-
nodeId,
|
|
45785
|
-
createNodeMessage("node.agent.upgrade", { agent }, { expectsResponse: true })
|
|
45786
|
-
);
|
|
45787
|
-
applySyncedSettingsSnapshot(deps, nodeId, controlResponse.body);
|
|
45788
|
-
sendWorkerControlResponse(res, controlResponse);
|
|
45789
|
-
}
|
|
45790
|
-
async function proxyUpgrade(deps, nodeId, agent) {
|
|
45791
|
-
const node = deps.nodeRegistry.getNode(nodeId);
|
|
45792
|
-
if (!node) {
|
|
45793
|
-
throw new MeshyError("NODE_NOT_FOUND", `Node ${nodeId} not found`, 404);
|
|
45794
|
-
}
|
|
45795
|
-
const { response } = await fetchNodeWithFallback(node, `/api/nodes/${nodeId}/agents/${agent}/upgrade`, {
|
|
45796
|
-
method: "POST",
|
|
45797
|
-
headers: { "Content-Type": "application/json" }
|
|
45798
|
-
}, void 0, void 0, { preferPublicEndpoint: true });
|
|
45799
|
-
const body = await response.json().catch(() => ({ error: response.statusText }));
|
|
45800
|
-
if (!response.ok) {
|
|
45801
|
-
throw new MeshyError("NODE_OFFLINE", `Remote node returned ${response.status}`, response.status, body);
|
|
45802
|
-
}
|
|
45803
|
-
applySyncedSettingsSnapshot(deps, nodeId, body);
|
|
45804
|
-
return body;
|
|
45805
|
-
}
|
|
45806
46809
|
async function sendNodeAgentUpgrade(req, res, nodeId, agentParam) {
|
|
45807
46810
|
const deps = req.app.locals.deps;
|
|
45808
46811
|
const agent = parseAgent(agentParam);
|
|
@@ -45811,21 +46814,23 @@ async function sendNodeAgentUpgrade(req, res, nodeId, agentParam) {
|
|
|
45811
46814
|
if (!isSelf && !deps.election.isLeader()) {
|
|
45812
46815
|
throw new MeshyError("NOT_LEADER", "Only the leader can upgrade agents on other nodes", 403);
|
|
45813
46816
|
}
|
|
45814
|
-
|
|
45815
|
-
|
|
45816
|
-
|
|
45817
|
-
}
|
|
45818
|
-
const canPushToNode = deps.heartbeat?.canPushToNode?.(nodeId) ?? true;
|
|
45819
|
-
if (!canPushToNode) {
|
|
45820
|
-
await fallbackUpgrade(deps, res, nodeId, agent);
|
|
45821
|
-
return;
|
|
46817
|
+
const node = isSelf ? self2 : deps.nodeRegistry.getNode(nodeId);
|
|
46818
|
+
if (!node) {
|
|
46819
|
+
throw new MeshyError("NODE_NOT_FOUND", `Node ${nodeId} not found`, 404);
|
|
45822
46820
|
}
|
|
45823
|
-
|
|
45824
|
-
|
|
45825
|
-
|
|
45826
|
-
|
|
45827
|
-
|
|
46821
|
+
const operations = getNodeOperationService(deps);
|
|
46822
|
+
const operation = operations.create("agent.upgrade", nodeId, { agent });
|
|
46823
|
+
if (isSelf) {
|
|
46824
|
+
operations.runLocal(operation.id);
|
|
46825
|
+
} else {
|
|
46826
|
+
try {
|
|
46827
|
+
await dispatchNodeOperation(deps, operation, node);
|
|
46828
|
+
} catch (err) {
|
|
46829
|
+
operations.markFailed(operation.id, err instanceof Error ? err.message : String(err));
|
|
46830
|
+
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} to upgrade ${agent}`, 502);
|
|
46831
|
+
}
|
|
45828
46832
|
}
|
|
46833
|
+
res.status(202).json(operation);
|
|
45829
46834
|
}
|
|
45830
46835
|
|
|
45831
46836
|
// ../../packages/api/src/routes/nodes.ts
|
|
@@ -46022,79 +47027,6 @@ async function maybeHandleRemoteNodeWorkDirBranchInfoRequest(req, res, nodeId) {
|
|
|
46022
47027
|
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} to inspect its git branch`, 502);
|
|
46023
47028
|
}
|
|
46024
47029
|
}
|
|
46025
|
-
async function maybeHandleRemoteNodeWorkDirBranchCreateRequest(req, res, nodeId) {
|
|
46026
|
-
const body = CreateNodeWorkDirBranchBody.parse(req.body);
|
|
46027
|
-
const { nodeRegistry, heartbeat, logger: rootLogger } = req.app.locals.deps;
|
|
46028
|
-
const selfId = nodeRegistry.getSelf().id;
|
|
46029
|
-
if (nodeId === selfId) {
|
|
46030
|
-
return false;
|
|
46031
|
-
}
|
|
46032
|
-
const node = nodeRegistry.getNode(nodeId);
|
|
46033
|
-
if (!node) {
|
|
46034
|
-
throw new MeshyError("NODE_NOT_FOUND", `Node ${nodeId} not found`, 404);
|
|
46035
|
-
}
|
|
46036
|
-
const log2 = rootLogger.child("nodes/workdir-branch-create");
|
|
46037
|
-
const proxyPath = req.originalUrl ?? `/api/nodes/${nodeId}/workdir/branch`;
|
|
46038
|
-
const fallbackRequest = createNodeMessage("node.workdir.branch-create", {
|
|
46039
|
-
path: body.path,
|
|
46040
|
-
branchName: body.branchName,
|
|
46041
|
-
startPoint: body.startPoint,
|
|
46042
|
-
limit: body.limit,
|
|
46043
|
-
offset: body.offset,
|
|
46044
|
-
allowAbsolute: body.allowAbsolute
|
|
46045
|
-
}, { expectsResponse: true });
|
|
46046
|
-
const canPushToNode = heartbeat?.canPushToNode?.(nodeId) ?? true;
|
|
46047
|
-
if (!canPushToNode && canRequestNodeMessage(heartbeat)) {
|
|
46048
|
-
log2.warn("node workdir branch create request falling back to keepalive control", {
|
|
46049
|
-
nodeId,
|
|
46050
|
-
proxyPath
|
|
46051
|
-
});
|
|
46052
|
-
const controlResponse = await requestFallbackNodeMessage(heartbeat, nodeId, fallbackRequest);
|
|
46053
|
-
sendWorkerControlResponse(res, controlResponse);
|
|
46054
|
-
return true;
|
|
46055
|
-
}
|
|
46056
|
-
try {
|
|
46057
|
-
const { endpoint, response } = await fetchNodeWithFallback(
|
|
46058
|
-
node,
|
|
46059
|
-
proxyPath,
|
|
46060
|
-
{
|
|
46061
|
-
method: "POST",
|
|
46062
|
-
headers: { "Content-Type": "application/json" },
|
|
46063
|
-
body: JSON.stringify(body)
|
|
46064
|
-
},
|
|
46065
|
-
NODE_WORKDIR_BRANCH_PROXY_TIMEOUT_MS,
|
|
46066
|
-
createNodeWorkdirProxyTrace(log2, nodeId, proxyPath),
|
|
46067
|
-
{ preferPublicEndpoint: true }
|
|
46068
|
-
);
|
|
46069
|
-
log2.debug("proxying node workdir branch create request", {
|
|
46070
|
-
nodeId,
|
|
46071
|
-
endpoint,
|
|
46072
|
-
proxyPath
|
|
46073
|
-
});
|
|
46074
|
-
await sendProxyResponse(res, response);
|
|
46075
|
-
return true;
|
|
46076
|
-
} catch (err) {
|
|
46077
|
-
const errorDetails = describeProxyError2(err);
|
|
46078
|
-
log2.warn("node workdir branch create proxy error", {
|
|
46079
|
-
nodeId,
|
|
46080
|
-
proxyPath,
|
|
46081
|
-
timeoutMs: NODE_WORKDIR_BRANCH_PROXY_TIMEOUT_MS,
|
|
46082
|
-
...errorDetails
|
|
46083
|
-
});
|
|
46084
|
-
if (canRequestNodeMessage(heartbeat)) {
|
|
46085
|
-
log2.warn("node workdir branch create proxy failed, falling back to keepalive control", {
|
|
46086
|
-
nodeId,
|
|
46087
|
-
proxyPath,
|
|
46088
|
-
timeoutMs: NODE_WORKDIR_BRANCH_PROXY_TIMEOUT_MS,
|
|
46089
|
-
...errorDetails
|
|
46090
|
-
});
|
|
46091
|
-
const controlResponse = await requestFallbackNodeMessage(heartbeat, nodeId, fallbackRequest);
|
|
46092
|
-
sendWorkerControlResponse(res, controlResponse);
|
|
46093
|
-
return true;
|
|
46094
|
-
}
|
|
46095
|
-
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} to create a git branch`, 502);
|
|
46096
|
-
}
|
|
46097
|
-
}
|
|
46098
47030
|
async function maybeHandleRemoteNodeNativeSessionsRequest(req, res, nodeId) {
|
|
46099
47031
|
const query = NodeNativeSessionsQuery.parse(req.query);
|
|
46100
47032
|
const { nodeRegistry, heartbeat, logger: rootLogger } = req.app.locals.deps;
|
|
@@ -46228,11 +47160,7 @@ function createNodeRoutes() {
|
|
|
46228
47160
|
}));
|
|
46229
47161
|
router.post("/:id/workdir/branch", asyncHandler3(async (req, res) => {
|
|
46230
47162
|
const nodeId = req.params.id;
|
|
46231
|
-
|
|
46232
|
-
if (handled) {
|
|
46233
|
-
return;
|
|
46234
|
-
}
|
|
46235
|
-
sendLocalNodeWorkDirBranchCreate(req, res, nodeId);
|
|
47163
|
+
await sendNodeWorkDirBranchCreateOperation(req, res, nodeId);
|
|
46236
47164
|
}));
|
|
46237
47165
|
router.post("/:id/agents/:agent/upgrade", asyncHandler3(async (req, res) => {
|
|
46238
47166
|
await sendNodeAgentUpgrade(req, res, req.params.id, req.params.agent);
|
|
@@ -47180,12 +48108,12 @@ function createTaskOutputRoutes(options = {}) {
|
|
|
47180
48108
|
method: "POST",
|
|
47181
48109
|
headers: { "Content-Type": "application/json" },
|
|
47182
48110
|
body: JSON.stringify(body)
|
|
47183
|
-
}, createNodeMessage("task.preview.create", { taskId, path: body.path }, { expectsResponse: true }));
|
|
48111
|
+
}, createNodeMessage("task.preview.create", { taskId, path: body.path, port: body.port }, { expectsResponse: true }));
|
|
47184
48112
|
if (handled) {
|
|
47185
48113
|
return;
|
|
47186
48114
|
}
|
|
47187
48115
|
}
|
|
47188
|
-
res.json(await createPreviewSessionPayload(req.app.locals.deps, taskId, body
|
|
48116
|
+
res.json(await createPreviewSessionPayload(req.app.locals.deps, taskId, body, resolveRequestOrigin(req)));
|
|
47189
48117
|
}));
|
|
47190
48118
|
return router;
|
|
47191
48119
|
}
|
|
@@ -47194,6 +48122,7 @@ function createTaskOutputRoutes(options = {}) {
|
|
|
47194
48122
|
var TERMINAL_STATUSES3 = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "archived"]);
|
|
47195
48123
|
var ARCHIVABLE_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "archived"]);
|
|
47196
48124
|
var ACTIVE_STATUSES = /* @__PURE__ */ new Set(["pending", "assigned", "running"]);
|
|
48125
|
+
var TASK_DELETE_NOTIFY_TIMEOUT_MS = 1500;
|
|
47197
48126
|
function shouldGenerateTitle(task) {
|
|
47198
48127
|
return task.payload.titleSource === "derived";
|
|
47199
48128
|
}
|
|
@@ -47307,6 +48236,39 @@ function toTaskResponse(task, nodeRegistry, taskEngine, shareOrigin) {
|
|
|
47307
48236
|
function buildShareUrl(origin, shareId) {
|
|
47308
48237
|
return `${origin.replace(/\/+$/, "")}/shared/tasks/${encodeURIComponent(shareId)}`;
|
|
47309
48238
|
}
|
|
48239
|
+
async function notifyAssignedWorkerTaskDeleted(deps, task) {
|
|
48240
|
+
if (!task.assignedTo || task.assignedTo === deps.nodeRegistry.getSelf()?.id) {
|
|
48241
|
+
return;
|
|
48242
|
+
}
|
|
48243
|
+
const node = deps.nodeRegistry.getNode(task.assignedTo);
|
|
48244
|
+
const log2 = deps.logger.child("tasks/delete");
|
|
48245
|
+
if (!node) {
|
|
48246
|
+
log2.warn("skipping worker task delete notification because assigned node is missing", {
|
|
48247
|
+
taskId: task.id,
|
|
48248
|
+
assignedTo: task.assignedTo
|
|
48249
|
+
});
|
|
48250
|
+
return;
|
|
48251
|
+
}
|
|
48252
|
+
try {
|
|
48253
|
+
const client = new NodeMessageClient({
|
|
48254
|
+
heartbeat: deps.heartbeat,
|
|
48255
|
+
logger: deps.logger,
|
|
48256
|
+
timeoutMs: TASK_DELETE_NOTIFY_TIMEOUT_MS
|
|
48257
|
+
});
|
|
48258
|
+
const delivery = await client.send(node, createNodeMessage("task.delete", { taskId: task.id }));
|
|
48259
|
+
log2.info("notified assigned worker of task delete", {
|
|
48260
|
+
taskId: task.id,
|
|
48261
|
+
assignedTo: task.assignedTo,
|
|
48262
|
+
queued: delivery.queued
|
|
48263
|
+
});
|
|
48264
|
+
} catch (err) {
|
|
48265
|
+
log2.warn("failed to notify assigned worker of task delete", {
|
|
48266
|
+
taskId: task.id,
|
|
48267
|
+
assignedTo: task.assignedTo,
|
|
48268
|
+
error: err instanceof Error ? err.message : String(err)
|
|
48269
|
+
});
|
|
48270
|
+
}
|
|
48271
|
+
}
|
|
47310
48272
|
function createTaskRoutes() {
|
|
47311
48273
|
const router = (0, import_express8.Router)();
|
|
47312
48274
|
router.post("/", asyncHandler6(async (req, res) => {
|
|
@@ -47358,16 +48320,21 @@ function createTaskRoutes() {
|
|
|
47358
48320
|
});
|
|
47359
48321
|
}));
|
|
47360
48322
|
router.post("/batch/delete", asyncHandler6(async (req, res) => {
|
|
47361
|
-
const
|
|
48323
|
+
const deps = req.app.locals.deps;
|
|
48324
|
+
const { taskEngine } = deps;
|
|
47362
48325
|
const { ids } = BatchTaskIdsBody.parse(req.body);
|
|
48326
|
+
const deletedTasks = [];
|
|
47363
48327
|
const results = ids.map((id) => {
|
|
47364
48328
|
try {
|
|
48329
|
+
const task = taskEngine.getTask(id);
|
|
47365
48330
|
const ok = taskEngine.deleteTask(id);
|
|
48331
|
+
if (ok && task) deletedTasks.push(task);
|
|
47366
48332
|
return ok ? { id, ok: true } : { id, ok: false, error: "Task not found" };
|
|
47367
48333
|
} catch (err) {
|
|
47368
48334
|
return { id, ok: false, error: err instanceof Error ? err.message : "Unknown error" };
|
|
47369
48335
|
}
|
|
47370
48336
|
});
|
|
48337
|
+
await Promise.all(deletedTasks.map((task) => notifyAssignedWorkerTaskDeleted(deps, task)));
|
|
47371
48338
|
res.json({ results });
|
|
47372
48339
|
}));
|
|
47373
48340
|
router.post("/batch/archive", asyncHandler6(async (req, res) => {
|
|
@@ -47489,12 +48456,17 @@ function createTaskRoutes() {
|
|
|
47489
48456
|
res.json(withAssignedNodeMetadata(task, nodeRegistry));
|
|
47490
48457
|
}));
|
|
47491
48458
|
router.delete("/:id", asyncHandler6(async (req, res) => {
|
|
47492
|
-
const
|
|
48459
|
+
const deps = req.app.locals.deps;
|
|
48460
|
+
const { taskEngine } = deps;
|
|
47493
48461
|
const taskId = req.params.id;
|
|
48462
|
+
const task = taskEngine.getTask(taskId);
|
|
47494
48463
|
const result = taskEngine.deleteTask(taskId);
|
|
47495
48464
|
if (!result) {
|
|
47496
48465
|
throw new MeshyError("TASK_NOT_FOUND", `Task ${taskId} not found`, 404);
|
|
47497
48466
|
}
|
|
48467
|
+
if (task) {
|
|
48468
|
+
await notifyAssignedWorkerTaskDeleted(deps, task);
|
|
48469
|
+
}
|
|
47498
48470
|
res.json({ ok: true });
|
|
47499
48471
|
}));
|
|
47500
48472
|
router.post("/:id/cancel", asyncHandler6(async (req, res) => {
|
|
@@ -47750,13 +48722,16 @@ function createSharedRoutes() {
|
|
|
47750
48722
|
const shareId = req.params.shareId;
|
|
47751
48723
|
const share = assertActiveShare(taskEngine.getTaskShare(shareId));
|
|
47752
48724
|
assertFilesPreviewShare(share);
|
|
48725
|
+
if (body.port !== void 0) {
|
|
48726
|
+
throw new MeshyError("VALIDATION_ERROR", "Shared previews only support task output files", 403);
|
|
48727
|
+
}
|
|
47753
48728
|
const handled = await maybeHandleRemoteTaskOutputRequest(req, res, share.taskId, "/preview-sessions", {
|
|
47754
48729
|
method: "POST",
|
|
47755
48730
|
headers: { "Content-Type": "application/json" },
|
|
47756
48731
|
body: JSON.stringify(body)
|
|
47757
48732
|
}, createNodeMessage("task.preview.create", { taskId: share.taskId, path: body.path }, { expectsResponse: true }));
|
|
47758
48733
|
if (handled) return;
|
|
47759
|
-
res.json(await createPreviewSessionPayload(req.app.locals.deps, share.taskId, body
|
|
48734
|
+
res.json(await createPreviewSessionPayload(req.app.locals.deps, share.taskId, body, resolveRequestOrigin(req)));
|
|
47760
48735
|
}));
|
|
47761
48736
|
return router;
|
|
47762
48737
|
}
|
|
@@ -47774,6 +48749,15 @@ function asyncHandler8(fn) {
|
|
|
47774
48749
|
}
|
|
47775
48750
|
function createWorkerRoutes() {
|
|
47776
48751
|
const router = (0, import_express10.Router)();
|
|
48752
|
+
router.post("/node-operations/:id", asyncHandler8(async (req, res) => {
|
|
48753
|
+
const deps = req.app.locals.deps;
|
|
48754
|
+
const operation = req.body;
|
|
48755
|
+
if (!operation || operation.id !== req.params.id) {
|
|
48756
|
+
throw new MeshyError("VALIDATION_ERROR", "Node operation update id mismatch", 400);
|
|
48757
|
+
}
|
|
48758
|
+
const saved = getNodeOperationService(deps).applyRemoteUpdate(operation);
|
|
48759
|
+
res.json({ ok: true, operation: saved });
|
|
48760
|
+
}));
|
|
47777
48761
|
router.post("/execute", asyncHandler8(async (req, res) => {
|
|
47778
48762
|
const { taskEngine, engineRegistry, nodeRegistry, eventBus, logger: rootLogger, workDir } = req.app.locals.deps;
|
|
47779
48763
|
const log2 = rootLogger.child("worker/execute");
|
|
@@ -47945,20 +48929,20 @@ function createWorkerRoutes() {
|
|
|
47945
48929
|
const payload = await createPreviewSessionPayload(
|
|
47946
48930
|
req.app.locals.deps,
|
|
47947
48931
|
body.taskId,
|
|
47948
|
-
body
|
|
48932
|
+
body,
|
|
47949
48933
|
resolveRequestOrigin(req)
|
|
47950
48934
|
);
|
|
47951
|
-
log2.info("created preview session", { taskId: body.taskId, entryPath: payload.entryPath });
|
|
48935
|
+
log2.info("created preview session", { taskId: body.taskId, entryPath: payload.entryPath, kind: payload.kind, port: payload.port });
|
|
47952
48936
|
res.json(payload);
|
|
47953
48937
|
}));
|
|
47954
|
-
router.
|
|
48938
|
+
router.all("/preview-asset", asyncHandler8(async (req, res) => {
|
|
47955
48939
|
const { previewSessionManager } = req.app.locals.deps;
|
|
47956
48940
|
if (!previewSessionManager) {
|
|
47957
48941
|
throw new MeshyError("VALIDATION_ERROR", "Preview not available on this node", 400);
|
|
47958
48942
|
}
|
|
47959
48943
|
const token = external_exports.string().min(1).parse(req.query.token);
|
|
47960
48944
|
const requestedPath = typeof req.query.path === "string" && req.query.path.length > 0 ? req.query.path : void 0;
|
|
47961
|
-
sendPreviewAssetResponse(previewSessionManager, token, requestedPath, res);
|
|
48945
|
+
await sendPreviewAssetResponse(previewSessionManager, token, requestedPath, res, req);
|
|
47962
48946
|
}));
|
|
47963
48947
|
router.post("/control-response", asyncHandler8(async (req, res) => {
|
|
47964
48948
|
const { heartbeat, logger: rootLogger } = req.app.locals.deps;
|
|
@@ -48101,15 +49085,17 @@ function createSystemRoutes() {
|
|
|
48101
49085
|
var import_express12 = __toESM(require_express2(), 1);
|
|
48102
49086
|
var HEARTBEAT_INTERVAL_MS = 15e3;
|
|
48103
49087
|
var CATEGORY_MAP = {
|
|
48104
|
-
tasks: "task.",
|
|
48105
|
-
nodes: "node.",
|
|
48106
|
-
elections: "election.",
|
|
48107
|
-
cluster: "cluster."
|
|
49088
|
+
tasks: ["task."],
|
|
49089
|
+
nodes: ["node.", "transport."],
|
|
49090
|
+
elections: ["election."],
|
|
49091
|
+
cluster: ["cluster."]
|
|
48108
49092
|
};
|
|
48109
49093
|
var ALL_EVENT_NAMES = [
|
|
48110
49094
|
"node.joined",
|
|
48111
49095
|
"node.left",
|
|
48112
49096
|
"node.status",
|
|
49097
|
+
"node.operation.created",
|
|
49098
|
+
"node.operation.updated",
|
|
48113
49099
|
"task.created",
|
|
48114
49100
|
"task.assigned",
|
|
48115
49101
|
"task.status",
|
|
@@ -48118,7 +49104,8 @@ var ALL_EVENT_NAMES = [
|
|
|
48118
49104
|
"task.output",
|
|
48119
49105
|
"election.started",
|
|
48120
49106
|
"election.complete",
|
|
48121
|
-
"cluster.state"
|
|
49107
|
+
"cluster.state",
|
|
49108
|
+
"transport.changed"
|
|
48122
49109
|
];
|
|
48123
49110
|
function parseFilter(filterParam) {
|
|
48124
49111
|
if (typeof filterParam !== "string" || filterParam.trim() === "") {
|
|
@@ -48129,8 +49116,8 @@ function parseFilter(filterParam) {
|
|
|
48129
49116
|
function shouldIncludeEvent(eventName, categories) {
|
|
48130
49117
|
if (!categories) return true;
|
|
48131
49118
|
return categories.some((cat) => {
|
|
48132
|
-
const
|
|
48133
|
-
return
|
|
49119
|
+
const prefixes = CATEGORY_MAP[cat];
|
|
49120
|
+
return prefixes != null && prefixes.some((prefix) => eventName.startsWith(prefix));
|
|
48134
49121
|
});
|
|
48135
49122
|
}
|
|
48136
49123
|
function createEventRoutes() {
|
|
@@ -48174,6 +49161,39 @@ data: ${JSON.stringify(data)}
|
|
|
48174
49161
|
return router;
|
|
48175
49162
|
}
|
|
48176
49163
|
|
|
49164
|
+
// ../../packages/api/src/routes/node-operations.ts
|
|
49165
|
+
var import_express13 = __toESM(require_express2(), 1);
|
|
49166
|
+
function asyncHandler10(fn) {
|
|
49167
|
+
return (req, res, next) => fn(req, res, next).catch(next);
|
|
49168
|
+
}
|
|
49169
|
+
function parseStatus(value) {
|
|
49170
|
+
if (value === "queued" || value === "running" || value === "succeeded" || value === "failed") return value;
|
|
49171
|
+
return void 0;
|
|
49172
|
+
}
|
|
49173
|
+
function createNodeOperationRoutes() {
|
|
49174
|
+
const router = (0, import_express13.Router)();
|
|
49175
|
+
router.get("/", asyncHandler10(async (req, res) => {
|
|
49176
|
+
if (await maybeProxyReadToLeader(req, res)) return;
|
|
49177
|
+
const deps = req.app.locals.deps;
|
|
49178
|
+
const operations = getNodeOperationService(deps).list({
|
|
49179
|
+
nodeId: typeof req.query.nodeId === "string" ? req.query.nodeId : void 0,
|
|
49180
|
+
status: parseStatus(req.query.status),
|
|
49181
|
+
kind: typeof req.query.kind === "string" ? req.query.kind : void 0
|
|
49182
|
+
});
|
|
49183
|
+
res.json({ operations });
|
|
49184
|
+
}));
|
|
49185
|
+
router.get("/:id", asyncHandler10(async (req, res) => {
|
|
49186
|
+
if (await maybeProxyReadToLeader(req, res)) return;
|
|
49187
|
+
const deps = req.app.locals.deps;
|
|
49188
|
+
const operation = getNodeOperationService(deps).get(req.params.id);
|
|
49189
|
+
if (!operation) {
|
|
49190
|
+
throw new MeshyError("NODE_NOT_FOUND", `Node operation ${req.params.id} not found`, 404);
|
|
49191
|
+
}
|
|
49192
|
+
res.json(operation);
|
|
49193
|
+
}));
|
|
49194
|
+
return router;
|
|
49195
|
+
}
|
|
49196
|
+
|
|
48177
49197
|
// ../../packages/api/src/app/server.ts
|
|
48178
49198
|
var JSON_BODY_LIMIT = "1mb";
|
|
48179
49199
|
var JSON_BODY_LIMIT_LARGE = "25mb";
|
|
@@ -48211,11 +49231,18 @@ function isShareHostRequest(req, shareOrigin) {
|
|
|
48211
49231
|
function isAllowedSharePath(pathname) {
|
|
48212
49232
|
return pathname === "/favicon.ico" || pathname === "/api/shared" || pathname.startsWith("/api/shared/") || pathname === "/preview" || pathname.startsWith("/preview/") || pathname === "/shared" || pathname.startsWith("/shared/") || pathname === "/assets" || pathname.startsWith("/assets/");
|
|
48213
49233
|
}
|
|
49234
|
+
function hasAuthorizationHeader(req) {
|
|
49235
|
+
const header = req.headers[MESHY_AUTHORIZATION_HEADER] ?? req.headers.authorization;
|
|
49236
|
+
if (Array.isArray(header)) {
|
|
49237
|
+
return header.some((value) => value.trim().length > 0);
|
|
49238
|
+
}
|
|
49239
|
+
return typeof header === "string" && header.trim().length > 0;
|
|
49240
|
+
}
|
|
48214
49241
|
function resolveRuntimeBaseDir() {
|
|
48215
49242
|
const entryPath = process.argv[1];
|
|
48216
49243
|
if (typeof entryPath === "string" && entryPath.length > 0) {
|
|
48217
|
-
const resolved =
|
|
48218
|
-
return
|
|
49244
|
+
const resolved = fs19.realpathSync(path20.resolve(entryPath));
|
|
49245
|
+
return path20.dirname(resolved);
|
|
48219
49246
|
}
|
|
48220
49247
|
return process.cwd();
|
|
48221
49248
|
}
|
|
@@ -48223,25 +49250,25 @@ function resolveStaticDir(baseDir) {
|
|
|
48223
49250
|
const envStaticDir = process.env.MESHY_STATIC_DIR;
|
|
48224
49251
|
const candidateDirs = [
|
|
48225
49252
|
envStaticDir,
|
|
48226
|
-
|
|
48227
|
-
|
|
48228
|
-
|
|
48229
|
-
|
|
48230
|
-
|
|
48231
|
-
|
|
48232
|
-
|
|
48233
|
-
|
|
48234
|
-
|
|
49253
|
+
path20.resolve(baseDir, "dashboard"),
|
|
49254
|
+
path20.resolve(baseDir, "../dashboard"),
|
|
49255
|
+
path20.resolve(baseDir, "../../dashboard/dist"),
|
|
49256
|
+
path20.resolve(baseDir, "../../../packages/dashboard/dist"),
|
|
49257
|
+
path20.resolve(baseDir, "../public"),
|
|
49258
|
+
path20.resolve(baseDir, "../../packages/api/public"),
|
|
49259
|
+
path20.resolve(baseDir, "../../../packages/api/public"),
|
|
49260
|
+
path20.resolve(process.cwd(), "packages/dashboard/dist"),
|
|
49261
|
+
path20.resolve(process.cwd(), "packages/api/public")
|
|
48235
49262
|
].filter((value) => typeof value === "string" && value.length > 0);
|
|
48236
49263
|
for (const candidate of candidateDirs) {
|
|
48237
|
-
if (
|
|
49264
|
+
if (fs19.existsSync(candidate)) {
|
|
48238
49265
|
return candidate;
|
|
48239
49266
|
}
|
|
48240
49267
|
}
|
|
48241
49268
|
return null;
|
|
48242
49269
|
}
|
|
48243
49270
|
function createServer2(deps) {
|
|
48244
|
-
const app = (0,
|
|
49271
|
+
const app = (0, import_express14.default)();
|
|
48245
49272
|
app.locals.deps = deps;
|
|
48246
49273
|
if (typeof deps.heartbeat.setNodeMessageHandler === "function") {
|
|
48247
49274
|
deps.heartbeat.setNodeMessageHandler((message) => handleNodeMessage(deps, message));
|
|
@@ -48267,7 +49294,9 @@ function createServer2(deps) {
|
|
|
48267
49294
|
}
|
|
48268
49295
|
};
|
|
48269
49296
|
const isApiRequest = (req) => req.path === "/api" || req.path.startsWith("/api/");
|
|
49297
|
+
const isPreviewRequest = (req) => req.path.startsWith("/preview/") || req.path.startsWith("/preview-open/");
|
|
48270
49298
|
const canServeDashboard = (req) => !deps.config.validateBearerToken || isTrustedDashboardRequest(req, authConfig);
|
|
49299
|
+
const canServePreview = (req) => canServeDashboard(req) || hasAuthorizationHeader(req);
|
|
48271
49300
|
app.use((req, res, next) => {
|
|
48272
49301
|
if (!isShareHostRequest(req, deps.shareOrigin)) {
|
|
48273
49302
|
next();
|
|
@@ -48282,9 +49311,9 @@ function createServer2(deps) {
|
|
|
48282
49311
|
const runtimeBaseDir = resolveRuntimeBaseDir();
|
|
48283
49312
|
const staticDir = resolveStaticDir(runtimeBaseDir);
|
|
48284
49313
|
if (staticDir) {
|
|
48285
|
-
const staticMiddleware =
|
|
49314
|
+
const staticMiddleware = import_express14.default.static(staticDir);
|
|
48286
49315
|
app.use((req, res, next) => {
|
|
48287
|
-
if (isApiRequest(req)) {
|
|
49316
|
+
if (isApiRequest(req) || isPreviewRequest(req)) {
|
|
48288
49317
|
next();
|
|
48289
49318
|
return;
|
|
48290
49319
|
}
|
|
@@ -48295,29 +49324,33 @@ function createServer2(deps) {
|
|
|
48295
49324
|
staticMiddleware(req, res, next);
|
|
48296
49325
|
});
|
|
48297
49326
|
}
|
|
48298
|
-
app.use(
|
|
49327
|
+
app.use(import_express14.default.json({ limit: JSON_BODY_LIMIT }));
|
|
48299
49328
|
app.use(createAuthMiddleware(authConfig));
|
|
48300
49329
|
app.use((req, res, next) => {
|
|
48301
49330
|
void (async () => {
|
|
48302
|
-
if (!req
|
|
49331
|
+
if (!isPreviewRequest(req)) {
|
|
48303
49332
|
next();
|
|
48304
49333
|
return;
|
|
48305
49334
|
}
|
|
48306
|
-
if (!
|
|
49335
|
+
if (!canServePreview(req)) {
|
|
48307
49336
|
res.status(404).type("text/plain").send("Not Found");
|
|
48308
49337
|
return;
|
|
48309
49338
|
}
|
|
48310
49339
|
if (deps.previewProxyManager && await handlePreviewProxyRequest(deps.previewProxyManager, deps.nodeRegistry, deps.logger, req, res)) {
|
|
48311
49340
|
return;
|
|
48312
49341
|
}
|
|
48313
|
-
if (deps.previewSessionManager && handlePreviewRequest(deps.previewSessionManager, req, res)) {
|
|
49342
|
+
if (deps.previewSessionManager && await handlePreviewRequest(deps.previewSessionManager, req, res)) {
|
|
48314
49343
|
return;
|
|
48315
49344
|
}
|
|
48316
49345
|
next();
|
|
48317
49346
|
})().catch(next);
|
|
48318
49347
|
});
|
|
48319
|
-
app.use(createRoutingMiddleware(
|
|
48320
|
-
|
|
49348
|
+
app.use(createRoutingMiddleware({
|
|
49349
|
+
dataRouter: deps.dataRouter,
|
|
49350
|
+
taskEngine: deps.taskEngine,
|
|
49351
|
+
logger: deps.logger
|
|
49352
|
+
}));
|
|
49353
|
+
const largeBodyParser = import_express14.default.json({ limit: JSON_BODY_LIMIT_LARGE });
|
|
48321
49354
|
app.use("/api/cluster", createClusterRoutes());
|
|
48322
49355
|
app.use("/api/cluster-control", createClusterControlRoutes());
|
|
48323
49356
|
app.use("/api/node", largeBodyParser, createNodeMessageRoutes());
|
|
@@ -48326,10 +49359,11 @@ function createServer2(deps) {
|
|
|
48326
49359
|
app.use("/api/shared", createSharedRoutes());
|
|
48327
49360
|
app.use("/api/worker", largeBodyParser, createWorkerRoutes());
|
|
48328
49361
|
app.use("/api/system", createSystemRoutes());
|
|
49362
|
+
app.use("/api/node-operations", createNodeOperationRoutes());
|
|
48329
49363
|
app.use("/api/events", createEventRoutes());
|
|
48330
49364
|
if (staticDir) {
|
|
48331
|
-
const indexPath =
|
|
48332
|
-
if (
|
|
49365
|
+
const indexPath = path20.join(staticDir, "index.html");
|
|
49366
|
+
if (fs19.existsSync(indexPath)) {
|
|
48333
49367
|
app.get("*", (req, res, next) => {
|
|
48334
49368
|
if (isApiRequest(req)) {
|
|
48335
49369
|
next();
|
|
@@ -48725,8 +49759,8 @@ var terminalWriter = {
|
|
|
48725
49759
|
};
|
|
48726
49760
|
|
|
48727
49761
|
// src/startup.ts
|
|
48728
|
-
var
|
|
48729
|
-
var
|
|
49762
|
+
var fs20 = __toESM(require("fs"), 1);
|
|
49763
|
+
var path21 = __toESM(require("path"), 1);
|
|
48730
49764
|
var readline = __toESM(require("readline/promises"), 1);
|
|
48731
49765
|
var import_node_child_process11 = require("child_process");
|
|
48732
49766
|
function getDefaultNodeName() {
|
|
@@ -48789,19 +49823,19 @@ function createDefaultCommandRunner(platform2) {
|
|
|
48789
49823
|
};
|
|
48790
49824
|
}
|
|
48791
49825
|
function getNodeMetadataPath2(storagePath) {
|
|
48792
|
-
return
|
|
49826
|
+
return path21.join(storagePath, "metadata.json");
|
|
48793
49827
|
}
|
|
48794
49828
|
function readStartupMetadataFile(storagePath) {
|
|
48795
49829
|
try {
|
|
48796
|
-
const raw = JSON.parse(
|
|
49830
|
+
const raw = JSON.parse(fs20.readFileSync(getNodeMetadataPath2(storagePath), "utf-8"));
|
|
48797
49831
|
return typeof raw === "object" && raw !== null ? raw : {};
|
|
48798
49832
|
} catch {
|
|
48799
49833
|
return {};
|
|
48800
49834
|
}
|
|
48801
49835
|
}
|
|
48802
49836
|
function writeStartupMetadataFile(storagePath, metadata) {
|
|
48803
|
-
|
|
48804
|
-
|
|
49837
|
+
fs20.mkdirSync(storagePath, { recursive: true });
|
|
49838
|
+
fs20.writeFileSync(getNodeMetadataPath2(storagePath), JSON.stringify(metadata, null, 2) + "\n", "utf-8");
|
|
48805
49839
|
}
|
|
48806
49840
|
function formatLocalDate2(now) {
|
|
48807
49841
|
const year = now.getFullYear();
|
|
@@ -49040,9 +50074,9 @@ async function ensureStartupRequirements(storagePath, options = {}) {
|
|
|
49040
50074
|
metadata
|
|
49041
50075
|
};
|
|
49042
50076
|
}
|
|
49043
|
-
function loadConfigFile(
|
|
50077
|
+
function loadConfigFile(path23) {
|
|
49044
50078
|
try {
|
|
49045
|
-
const raw =
|
|
50079
|
+
const raw = fs20.readFileSync(path23, "utf-8");
|
|
49046
50080
|
return JSON.parse(raw);
|
|
49047
50081
|
} catch {
|
|
49048
50082
|
return {};
|
|
@@ -49220,26 +50254,26 @@ function formatLoadedStartMetadata(info, authEnabled) {
|
|
|
49220
50254
|
}
|
|
49221
50255
|
|
|
49222
50256
|
// src/runtime-metadata.ts
|
|
49223
|
-
var
|
|
49224
|
-
var
|
|
50257
|
+
var fs21 = __toESM(require("fs"), 1);
|
|
50258
|
+
var path22 = __toESM(require("path"), 1);
|
|
49225
50259
|
var import_node_child_process12 = require("child_process");
|
|
49226
50260
|
var runtimeDir = resolveRuntimeDir();
|
|
49227
50261
|
var appRoot = resolveAppRoot(runtimeDir);
|
|
49228
|
-
var repoRoot =
|
|
50262
|
+
var repoRoot = path22.resolve(appRoot, "../..");
|
|
49229
50263
|
function resolveRuntimeDir() {
|
|
49230
50264
|
const entryPath = process.argv[1];
|
|
49231
50265
|
if (typeof entryPath === "string" && entryPath.length > 0) {
|
|
49232
50266
|
try {
|
|
49233
|
-
return
|
|
50267
|
+
return path22.dirname(fs21.realpathSync(path22.resolve(entryPath)));
|
|
49234
50268
|
} catch {
|
|
49235
|
-
return
|
|
50269
|
+
return path22.dirname(path22.resolve(entryPath));
|
|
49236
50270
|
}
|
|
49237
50271
|
}
|
|
49238
50272
|
return process.cwd();
|
|
49239
50273
|
}
|
|
49240
50274
|
function readJsonFile(filePath) {
|
|
49241
50275
|
try {
|
|
49242
|
-
return JSON.parse(
|
|
50276
|
+
return JSON.parse(fs21.readFileSync(filePath, "utf-8"));
|
|
49243
50277
|
} catch {
|
|
49244
50278
|
return null;
|
|
49245
50279
|
}
|
|
@@ -49249,9 +50283,9 @@ function readPackageManifest(filePath) {
|
|
|
49249
50283
|
}
|
|
49250
50284
|
function readEmbeddedRuntimeMetadata() {
|
|
49251
50285
|
const candidates = [
|
|
49252
|
-
|
|
49253
|
-
|
|
49254
|
-
|
|
50286
|
+
path22.join(appRoot, "runtime-metadata.json"),
|
|
50287
|
+
path22.join(runtimeDir, "runtime-metadata.json"),
|
|
50288
|
+
path22.resolve(process.cwd(), "apps/node/dist/runtime-metadata.json")
|
|
49255
50289
|
];
|
|
49256
50290
|
for (const candidate of candidates) {
|
|
49257
50291
|
const metadata = readJsonFile(candidate);
|
|
@@ -49264,23 +50298,23 @@ function readEmbeddedRuntimeMetadata() {
|
|
|
49264
50298
|
function resolveAppRoot(baseDir) {
|
|
49265
50299
|
const candidates = [
|
|
49266
50300
|
baseDir,
|
|
49267
|
-
|
|
49268
|
-
|
|
49269
|
-
|
|
50301
|
+
path22.resolve(baseDir, ".."),
|
|
50302
|
+
path22.resolve(process.cwd(), "apps/node/dist"),
|
|
50303
|
+
path22.resolve(process.cwd(), "apps/node"),
|
|
49270
50304
|
process.cwd()
|
|
49271
50305
|
];
|
|
49272
50306
|
for (const candidate of candidates) {
|
|
49273
|
-
const manifest = readPackageManifest(
|
|
50307
|
+
const manifest = readPackageManifest(path22.join(candidate, "package.json"));
|
|
49274
50308
|
if (manifest?.name === "@meshy/node" || manifest?.name === "meshy-node") {
|
|
49275
50309
|
return candidate;
|
|
49276
50310
|
}
|
|
49277
50311
|
}
|
|
49278
50312
|
for (const candidate of candidates) {
|
|
49279
|
-
if (
|
|
50313
|
+
if (fs21.existsSync(path22.join(candidate, "package.json"))) {
|
|
49280
50314
|
return candidate;
|
|
49281
50315
|
}
|
|
49282
50316
|
}
|
|
49283
|
-
return
|
|
50317
|
+
return path22.resolve(baseDir, "..");
|
|
49284
50318
|
}
|
|
49285
50319
|
function toPackageInfo(filePath) {
|
|
49286
50320
|
const manifest = readPackageManifest(filePath);
|
|
@@ -49340,8 +50374,8 @@ function buildRuntimeMetadata(storagePath) {
|
|
|
49340
50374
|
components: startupRequirements.components
|
|
49341
50375
|
};
|
|
49342
50376
|
}
|
|
49343
|
-
const appPackage = toPackageInfo(
|
|
49344
|
-
const workspaceManifest = readPackageManifest(
|
|
50377
|
+
const appPackage = toPackageInfo(path22.join(appRoot, "package.json"));
|
|
50378
|
+
const workspaceManifest = readPackageManifest(path22.join(repoRoot, "package.json"));
|
|
49345
50379
|
return {
|
|
49346
50380
|
packageName: appPackage?.name ?? "meshy",
|
|
49347
50381
|
packageVersion: appPackage?.version ?? "0.1.0",
|
|
@@ -49349,11 +50383,11 @@ function buildRuntimeMetadata(storagePath) {
|
|
|
49349
50383
|
startupRequirementsLastCheckedOn: startupRequirements.lastCheckedOn,
|
|
49350
50384
|
components: startupRequirements.components,
|
|
49351
50385
|
packages: {
|
|
49352
|
-
workspace: toPackageInfo(
|
|
50386
|
+
workspace: toPackageInfo(path22.join(repoRoot, "package.json")),
|
|
49353
50387
|
node: appPackage,
|
|
49354
|
-
core: toPackageInfo(
|
|
49355
|
-
dashboard: toPackageInfo(
|
|
49356
|
-
api: toPackageInfo(
|
|
50388
|
+
core: toPackageInfo(path22.join(repoRoot, "packages/core/package.json")),
|
|
50389
|
+
dashboard: toPackageInfo(path22.join(repoRoot, "packages/dashboard/package.json")),
|
|
50390
|
+
api: toPackageInfo(path22.join(repoRoot, "packages/api/package.json"))
|
|
49357
50391
|
},
|
|
49358
50392
|
repository: {
|
|
49359
50393
|
url: normalizeRepositoryUrl(readGitValue(["config", "--get", "remote.upstream.url"])) ?? normalizeRepositoryUrl(readGitValue(["config", "--get", "remote.origin.url"])) ?? readRepositoryUrlFromManifest(workspaceManifest),
|