meshy-node 0.9.3 → 0.9.4
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-D2jQAhdO.js +164 -0
- package/dashboard/assets/{DashboardShared-Coi8X4Mf.js → DashboardShared-clSb73vU.js} +35 -35
- package/dashboard/assets/{DiffTab-797YuD9i.js → DiffTab-QOs1BAhv.js} +2 -2
- package/dashboard/assets/{FilesTab-CxWQD31o.js → FilesTab-amewzDu1.js} +2 -2
- package/dashboard/assets/{MarkdownPreviewFrame-tY-M5bCG.js → MarkdownPreviewFrame-DTqC8qsr.js} +1 -1
- package/dashboard/assets/PreviewTab-CDVQQTEo.js +21 -0
- package/dashboard/assets/SharedConversationPage-BlehYOnU.js +2 -0
- package/dashboard/assets/{file-QtUVb5S2.js → file-61zsRyWG.js} +1 -1
- package/dashboard/assets/{index-BxuLE_uo.js → index-BubHGNBS.js} +64 -64
- package/dashboard/assets/index-DGEkwKT1.css +1 -0
- package/dashboard/index.html +2 -2
- package/main.cjs +226 -91
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/DashboardPage-DyNoe7cv.js +0 -149
- package/dashboard/assets/PreviewTab-Ci5d1xLj.js +0 -16
- package/dashboard/assets/SharedConversationPage-BMmvljLM.js +0 -2
- package/dashboard/assets/index-BT6taBuK.css +0 -1
- package/dashboard/assets/play-Cwrx3Fzy.js +0 -6
package/main.cjs
CHANGED
|
@@ -55917,6 +55917,7 @@ var NODE_KIND_BY_LEGACY = {
|
|
|
55917
55917
|
"node-terminal-session-get": "node.terminal.session.get",
|
|
55918
55918
|
"node-terminal-session-stop": "node.terminal.session.stop",
|
|
55919
55919
|
"node-sessions-list": "node.sessions.list",
|
|
55920
|
+
"node-preview-session": "node.preview.create",
|
|
55920
55921
|
devtunnel: "node.transport.set",
|
|
55921
55922
|
"node-agent-upgrade": "node.agent.upgrade",
|
|
55922
55923
|
"task-cancel": "task.cancel",
|
|
@@ -57223,14 +57224,15 @@ function normalizeCopilotToolInput(value) {
|
|
|
57223
57224
|
}
|
|
57224
57225
|
function extractCopilotAssistantContent(event) {
|
|
57225
57226
|
const data = isRecord3(event.data) ? event.data : void 0;
|
|
57226
|
-
const
|
|
57227
|
+
const activityContent = [];
|
|
57228
|
+
const textContent = [];
|
|
57227
57229
|
const reasoning = extractStringContent(data?.reasoningText) || extractStringContent(data?.reasoning);
|
|
57228
57230
|
const text = extractCopilotEventText(event);
|
|
57229
57231
|
if (reasoning) {
|
|
57230
|
-
|
|
57232
|
+
activityContent.push({ type: "thinking", thinking: reasoning });
|
|
57231
57233
|
}
|
|
57232
57234
|
if (text) {
|
|
57233
|
-
|
|
57235
|
+
textContent.push({ type: "text", text });
|
|
57234
57236
|
}
|
|
57235
57237
|
if (Array.isArray(data?.toolRequests)) {
|
|
57236
57238
|
for (const request of data.toolRequests) {
|
|
@@ -57238,7 +57240,7 @@ function extractCopilotAssistantContent(event) {
|
|
|
57238
57240
|
const id = getStringField(request, "toolCallId") || getStringField(request, "id") || getStringField(request, "callId");
|
|
57239
57241
|
const name2 = getStringField(request, "name") || getStringField(request, "toolName");
|
|
57240
57242
|
if (!id || !name2) continue;
|
|
57241
|
-
|
|
57243
|
+
activityContent.push({
|
|
57242
57244
|
type: "tool_use",
|
|
57243
57245
|
id,
|
|
57244
57246
|
name: name2,
|
|
@@ -57246,7 +57248,7 @@ function extractCopilotAssistantContent(event) {
|
|
|
57246
57248
|
});
|
|
57247
57249
|
}
|
|
57248
57250
|
}
|
|
57249
|
-
return
|
|
57251
|
+
return { activityContent, textContent };
|
|
57250
57252
|
}
|
|
57251
57253
|
function extractCopilotToolResult(event) {
|
|
57252
57254
|
const data = isRecord3(event.data) ? event.data : void 0;
|
|
@@ -57273,11 +57275,14 @@ function convertCopilotTranscriptEvent(event, opts = {}) {
|
|
|
57273
57275
|
return [buildTaskUserLogEvent([{ type: "text", text }], timestamp)];
|
|
57274
57276
|
}
|
|
57275
57277
|
if (type === "assistant.message" || type === "assistant_message" || type === "assistant" || type === "message") {
|
|
57276
|
-
const
|
|
57277
|
-
if (
|
|
57278
|
+
const { activityContent, textContent } = extractCopilotAssistantContent(event);
|
|
57279
|
+
if (activityContent.length === 0 && textContent.length === 0) {
|
|
57278
57280
|
return [];
|
|
57279
57281
|
}
|
|
57280
|
-
return [
|
|
57282
|
+
return [
|
|
57283
|
+
...activityContent.length > 0 ? [buildAssistantContentEvent(activityContent, timestamp)] : [],
|
|
57284
|
+
...textContent.length > 0 ? [buildAssistantContentEvent(textContent, timestamp)] : []
|
|
57285
|
+
];
|
|
57281
57286
|
}
|
|
57282
57287
|
if (type === "tool.execution_complete" || type === "tool_execution_complete") {
|
|
57283
57288
|
const result = extractCopilotToolResult(event);
|
|
@@ -57405,18 +57410,50 @@ function extractTextFromClaudeMessageContent(content) {
|
|
|
57405
57410
|
}
|
|
57406
57411
|
return "";
|
|
57407
57412
|
}
|
|
57413
|
+
function countLeadingWhitespace(line) {
|
|
57414
|
+
return line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
57415
|
+
}
|
|
57416
|
+
function isYamlBlockScalar(value) {
|
|
57417
|
+
return /^([|>])(?:[+-]?\d*|\d*[+-]?)$/.test(value);
|
|
57418
|
+
}
|
|
57419
|
+
function readYamlBlockValue(lines, startIndex) {
|
|
57420
|
+
const blockLines = [];
|
|
57421
|
+
let index = startIndex;
|
|
57422
|
+
for (; index < lines.length; index += 1) {
|
|
57423
|
+
const rawLine = lines[index] ?? "";
|
|
57424
|
+
if (!rawLine) {
|
|
57425
|
+
blockLines.push("");
|
|
57426
|
+
continue;
|
|
57427
|
+
}
|
|
57428
|
+
if (!rawLine.startsWith(" ") && !rawLine.startsWith(" ") && rawLine.trim()) {
|
|
57429
|
+
break;
|
|
57430
|
+
}
|
|
57431
|
+
blockLines.push(rawLine);
|
|
57432
|
+
}
|
|
57433
|
+
const indent = blockLines.filter((line) => line.trim()).reduce((lowest, line) => Math.min(lowest, countLeadingWhitespace(line)), Number.POSITIVE_INFINITY);
|
|
57434
|
+
const stripIndent = Number.isFinite(indent) ? indent : 0;
|
|
57435
|
+
const value = blockLines.map((line) => line.trim() ? line.slice(stripIndent) : "").join("\n").trim();
|
|
57436
|
+
return { value, endIndex: index - 1 };
|
|
57437
|
+
}
|
|
57408
57438
|
function readSimpleYaml(filePath) {
|
|
57409
57439
|
if (!fs8.existsSync(filePath)) {
|
|
57410
57440
|
return {};
|
|
57411
57441
|
}
|
|
57412
57442
|
const metadata = {};
|
|
57413
|
-
|
|
57443
|
+
const lines = fs8.readFileSync(filePath, "utf8").split(/\r?\n/);
|
|
57444
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
57445
|
+
const rawLine = lines[index] ?? "";
|
|
57414
57446
|
const line = rawLine.trim();
|
|
57415
57447
|
if (!line || line.startsWith("#")) continue;
|
|
57416
57448
|
const separatorIndex = line.indexOf(":");
|
|
57417
57449
|
if (separatorIndex <= 0) continue;
|
|
57418
57450
|
const key = line.slice(0, separatorIndex).trim();
|
|
57419
57451
|
let value = line.slice(separatorIndex + 1).trim();
|
|
57452
|
+
if (isYamlBlockScalar(value)) {
|
|
57453
|
+
const block = readYamlBlockValue(lines, index + 1);
|
|
57454
|
+
value = block.value;
|
|
57455
|
+
index = block.endIndex;
|
|
57456
|
+
}
|
|
57420
57457
|
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
57421
57458
|
value = value.slice(1, -1);
|
|
57422
57459
|
}
|
|
@@ -61967,6 +62004,10 @@ var NodeTerminalSessionStartBody = external_exports.object({
|
|
|
61967
62004
|
command: external_exports.string().trim().min(1),
|
|
61968
62005
|
cwd: external_exports.string().trim().min(1).optional()
|
|
61969
62006
|
});
|
|
62007
|
+
var NodePreviewSessionBody = external_exports.object({
|
|
62008
|
+
port: external_exports.coerce.number().int().min(1).max(65535),
|
|
62009
|
+
path: external_exports.string().trim().min(1).optional()
|
|
62010
|
+
});
|
|
61970
62011
|
var NodeWorkDirTreeResponse = external_exports.object({
|
|
61971
62012
|
nodeId: external_exports.string(),
|
|
61972
62013
|
rootPath: external_exports.string(),
|
|
@@ -64692,6 +64733,7 @@ var LEGACY_KIND_BY_NODE_MESSAGE = {
|
|
|
64692
64733
|
"node.terminal.session.get": "node-terminal-session-get",
|
|
64693
64734
|
"node.terminal.session.stop": "node-terminal-session-stop",
|
|
64694
64735
|
"node.sessions.list": "node-sessions-list",
|
|
64736
|
+
"node.preview.create": "node-preview-session",
|
|
64695
64737
|
"node.transport.set": "devtunnel",
|
|
64696
64738
|
"node.agent.upgrade": "node-agent-upgrade",
|
|
64697
64739
|
"task.cancel": "task-cancel",
|
|
@@ -65590,7 +65632,7 @@ function normalizeServiceRequestPath(pathname) {
|
|
|
65590
65632
|
}
|
|
65591
65633
|
function rewriteServiceRootRelativeUrls(value, token) {
|
|
65592
65634
|
const previewRoot = `/preview/${token}/`;
|
|
65593
|
-
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`);
|
|
65635
|
+
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(/(['"])\/(api(?:\/[^'"]*)?|assets\/[^'"]+)\1/g, `$1${previewRoot}$2$1`);
|
|
65594
65636
|
}
|
|
65595
65637
|
function escapeHtmlAttribute(value) {
|
|
65596
65638
|
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
@@ -65600,38 +65642,20 @@ function buildServicePreviewBridge(token) {
|
|
|
65600
65642
|
const previewBase = previewRoot.replace(/\/$/, "");
|
|
65601
65643
|
const script = [
|
|
65602
65644
|
"(()=>{",
|
|
65645
|
+
"const stopPreviewFrameError=(event)=>{try{event.stopPropagation();}catch{}};",
|
|
65646
|
+
'window.addEventListener("error",stopPreviewFrameError,true);',
|
|
65647
|
+
'window.addEventListener("unhandledrejection",stopPreviewFrameError,true);',
|
|
65648
|
+
"try{",
|
|
65603
65649
|
"if(window.top===window)return;",
|
|
65604
65650
|
`const previewBase=${JSON.stringify(previewBase)};`,
|
|
65605
65651
|
`const previewRoot=${JSON.stringify(previewRoot)};`,
|
|
65606
|
-
"const rewritePreviewRequestUrl=(value)=>{",
|
|
65607
|
-
"if(value==null)return value;",
|
|
65608
|
-
"let raw;",
|
|
65609
|
-
'try{raw=value instanceof URL?value.href:typeof value==="string"?value:value&&typeof value.url==="string"?value.url:undefined;}catch{return value;}',
|
|
65610
|
-
"if(!raw)return value;",
|
|
65611
|
-
"let url;",
|
|
65612
|
-
"try{url=new URL(raw,window.location.href);}catch{return value;}",
|
|
65613
|
-
"if(url.origin!==window.location.origin)return value;",
|
|
65614
|
-
'if(url.pathname===previewBase||url.pathname.startsWith(previewRoot)||url.pathname.startsWith("/preview-open/"))return value;',
|
|
65615
|
-
'return previewRoot+url.pathname.replace(/^\\/+/,"")+url.search+url.hash;',
|
|
65616
|
-
"};",
|
|
65617
|
-
"const rewritePreviewRequestInput=(input)=>{",
|
|
65618
|
-
"const next=rewritePreviewRequestUrl(input);",
|
|
65619
|
-
"if(next===input)return input;",
|
|
65620
|
-
'if(typeof Request==="function"&&input instanceof Request)return new Request(next,input);',
|
|
65621
|
-
"return next;",
|
|
65622
|
-
"};",
|
|
65623
|
-
"const originalFetch=window.fetch;",
|
|
65624
|
-
'if(typeof originalFetch==="function")window.fetch=(input,init)=>originalFetch.call(window,rewritePreviewRequestInput(input),init);',
|
|
65625
|
-
"const XHR=window.XMLHttpRequest;",
|
|
65626
|
-
"if(XHR&&XHR.prototype){const open=XHR.prototype.open;XMLHttpRequest.prototype.open=function(method,url,...rest){return open.call(this,method,rewritePreviewRequestUrl(url),...rest);};}",
|
|
65627
|
-
"const OriginalEventSource=window.EventSource;",
|
|
65628
|
-
'if(typeof OriginalEventSource==="function"){window.EventSource=function(url,config){return new OriginalEventSource(rewritePreviewRequestUrl(url),config);};window.EventSource.prototype=OriginalEventSource.prototype;}',
|
|
65629
65652
|
"const currentPath=window.location.pathname;",
|
|
65630
65653
|
"if(currentPath===previewBase||currentPath.startsWith(previewRoot)){",
|
|
65631
65654
|
"const suffix=currentPath===previewBase?'':currentPath.slice(previewRoot.length);",
|
|
65632
65655
|
"const servicePath=suffix?'/' + suffix:'/';",
|
|
65633
|
-
"window.history.replaceState(window.history.state,'',servicePath+window.location.search+window.location.hash);",
|
|
65656
|
+
"try{window.history.replaceState(window.history.state,'',servicePath+window.location.search+window.location.hash);}catch{}",
|
|
65634
65657
|
"}",
|
|
65658
|
+
"}catch{}",
|
|
65635
65659
|
"})();"
|
|
65636
65660
|
].join("");
|
|
65637
65661
|
return `<base data-meshy-preview-base href="${escapeHtmlAttribute(previewRoot)}"><script data-meshy-preview-bridge>${script}</script>`;
|
|
@@ -65781,6 +65805,13 @@ function renderPreviewOpenDocument(previewUrl) {
|
|
|
65781
65805
|
html, body { width: 100%; height: 100%; margin: 0; background: #fff; }
|
|
65782
65806
|
iframe { display: block; width: 100%; height: 100%; border: 0; }
|
|
65783
65807
|
</style>
|
|
65808
|
+
<script data-meshy-preview-shell>
|
|
65809
|
+
(() => {
|
|
65810
|
+
const stopPreviewFrameError = (event) => { try { event.stopPropagation() } catch {} };
|
|
65811
|
+
window.addEventListener('error', stopPreviewFrameError, true);
|
|
65812
|
+
window.addEventListener('unhandledrejection', stopPreviewFrameError, true);
|
|
65813
|
+
})();
|
|
65814
|
+
</script>
|
|
65784
65815
|
</head>
|
|
65785
65816
|
<body>
|
|
65786
65817
|
<iframe src="${safePreviewUrl}" title="Preview"></iframe>
|
|
@@ -66222,6 +66253,39 @@ async function createPreviewSessionPayload(deps, taskId, optionsOrPath, requestO
|
|
|
66222
66253
|
};
|
|
66223
66254
|
}
|
|
66224
66255
|
|
|
66256
|
+
// ../../packages/api/src/node/node-preview-service.ts
|
|
66257
|
+
init_cjs_shims();
|
|
66258
|
+
function isPreviewSessionPayload(value) {
|
|
66259
|
+
return typeof value === "object" && value !== null && typeof value.previewUrl === "string" && typeof value.entryPath === "string" && typeof value.expiresAt === "number";
|
|
66260
|
+
}
|
|
66261
|
+
function rewriteNodePreviewPayloadForProxy(deps, payload, nodeId) {
|
|
66262
|
+
const manager = deps.previewProxyManager;
|
|
66263
|
+
return manager ? rewritePreviewSessionPayloadForProxy(manager, payload, nodeId) : payload;
|
|
66264
|
+
}
|
|
66265
|
+
async function createNodePreviewSessionPayload(deps, nodeId, options, requestOrigin) {
|
|
66266
|
+
const previewManager = deps.previewSessionManager;
|
|
66267
|
+
if (!previewManager) {
|
|
66268
|
+
throw new MeshyError("VALIDATION_ERROR", "Preview not available on this node", 400);
|
|
66269
|
+
}
|
|
66270
|
+
const session = previewManager.create({
|
|
66271
|
+
taskId: `node:${nodeId}`,
|
|
66272
|
+
port: options.port,
|
|
66273
|
+
entryPath: options.path
|
|
66274
|
+
});
|
|
66275
|
+
const origin = requestOrigin ?? deps.dashboardOrigin ?? deps.localDashboardOrigin;
|
|
66276
|
+
if (!origin) {
|
|
66277
|
+
throw new MeshyError("VALIDATION_ERROR", "Preview origin not available", 502);
|
|
66278
|
+
}
|
|
66279
|
+
return {
|
|
66280
|
+
previewUrl: buildPreviewUrl(origin, session),
|
|
66281
|
+
openUrl: buildPreviewOpenUrl(origin, session),
|
|
66282
|
+
expiresAt: session.expiresAt,
|
|
66283
|
+
entryPath: session.entryPath,
|
|
66284
|
+
kind: session.kind,
|
|
66285
|
+
...session.kind === "service" ? { port: session.port } : {}
|
|
66286
|
+
};
|
|
66287
|
+
}
|
|
66288
|
+
|
|
66225
66289
|
// ../../packages/api/src/node/capability-service.ts
|
|
66226
66290
|
init_cjs_shims();
|
|
66227
66291
|
var fs25 = __toESM(require("fs"), 1);
|
|
@@ -66457,6 +66521,23 @@ async function executeWorkerControlRequest(deps, request) {
|
|
|
66457
66521
|
);
|
|
66458
66522
|
break;
|
|
66459
66523
|
}
|
|
66524
|
+
case "node.preview.create": {
|
|
66525
|
+
const self2 = deps.nodeRegistry.getSelf();
|
|
66526
|
+
const previewPath = payloadValue(request, "path", void 0);
|
|
66527
|
+
const previewPort = payloadValue(request, "port", void 0);
|
|
66528
|
+
if (typeof previewPort !== "number") {
|
|
66529
|
+
throw new MeshyError("VALIDATION_ERROR", "node.preview.create requires a service port", 400);
|
|
66530
|
+
}
|
|
66531
|
+
response = jsonResponse(
|
|
66532
|
+
request.id,
|
|
66533
|
+
200,
|
|
66534
|
+
await createNodePreviewSessionPayload(deps, self2.id, {
|
|
66535
|
+
path: typeof previewPath === "string" ? previewPath : void 0,
|
|
66536
|
+
port: previewPort
|
|
66537
|
+
})
|
|
66538
|
+
);
|
|
66539
|
+
break;
|
|
66540
|
+
}
|
|
66460
66541
|
case "node.transport.set": {
|
|
66461
66542
|
assertCanChangeNodeDevTunnel(deps.taskEngine, deps.nodeRegistry.getSelf().id);
|
|
66462
66543
|
if (payloadValue(request, "enabled", false)) {
|
|
@@ -66779,6 +66860,110 @@ async function sendNodeRuntimeRestart(req, res, nodeId) {
|
|
|
66779
66860
|
res.status(202).json(operation);
|
|
66780
66861
|
}
|
|
66781
66862
|
|
|
66863
|
+
// ../../packages/api/src/routes/node-preview.ts
|
|
66864
|
+
init_cjs_shims();
|
|
66865
|
+
|
|
66866
|
+
// ../../packages/api/src/app/request-origin.ts
|
|
66867
|
+
init_cjs_shims();
|
|
66868
|
+
function getFirstHeaderValue(value) {
|
|
66869
|
+
if (Array.isArray(value)) {
|
|
66870
|
+
return getFirstHeaderValue(value[0]);
|
|
66871
|
+
}
|
|
66872
|
+
if (typeof value !== "string") {
|
|
66873
|
+
return void 0;
|
|
66874
|
+
}
|
|
66875
|
+
const first = value.split(",")[0]?.trim();
|
|
66876
|
+
return first ? first : void 0;
|
|
66877
|
+
}
|
|
66878
|
+
function getForwardedHeaderOrigin(req) {
|
|
66879
|
+
const forwarded = getFirstHeaderValue(req.headers.forwarded);
|
|
66880
|
+
if (!forwarded) {
|
|
66881
|
+
return void 0;
|
|
66882
|
+
}
|
|
66883
|
+
let host;
|
|
66884
|
+
let proto;
|
|
66885
|
+
for (const segment of forwarded.split(";")) {
|
|
66886
|
+
const [rawKey, rawValue] = segment.split("=", 2);
|
|
66887
|
+
const key = rawKey?.trim().toLowerCase();
|
|
66888
|
+
const value = rawValue?.trim().replace(/^"|"$/g, "");
|
|
66889
|
+
if (!key || !value) {
|
|
66890
|
+
continue;
|
|
66891
|
+
}
|
|
66892
|
+
if (key === "host" && !host) {
|
|
66893
|
+
host = value;
|
|
66894
|
+
}
|
|
66895
|
+
if (key === "proto" && !proto) {
|
|
66896
|
+
proto = value;
|
|
66897
|
+
}
|
|
66898
|
+
}
|
|
66899
|
+
if (!host) {
|
|
66900
|
+
return void 0;
|
|
66901
|
+
}
|
|
66902
|
+
return `${proto ?? req.protocol ?? "http"}://${host}`;
|
|
66903
|
+
}
|
|
66904
|
+
function resolveRequestOrigin(req) {
|
|
66905
|
+
const forwardedOrigin = getForwardedHeaderOrigin(req);
|
|
66906
|
+
if (forwardedOrigin) {
|
|
66907
|
+
return forwardedOrigin;
|
|
66908
|
+
}
|
|
66909
|
+
const host = getFirstHeaderValue(req.headers["x-forwarded-host"]) ?? getFirstHeaderValue(req.headers.host) ?? req.get("host");
|
|
66910
|
+
if (!host) {
|
|
66911
|
+
return void 0;
|
|
66912
|
+
}
|
|
66913
|
+
const proto = getFirstHeaderValue(req.headers["x-forwarded-proto"]) ?? req.protocol ?? "http";
|
|
66914
|
+
return `${proto}://${host}`;
|
|
66915
|
+
}
|
|
66916
|
+
|
|
66917
|
+
// ../../packages/api/src/routes/node-preview.ts
|
|
66918
|
+
var NODE_PREVIEW_PROXY_TIMEOUT_MS = 1e4;
|
|
66919
|
+
function sendNodePreviewMessageResponse(req, res, nodeId, response) {
|
|
66920
|
+
if (response.bodyEncoding === "json" && isPreviewSessionPayload(response.body)) {
|
|
66921
|
+
res.status(response.statusCode).json(
|
|
66922
|
+
rewriteNodePreviewPayloadForProxy(req.app.locals.deps, response.body, nodeId)
|
|
66923
|
+
);
|
|
66924
|
+
return;
|
|
66925
|
+
}
|
|
66926
|
+
sendWorkerControlResponse(res, response);
|
|
66927
|
+
}
|
|
66928
|
+
async function sendNodePreviewSessionCreate(req, res, nodeId) {
|
|
66929
|
+
const body = NodePreviewSessionBody.parse(req.body ?? {});
|
|
66930
|
+
const deps = req.app.locals.deps;
|
|
66931
|
+
const self2 = deps.nodeRegistry.getSelf();
|
|
66932
|
+
const node = deps.nodeRegistry.getNode(nodeId);
|
|
66933
|
+
if (!node) {
|
|
66934
|
+
throw new MeshyError("NODE_NOT_FOUND", `Node ${nodeId} not found`, 404);
|
|
66935
|
+
}
|
|
66936
|
+
if (nodeId === self2.id) {
|
|
66937
|
+
res.json(await createNodePreviewSessionPayload(deps, nodeId, body, resolveRequestOrigin(req)));
|
|
66938
|
+
return;
|
|
66939
|
+
}
|
|
66940
|
+
const message = createNodeMessage("node.preview.create", {
|
|
66941
|
+
port: body.port,
|
|
66942
|
+
path: body.path
|
|
66943
|
+
}, { expectsResponse: true });
|
|
66944
|
+
const heartbeat = deps.heartbeat;
|
|
66945
|
+
const canPushToNode = heartbeat?.canPushToNode?.(nodeId) ?? true;
|
|
66946
|
+
let response;
|
|
66947
|
+
if (!canPushToNode && canRequestNodeMessage(heartbeat)) {
|
|
66948
|
+
response = await requestFallbackNodeMessage(heartbeat, nodeId, message, NODE_PREVIEW_PROXY_TIMEOUT_MS);
|
|
66949
|
+
} else {
|
|
66950
|
+
try {
|
|
66951
|
+
response = await new NodeMessageClient({
|
|
66952
|
+
logger: deps.logger,
|
|
66953
|
+
timeoutMs: NODE_PREVIEW_PROXY_TIMEOUT_MS
|
|
66954
|
+
}).request(node, message);
|
|
66955
|
+
} catch (err) {
|
|
66956
|
+
if (!canRequestNodeMessage(heartbeat)) {
|
|
66957
|
+
throw new MeshyError("NODE_OFFLINE", `Cannot reach node ${nodeId} for service preview`, 502, {
|
|
66958
|
+
error: err instanceof Error ? err.message : String(err)
|
|
66959
|
+
});
|
|
66960
|
+
}
|
|
66961
|
+
response = await requestFallbackNodeMessage(heartbeat, nodeId, message, NODE_PREVIEW_PROXY_TIMEOUT_MS);
|
|
66962
|
+
}
|
|
66963
|
+
}
|
|
66964
|
+
sendNodePreviewMessageResponse(req, res, nodeId, response);
|
|
66965
|
+
}
|
|
66966
|
+
|
|
66782
66967
|
// ../../packages/api/src/routes/node-terminal.ts
|
|
66783
66968
|
init_cjs_shims();
|
|
66784
66969
|
var TERMINAL_SESSION_PROXY_TIMEOUT_MS = 1e4;
|
|
@@ -67264,6 +67449,9 @@ function createNodeRoutes() {
|
|
|
67264
67449
|
router.post("/:id/terminal/sessions/:sessionId/stop", asyncHandler3(async (req, res) => {
|
|
67265
67450
|
await sendNodeTerminalSessionStop(req, res, req.params.id, req.params.sessionId);
|
|
67266
67451
|
}));
|
|
67452
|
+
router.post("/:id/preview-sessions", asyncHandler3(async (req, res) => {
|
|
67453
|
+
await sendNodePreviewSessionCreate(req, res, req.params.id);
|
|
67454
|
+
}));
|
|
67267
67455
|
router.post("/:id/workdir/branch", asyncHandler3(async (req, res) => {
|
|
67268
67456
|
const nodeId = req.params.id;
|
|
67269
67457
|
await sendNodeWorkDirBranchCreateOperation(req, res, nodeId);
|
|
@@ -68298,59 +68486,6 @@ function buildTaskListResult(tasks, nodeRegistry, options) {
|
|
|
68298
68486
|
// ../../packages/api/src/routes/task-output.ts
|
|
68299
68487
|
init_cjs_shims();
|
|
68300
68488
|
var import_express9 = __toESM(require_express2(), 1);
|
|
68301
|
-
|
|
68302
|
-
// ../../packages/api/src/app/request-origin.ts
|
|
68303
|
-
init_cjs_shims();
|
|
68304
|
-
function getFirstHeaderValue(value) {
|
|
68305
|
-
if (Array.isArray(value)) {
|
|
68306
|
-
return getFirstHeaderValue(value[0]);
|
|
68307
|
-
}
|
|
68308
|
-
if (typeof value !== "string") {
|
|
68309
|
-
return void 0;
|
|
68310
|
-
}
|
|
68311
|
-
const first = value.split(",")[0]?.trim();
|
|
68312
|
-
return first ? first : void 0;
|
|
68313
|
-
}
|
|
68314
|
-
function getForwardedHeaderOrigin(req) {
|
|
68315
|
-
const forwarded = getFirstHeaderValue(req.headers.forwarded);
|
|
68316
|
-
if (!forwarded) {
|
|
68317
|
-
return void 0;
|
|
68318
|
-
}
|
|
68319
|
-
let host;
|
|
68320
|
-
let proto;
|
|
68321
|
-
for (const segment of forwarded.split(";")) {
|
|
68322
|
-
const [rawKey, rawValue] = segment.split("=", 2);
|
|
68323
|
-
const key = rawKey?.trim().toLowerCase();
|
|
68324
|
-
const value = rawValue?.trim().replace(/^"|"$/g, "");
|
|
68325
|
-
if (!key || !value) {
|
|
68326
|
-
continue;
|
|
68327
|
-
}
|
|
68328
|
-
if (key === "host" && !host) {
|
|
68329
|
-
host = value;
|
|
68330
|
-
}
|
|
68331
|
-
if (key === "proto" && !proto) {
|
|
68332
|
-
proto = value;
|
|
68333
|
-
}
|
|
68334
|
-
}
|
|
68335
|
-
if (!host) {
|
|
68336
|
-
return void 0;
|
|
68337
|
-
}
|
|
68338
|
-
return `${proto ?? req.protocol ?? "http"}://${host}`;
|
|
68339
|
-
}
|
|
68340
|
-
function resolveRequestOrigin(req) {
|
|
68341
|
-
const forwardedOrigin = getForwardedHeaderOrigin(req);
|
|
68342
|
-
if (forwardedOrigin) {
|
|
68343
|
-
return forwardedOrigin;
|
|
68344
|
-
}
|
|
68345
|
-
const host = getFirstHeaderValue(req.headers["x-forwarded-host"]) ?? getFirstHeaderValue(req.headers.host) ?? req.get("host");
|
|
68346
|
-
if (!host) {
|
|
68347
|
-
return void 0;
|
|
68348
|
-
}
|
|
68349
|
-
const proto = getFirstHeaderValue(req.headers["x-forwarded-proto"]) ?? req.protocol ?? "http";
|
|
68350
|
-
return `${proto}://${host}`;
|
|
68351
|
-
}
|
|
68352
|
-
|
|
68353
|
-
// ../../packages/api/src/routes/task-output.ts
|
|
68354
68489
|
var TASK_OUTPUT_PROXY_TIMEOUT_MS = 1e4;
|
|
68355
68490
|
function describeProxyError4(error2) {
|
|
68356
68491
|
if (error2 instanceof Error) {
|
|
@@ -68413,7 +68548,7 @@ function createTaskOutputProxyTrace(log2, taskId, assignedTo, kind, proxyPath) {
|
|
|
68413
68548
|
function asyncHandler7(fn) {
|
|
68414
68549
|
return (req, res, next) => fn(req, res, next).catch(next);
|
|
68415
68550
|
}
|
|
68416
|
-
function
|
|
68551
|
+
function isPreviewSessionPayload2(value) {
|
|
68417
68552
|
return typeof value === "object" && value !== null && typeof value.previewUrl === "string" && typeof value.entryPath === "string" && typeof value.expiresAt === "number";
|
|
68418
68553
|
}
|
|
68419
68554
|
function rewritePreviewPayloadIfNeeded(req, nodeId, payload) {
|
|
@@ -68430,7 +68565,7 @@ function withTaskSnapshot(message, task) {
|
|
|
68430
68565
|
async function sendTaskOutputProxyResponse(req, res, nodeId, proxyRes, fallbackRequest) {
|
|
68431
68566
|
if (fallbackRequest?.kind === "task.preview.create" && proxyRes.ok) {
|
|
68432
68567
|
const body = await proxyRes.json().catch(() => null);
|
|
68433
|
-
if (
|
|
68568
|
+
if (isPreviewSessionPayload2(body)) {
|
|
68434
68569
|
res.status(proxyRes.status).json(rewritePreviewPayloadIfNeeded(req, nodeId, body));
|
|
68435
68570
|
return;
|
|
68436
68571
|
}
|
|
@@ -68467,7 +68602,7 @@ async function maybeHandleRemoteTaskOutputRequest(req, res, taskId, subPath, ini
|
|
|
68467
68602
|
kind: hydratedFallbackRequest2.kind
|
|
68468
68603
|
});
|
|
68469
68604
|
const controlResponse = await requestFallbackNodeMessage(heartbeat, assignedNodeId, hydratedFallbackRequest2);
|
|
68470
|
-
if (hydratedFallbackRequest2.kind === "task.preview.create" && controlResponse.bodyEncoding === "json" &&
|
|
68605
|
+
if (hydratedFallbackRequest2.kind === "task.preview.create" && controlResponse.bodyEncoding === "json" && isPreviewSessionPayload2(controlResponse.body)) {
|
|
68471
68606
|
res.status(controlResponse.statusCode).json(
|
|
68472
68607
|
rewritePreviewPayloadIfNeeded(req, assignedNodeId, controlResponse.body)
|
|
68473
68608
|
);
|
|
@@ -68526,7 +68661,7 @@ async function maybeHandleRemoteTaskOutputRequest(req, res, taskId, subPath, ini
|
|
|
68526
68661
|
...describeProxyError4(err)
|
|
68527
68662
|
});
|
|
68528
68663
|
const controlResponse = await requestFallbackNodeMessage(heartbeat, assignedNodeId, hydratedFallbackRequest);
|
|
68529
|
-
if (hydratedFallbackRequest.kind === "task.preview.create" && controlResponse.bodyEncoding === "json" &&
|
|
68664
|
+
if (hydratedFallbackRequest.kind === "task.preview.create" && controlResponse.bodyEncoding === "json" && isPreviewSessionPayload2(controlResponse.body)) {
|
|
68530
68665
|
res.status(controlResponse.statusCode).json(
|
|
68531
68666
|
rewritePreviewPayloadIfNeeded(req, assignedNodeId, controlResponse.body)
|
|
68532
68667
|
);
|
package/package.json
CHANGED
package/runtime-metadata.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"packageName": "meshy-node",
|
|
3
|
-
"packageVersion": "0.9.
|
|
3
|
+
"packageVersion": "0.9.4",
|
|
4
4
|
"packages": {
|
|
5
5
|
"workspace": {
|
|
6
6
|
"name": "meshy",
|
|
7
|
-
"version": "0.9.
|
|
7
|
+
"version": "0.9.4"
|
|
8
8
|
},
|
|
9
9
|
"node": {
|
|
10
10
|
"name": "meshy-node",
|
|
11
|
-
"version": "0.9.
|
|
11
|
+
"version": "0.9.4"
|
|
12
12
|
},
|
|
13
13
|
"core": {
|
|
14
14
|
"name": "@meshy/core",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"repository": {
|
|
27
27
|
"url": "https://github.com/ai-microsoft/meshy",
|
|
28
28
|
"branch": "main",
|
|
29
|
-
"commit": "
|
|
29
|
+
"commit": "a741ca6"
|
|
30
30
|
}
|
|
31
31
|
}
|