@buildautomaton/cli 0.1.59 → 0.1.60
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/dist/cli.js +200 -200
- package/dist/cli.js.map +3 -3
- package/dist/index.js +200 -200
- package/dist/index.js.map +3 -3
- package/package.json +2 -3
package/dist/cli.js
CHANGED
|
@@ -25631,7 +25631,7 @@ var {
|
|
|
25631
25631
|
} = import_index.default;
|
|
25632
25632
|
|
|
25633
25633
|
// src/cli-version.ts
|
|
25634
|
-
var CLI_VERSION = "0.1.
|
|
25634
|
+
var CLI_VERSION = "0.1.60".length > 0 ? "0.1.60" : "0.0.0-dev";
|
|
25635
25635
|
|
|
25636
25636
|
// src/cli/defaults.ts
|
|
25637
25637
|
var DEFAULT_API_URL = process.env.BUILDAUTOMATON_API_URL ?? "https://api.buildautomaton.com";
|
|
@@ -27439,8 +27439,8 @@ function runPendingAuth(options) {
|
|
|
27439
27439
|
};
|
|
27440
27440
|
}
|
|
27441
27441
|
|
|
27442
|
-
// src/
|
|
27443
|
-
var
|
|
27442
|
+
// src/preview-environments/manager/preview-environment-constants.ts
|
|
27443
|
+
var BRIDGE_CLOSE_PREVIEW_ENVIRONMENT_GRACE_MS = 0;
|
|
27444
27444
|
var BRIDGE_SHUTDOWN_GRACE_MS = 8e3;
|
|
27445
27445
|
|
|
27446
27446
|
// src/runtime/cli-process-interrupt.ts
|
|
@@ -28147,7 +28147,7 @@ async function ensureCodeNavCacheSqliteInitialized() {
|
|
|
28147
28147
|
}
|
|
28148
28148
|
|
|
28149
28149
|
// src/connection/close-bridge-connection.ts
|
|
28150
|
-
async function closeBridgeConnection(state, acpManager,
|
|
28150
|
+
async function closeBridgeConnection(state, acpManager, previewEnvironmentManager, log2) {
|
|
28151
28151
|
requestCliImmediateShutdown();
|
|
28152
28152
|
const say = log2 ?? logImmediate;
|
|
28153
28153
|
say("Cleaning up connections\u2026");
|
|
@@ -28185,9 +28185,9 @@ async function closeBridgeConnection(state, acpManager, devServerManager, log2)
|
|
|
28185
28185
|
}
|
|
28186
28186
|
state.currentWs = null;
|
|
28187
28187
|
}
|
|
28188
|
-
if (
|
|
28189
|
-
say("Stopping local
|
|
28190
|
-
await
|
|
28188
|
+
if (previewEnvironmentManager) {
|
|
28189
|
+
say("Stopping local preview environment processes\u2026");
|
|
28190
|
+
await previewEnvironmentManager.shutdownAllGraceful({ graceMs: BRIDGE_CLOSE_PREVIEW_ENVIRONMENT_GRACE_MS });
|
|
28191
28191
|
}
|
|
28192
28192
|
try {
|
|
28193
28193
|
closeAllCliSqliteConnections();
|
|
@@ -43613,12 +43613,12 @@ function startFileIndexWatcher(cwd = getBridgeRoot()) {
|
|
|
43613
43613
|
// src/connection/create-bridge-connection.ts
|
|
43614
43614
|
import * as path74 from "node:path";
|
|
43615
43615
|
|
|
43616
|
-
// src/
|
|
43616
|
+
// src/preview-environments/manager/preview-environment-manager.ts
|
|
43617
43617
|
import { rm as rm2 } from "node:fs/promises";
|
|
43618
43618
|
|
|
43619
|
-
// src/
|
|
43620
|
-
function
|
|
43621
|
-
const payload = { type: "
|
|
43619
|
+
// src/preview-environments/process/send-preview-environment-status.ts
|
|
43620
|
+
function sendPreviewEnvironmentStatus(getWs, environmentId, status, options) {
|
|
43621
|
+
const payload = { type: "preview_environment_status", environmentId, status };
|
|
43622
43622
|
if (options?.detail) payload.detail = options.detail;
|
|
43623
43623
|
if (options?.tails) {
|
|
43624
43624
|
payload.stdoutTail = options.tails.stdout;
|
|
@@ -43631,12 +43631,12 @@ function sendDevServerStatus(getWs, serverId, status, options) {
|
|
|
43631
43631
|
});
|
|
43632
43632
|
}
|
|
43633
43633
|
|
|
43634
|
-
// src/
|
|
43634
|
+
// src/preview-environments/process/terminate-child-process.ts
|
|
43635
43635
|
async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
|
|
43636
43636
|
const exited = new Promise((resolve34) => {
|
|
43637
43637
|
proc.once("exit", () => resolve34());
|
|
43638
43638
|
});
|
|
43639
|
-
log2(`[
|
|
43639
|
+
log2(`[preview-environment] Sending SIGTERM to ${shortId} (pid=${proc.pid ?? "?"}).`);
|
|
43640
43640
|
try {
|
|
43641
43641
|
proc.kill("SIGTERM");
|
|
43642
43642
|
} catch {
|
|
@@ -43645,7 +43645,7 @@ async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
|
|
|
43645
43645
|
}
|
|
43646
43646
|
function forceKillChild(proc, log2, shortId, graceMs) {
|
|
43647
43647
|
log2(
|
|
43648
|
-
`[
|
|
43648
|
+
`[preview-environment] ${shortId} did not exit within ${graceMs}ms; sending SIGKILL (pid=${proc.pid ?? "?"}).`
|
|
43649
43649
|
);
|
|
43650
43650
|
proc.removeAllListeners();
|
|
43651
43651
|
try {
|
|
@@ -43654,10 +43654,10 @@ function forceKillChild(proc, log2, shortId, graceMs) {
|
|
|
43654
43654
|
}
|
|
43655
43655
|
}
|
|
43656
43656
|
|
|
43657
|
-
// src/
|
|
43657
|
+
// src/preview-environments/process/wire-preview-environment-child-process.ts
|
|
43658
43658
|
import fs37 from "node:fs";
|
|
43659
43659
|
|
|
43660
|
-
// src/
|
|
43660
|
+
// src/preview-environments/manager/forward-pipe.ts
|
|
43661
43661
|
function forwardChildPipe(childReadable, terminal, onData) {
|
|
43662
43662
|
if (!childReadable) return;
|
|
43663
43663
|
childReadable.on("data", (chunk) => {
|
|
@@ -43673,16 +43673,16 @@ function forwardChildPipe(childReadable, terminal, onData) {
|
|
|
43673
43673
|
});
|
|
43674
43674
|
}
|
|
43675
43675
|
|
|
43676
|
-
// src/
|
|
43677
|
-
function
|
|
43678
|
-
const { proc,
|
|
43676
|
+
// src/preview-environments/process/wire-preview-environment-child-process.ts
|
|
43677
|
+
function wirePreviewEnvironmentChildProcess(d) {
|
|
43678
|
+
const { proc, environmentId, title } = d;
|
|
43679
43679
|
forwardChildPipe(proc.stdout, null, (chunk) => {
|
|
43680
43680
|
d.stdoutTail.push(chunk);
|
|
43681
|
-
d.pushRemoteLogChunk(
|
|
43681
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
43682
43682
|
});
|
|
43683
43683
|
forwardChildPipe(proc.stderr, null, (chunk) => {
|
|
43684
43684
|
d.stderrTail.push(chunk);
|
|
43685
|
-
d.pushRemoteLogChunk(
|
|
43685
|
+
d.pushRemoteLogChunk(environmentId, "stderr", chunk);
|
|
43686
43686
|
});
|
|
43687
43687
|
if (d.mergedLogPath && d.mergedCleanupDir) {
|
|
43688
43688
|
const pollIv = setInterval(() => {
|
|
@@ -43698,7 +43698,7 @@ function wireDevServerChildProcess(d) {
|
|
|
43698
43698
|
d.mergedReadPos.value = buf.length;
|
|
43699
43699
|
if (chunk.length === 0) return;
|
|
43700
43700
|
d.stdoutTail.push(chunk);
|
|
43701
|
-
d.pushRemoteLogChunk(
|
|
43701
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
43702
43702
|
});
|
|
43703
43703
|
}, 100);
|
|
43704
43704
|
d.setPollInterval(pollIv);
|
|
@@ -43716,10 +43716,10 @@ function wireDevServerChildProcess(d) {
|
|
|
43716
43716
|
d.rmMergedCleanupDir(cleanupDir);
|
|
43717
43717
|
}
|
|
43718
43718
|
if (signal) {
|
|
43719
|
-
d.log(`[
|
|
43719
|
+
d.log(`[preview-environment] ${title} stopped (signal: ${String(signal)}).`);
|
|
43720
43720
|
} else if (code !== null && code !== 0) {
|
|
43721
43721
|
const errTail = d.stderrTail.getTail().slice(-3).join("\n");
|
|
43722
|
-
d.log(`[
|
|
43722
|
+
d.log(`[preview-environment] ${title} exited with code ${code}${errTail ? `
|
|
43723
43723
|
${errTail}` : ""}`);
|
|
43724
43724
|
}
|
|
43725
43725
|
d.detachProcessFromManager();
|
|
@@ -43734,7 +43734,7 @@ ${errTail}` : ""}`);
|
|
|
43734
43734
|
const chunk = Buffer.from(buf.subarray(d.mergedReadPos.value));
|
|
43735
43735
|
if (chunk.length > 0) {
|
|
43736
43736
|
d.stdoutTail.push(chunk);
|
|
43737
|
-
d.pushRemoteLogChunk(
|
|
43737
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
43738
43738
|
}
|
|
43739
43739
|
}
|
|
43740
43740
|
finishExit();
|
|
@@ -43758,12 +43758,12 @@ ${errTail}` : ""}`);
|
|
|
43758
43758
|
d.clearTailBuffers();
|
|
43759
43759
|
const msg = err instanceof Error ? err.message : String(err);
|
|
43760
43760
|
const errno = typeof err === "object" && err && "code" in err ? String(err.code) : "";
|
|
43761
|
-
d.log(`[
|
|
43761
|
+
d.log(`[preview-environment] ${title} process error: ${msg}${errno ? ` (${errno})` : ""}`);
|
|
43762
43762
|
d.sendStatus("error", msg, tails);
|
|
43763
43763
|
});
|
|
43764
43764
|
}
|
|
43765
43765
|
|
|
43766
|
-
// src/
|
|
43766
|
+
// src/preview-environments/manager/preview-environment-env.ts
|
|
43767
43767
|
function substituteCommand(cmd, env) {
|
|
43768
43768
|
return cmd.replace(/\$\{([^}]+)\}/g, (_, key) => env[key] != null ? String(env[key]) : "");
|
|
43769
43769
|
}
|
|
@@ -43799,15 +43799,15 @@ function envForSpawn(base, userEnv, ports) {
|
|
|
43799
43799
|
return out;
|
|
43800
43800
|
}
|
|
43801
43801
|
|
|
43802
|
-
// src/
|
|
43803
|
-
function
|
|
43802
|
+
// src/preview-environments/manager/parse-config.ts
|
|
43803
|
+
function parsePreviewEnvironmentDefs(servers) {
|
|
43804
43804
|
const out = [];
|
|
43805
43805
|
if (!Array.isArray(servers)) return out;
|
|
43806
43806
|
for (const s of servers) {
|
|
43807
43807
|
if (!s || typeof s !== "object") continue;
|
|
43808
43808
|
const o = s;
|
|
43809
|
-
const
|
|
43810
|
-
if (!
|
|
43809
|
+
const environmentId = typeof o.environmentId === "string" ? o.environmentId : "";
|
|
43810
|
+
if (!environmentId) continue;
|
|
43811
43811
|
const envRaw = o.env;
|
|
43812
43812
|
const env = Array.isArray(envRaw) ? envRaw.map((e) => {
|
|
43813
43813
|
if (!e || typeof e !== "object") return null;
|
|
@@ -43820,7 +43820,7 @@ function parseDevServerDefs(servers) {
|
|
|
43820
43820
|
const portsRaw = o.ports;
|
|
43821
43821
|
const ports = Array.isArray(portsRaw) ? portsRaw.filter((p) => typeof p === "number" && Number.isInteger(p) && p > 0 && p < 65536) : [];
|
|
43822
43822
|
out.push({
|
|
43823
|
-
|
|
43823
|
+
environmentId,
|
|
43824
43824
|
name: typeof o.name === "string" ? o.name : "",
|
|
43825
43825
|
command: typeof o.command === "string" ? o.command : "",
|
|
43826
43826
|
env,
|
|
@@ -43830,7 +43830,7 @@ function parseDevServerDefs(servers) {
|
|
|
43830
43830
|
return out;
|
|
43831
43831
|
}
|
|
43832
43832
|
|
|
43833
|
-
// src/
|
|
43833
|
+
// src/preview-environments/manager/shell-spawn/utils.ts
|
|
43834
43834
|
import fs38 from "node:fs";
|
|
43835
43835
|
function isSpawnEbadf(e) {
|
|
43836
43836
|
return typeof e === "object" && e !== null && "code" in e && e.code === "EBADF";
|
|
@@ -43853,7 +43853,7 @@ function pipedStdoutStderrFor(attemptStdio) {
|
|
|
43853
43853
|
return attemptStdio !== "inherit" && Array.isArray(attemptStdio) && attemptStdio[1] === "pipe" && attemptStdio[2] === "pipe";
|
|
43854
43854
|
}
|
|
43855
43855
|
|
|
43856
|
-
// src/
|
|
43856
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-piped-via-sh.ts
|
|
43857
43857
|
import { spawn as spawn5 } from "node:child_process";
|
|
43858
43858
|
function trySpawnPipedViaSh(command, env, cwd, signal) {
|
|
43859
43859
|
const attempts = [
|
|
@@ -43896,7 +43896,7 @@ function trySpawnPipedViaSh(command, env, cwd, signal) {
|
|
|
43896
43896
|
return { ok: false, lastErr };
|
|
43897
43897
|
}
|
|
43898
43898
|
|
|
43899
|
-
// src/
|
|
43899
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-shell-true-piped.ts
|
|
43900
43900
|
import { spawn as spawn6 } from "node:child_process";
|
|
43901
43901
|
function trySpawnShellTruePiped(command, env, cwd, devNullFd, signal) {
|
|
43902
43902
|
try {
|
|
@@ -43917,7 +43917,7 @@ function trySpawnShellTruePiped(command, env, cwd, devNullFd, signal) {
|
|
|
43917
43917
|
}
|
|
43918
43918
|
}
|
|
43919
43919
|
|
|
43920
|
-
// src/
|
|
43920
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-merged-log-file.ts
|
|
43921
43921
|
import { spawn as spawn7 } from "node:child_process";
|
|
43922
43922
|
import fs39 from "node:fs";
|
|
43923
43923
|
import { tmpdir } from "node:os";
|
|
@@ -43964,7 +43964,7 @@ function trySpawnMergedLogFile(command, env, cwd, signal) {
|
|
|
43964
43964
|
}
|
|
43965
43965
|
}
|
|
43966
43966
|
|
|
43967
|
-
// src/
|
|
43967
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-shell-script-log-redirect.ts
|
|
43968
43968
|
import { spawn as spawn8 } from "node:child_process";
|
|
43969
43969
|
import fs40 from "node:fs";
|
|
43970
43970
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
@@ -44040,7 +44040,7 @@ ${command} >> ${q(logPath)} 2>&1\r
|
|
|
44040
44040
|
}
|
|
44041
44041
|
}
|
|
44042
44042
|
|
|
44043
|
-
// src/
|
|
44043
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-inherit.ts
|
|
44044
44044
|
import { spawn as spawn9 } from "node:child_process";
|
|
44045
44045
|
function trySpawnInheritStdio(command, env, cwd, signal) {
|
|
44046
44046
|
const opts = {
|
|
@@ -44060,7 +44060,7 @@ function trySpawnInheritStdio(command, env, cwd, signal) {
|
|
|
44060
44060
|
return { proc, pipedStdoutStderr: false };
|
|
44061
44061
|
}
|
|
44062
44062
|
|
|
44063
|
-
// src/
|
|
44063
|
+
// src/preview-environments/manager/shell-spawn/shell-spawn.ts
|
|
44064
44064
|
function shellSpawn(command, env, cwd, options) {
|
|
44065
44065
|
const signal = options?.signal;
|
|
44066
44066
|
const piped = trySpawnPipedViaSh(command, env, cwd, signal);
|
|
@@ -44087,7 +44087,7 @@ function shellSpawn(command, env, cwd, options) {
|
|
|
44087
44087
|
}
|
|
44088
44088
|
}
|
|
44089
44089
|
|
|
44090
|
-
// src/
|
|
44090
|
+
// src/preview-environments/manager/stream-tail.ts
|
|
44091
44091
|
var MAX_TAIL_LINES = 80;
|
|
44092
44092
|
var MAX_LINE_CHARS = 8192;
|
|
44093
44093
|
var MAX_PENDING_CHARS = 65536;
|
|
@@ -44123,11 +44123,11 @@ var StreamTail = class {
|
|
|
44123
44123
|
}
|
|
44124
44124
|
};
|
|
44125
44125
|
|
|
44126
|
-
// src/
|
|
44126
|
+
// src/preview-environments/manager/preview-environment-firehose-messages.ts
|
|
44127
44127
|
function buildFirehoseSnapshotMessage(params) {
|
|
44128
44128
|
const payload = {
|
|
44129
44129
|
type: "log_snapshot",
|
|
44130
|
-
|
|
44130
|
+
environmentId: params.environmentId,
|
|
44131
44131
|
viewerId: params.viewerId,
|
|
44132
44132
|
stdoutTail: params.tails.stdout,
|
|
44133
44133
|
stderrTail: params.tails.stderr
|
|
@@ -44137,15 +44137,15 @@ function buildFirehoseSnapshotMessage(params) {
|
|
|
44137
44137
|
function buildFirehoseLogChunkMessage(params) {
|
|
44138
44138
|
const payload = {
|
|
44139
44139
|
type: "log_chunk",
|
|
44140
|
-
|
|
44140
|
+
environmentId: params.environmentId,
|
|
44141
44141
|
stream: params.stream,
|
|
44142
44142
|
text: params.text
|
|
44143
44143
|
};
|
|
44144
44144
|
return params.e2ee ? params.e2ee.encryptFields(payload, ["text"]) : payload;
|
|
44145
44145
|
}
|
|
44146
44146
|
|
|
44147
|
-
// src/
|
|
44148
|
-
var
|
|
44147
|
+
// src/preview-environments/manager/preview-environment-firehose-sink.ts
|
|
44148
|
+
var PreviewEnvironmentFirehoseSink = class {
|
|
44149
44149
|
constructor(options) {
|
|
44150
44150
|
this.options = options;
|
|
44151
44151
|
}
|
|
@@ -44158,31 +44158,31 @@ var DevServerFirehoseSink = class {
|
|
|
44158
44158
|
this.firehoseSend = null;
|
|
44159
44159
|
this.logViewerRefCountByServerId.clear();
|
|
44160
44160
|
}
|
|
44161
|
-
openLogViewer(
|
|
44162
|
-
const next = (this.logViewerRefCountByServerId.get(
|
|
44163
|
-
this.logViewerRefCountByServerId.set(
|
|
44164
|
-
this.sendSnapshot(
|
|
44161
|
+
openLogViewer(environmentId, viewerId) {
|
|
44162
|
+
const next = (this.logViewerRefCountByServerId.get(environmentId) ?? 0) + 1;
|
|
44163
|
+
this.logViewerRefCountByServerId.set(environmentId, next);
|
|
44164
|
+
this.sendSnapshot(environmentId, viewerId);
|
|
44165
44165
|
}
|
|
44166
|
-
closeLogViewer(
|
|
44167
|
-
const n = (this.logViewerRefCountByServerId.get(
|
|
44168
|
-
if (n <= 0) this.logViewerRefCountByServerId.delete(
|
|
44169
|
-
else this.logViewerRefCountByServerId.set(
|
|
44166
|
+
closeLogViewer(environmentId) {
|
|
44167
|
+
const n = (this.logViewerRefCountByServerId.get(environmentId) ?? 0) - 1;
|
|
44168
|
+
if (n <= 0) this.logViewerRefCountByServerId.delete(environmentId);
|
|
44169
|
+
else this.logViewerRefCountByServerId.set(environmentId, n);
|
|
44170
44170
|
}
|
|
44171
|
-
pushLogChunk(
|
|
44172
|
-
if ((this.logViewerRefCountByServerId.get(
|
|
44173
|
-
if (!this.options.isPipedCaptureEnabled(
|
|
44171
|
+
pushLogChunk(environmentId, stream, chunk) {
|
|
44172
|
+
if ((this.logViewerRefCountByServerId.get(environmentId) ?? 0) <= 0) return;
|
|
44173
|
+
if (!this.options.isPipedCaptureEnabled(environmentId)) return;
|
|
44174
44174
|
if (!this.firehoseSend) return;
|
|
44175
44175
|
const text = chunk.toString("utf8");
|
|
44176
44176
|
setImmediate(() => {
|
|
44177
44177
|
if (!this.firehoseSend) return;
|
|
44178
|
-
this.firehoseSend(buildFirehoseLogChunkMessage({
|
|
44178
|
+
this.firehoseSend(buildFirehoseLogChunkMessage({ environmentId, stream, text, e2ee: this.options.e2ee }));
|
|
44179
44179
|
});
|
|
44180
44180
|
}
|
|
44181
|
-
sendSnapshot(
|
|
44181
|
+
sendSnapshot(environmentId, viewerId) {
|
|
44182
44182
|
const payload = buildFirehoseSnapshotMessage({
|
|
44183
|
-
|
|
44183
|
+
environmentId,
|
|
44184
44184
|
viewerId,
|
|
44185
|
-
tails: this.options.getTails(
|
|
44185
|
+
tails: this.options.getTails(environmentId),
|
|
44186
44186
|
e2ee: this.options.e2ee
|
|
44187
44187
|
});
|
|
44188
44188
|
setImmediate(() => {
|
|
@@ -44193,19 +44193,19 @@ var DevServerFirehoseSink = class {
|
|
|
44193
44193
|
}
|
|
44194
44194
|
};
|
|
44195
44195
|
|
|
44196
|
-
// src/
|
|
44196
|
+
// src/preview-environments/manager/cleanup-merged-log-dir.ts
|
|
44197
44197
|
import { rm } from "node:fs/promises";
|
|
44198
|
-
function cleanupMergedLogDirForServer(map2,
|
|
44199
|
-
const mergedDir = map2.get(
|
|
44198
|
+
function cleanupMergedLogDirForServer(map2, environmentId) {
|
|
44199
|
+
const mergedDir = map2.get(environmentId);
|
|
44200
44200
|
if (!mergedDir) return;
|
|
44201
|
-
map2.delete(
|
|
44201
|
+
map2.delete(environmentId);
|
|
44202
44202
|
void rm(mergedDir, { recursive: true, force: true }).catch(() => {
|
|
44203
44203
|
});
|
|
44204
44204
|
}
|
|
44205
44205
|
|
|
44206
|
-
// src/
|
|
44206
|
+
// src/preview-environments/manager/preview-environment-manager.ts
|
|
44207
44207
|
var emptyTails = () => ({ stdout: [], stderr: [] });
|
|
44208
|
-
var
|
|
44208
|
+
var PreviewEnvironmentManager = class {
|
|
44209
44209
|
defsById = /* @__PURE__ */ new Map();
|
|
44210
44210
|
processes = /* @__PURE__ */ new Map();
|
|
44211
44211
|
streamTailsByServerId = /* @__PURE__ */ new Map();
|
|
@@ -44224,9 +44224,9 @@ var DevServerManager = class {
|
|
|
44224
44224
|
this.log = options.log;
|
|
44225
44225
|
this.getBridgeRoot = options.getBridgeRoot ?? (() => process.cwd());
|
|
44226
44226
|
this.e2ee = options.e2ee;
|
|
44227
|
-
this.firehoseSink = new
|
|
44228
|
-
getTails: (
|
|
44229
|
-
isPipedCaptureEnabled: (
|
|
44227
|
+
this.firehoseSink = new PreviewEnvironmentFirehoseSink({
|
|
44228
|
+
getTails: (environmentId) => this.snapshotTails(environmentId),
|
|
44229
|
+
isPipedCaptureEnabled: (environmentId) => this.pipedCaptureByServerId.get(environmentId) === true,
|
|
44230
44230
|
e2ee: this.e2ee
|
|
44231
44231
|
});
|
|
44232
44232
|
}
|
|
@@ -44236,89 +44236,89 @@ var DevServerManager = class {
|
|
|
44236
44236
|
detachFirehose() {
|
|
44237
44237
|
this.firehoseSink.detach();
|
|
44238
44238
|
}
|
|
44239
|
-
handleFirehoseLogViewerOpen(
|
|
44240
|
-
this.firehoseSink.openLogViewer(
|
|
44239
|
+
handleFirehoseLogViewerOpen(environmentId, _viewerId) {
|
|
44240
|
+
this.firehoseSink.openLogViewer(environmentId, _viewerId);
|
|
44241
44241
|
}
|
|
44242
|
-
handleFirehoseLogViewerClose(
|
|
44243
|
-
this.firehoseSink.closeLogViewer(
|
|
44242
|
+
handleFirehoseLogViewerClose(environmentId, _viewerId) {
|
|
44243
|
+
this.firehoseSink.closeLogViewer(environmentId);
|
|
44244
44244
|
}
|
|
44245
44245
|
applyConfig(servers) {
|
|
44246
44246
|
this.defsById.clear();
|
|
44247
|
-
for (const d of
|
|
44248
|
-
this.defsById.set(d.
|
|
44247
|
+
for (const d of parsePreviewEnvironmentDefs(servers)) {
|
|
44248
|
+
this.defsById.set(d.environmentId, d);
|
|
44249
44249
|
}
|
|
44250
44250
|
}
|
|
44251
|
-
snapshotTails(
|
|
44252
|
-
const t = this.streamTailsByServerId.get(
|
|
44251
|
+
snapshotTails(environmentId) {
|
|
44252
|
+
const t = this.streamTailsByServerId.get(environmentId);
|
|
44253
44253
|
if (!t) return { stdout: [], stderr: [] };
|
|
44254
44254
|
return { stdout: t.stdout.getTail(), stderr: t.stderr.getTail() };
|
|
44255
44255
|
}
|
|
44256
|
-
clearTails(
|
|
44257
|
-
this.streamTailsByServerId.delete(
|
|
44256
|
+
clearTails(environmentId) {
|
|
44257
|
+
this.streamTailsByServerId.delete(environmentId);
|
|
44258
44258
|
}
|
|
44259
|
-
sendStatus(
|
|
44260
|
-
|
|
44259
|
+
sendStatus(environmentId, status, detail, tails) {
|
|
44260
|
+
sendPreviewEnvironmentStatus(this.getWs, environmentId, status, { detail, tails });
|
|
44261
44261
|
}
|
|
44262
|
-
bumpGeneration(
|
|
44263
|
-
const nextGen = (this.spawnGenerationByServerId.get(
|
|
44264
|
-
this.spawnGenerationByServerId.set(
|
|
44262
|
+
bumpGeneration(environmentId) {
|
|
44263
|
+
const nextGen = (this.spawnGenerationByServerId.get(environmentId) ?? 0) + 1;
|
|
44264
|
+
this.spawnGenerationByServerId.set(environmentId, nextGen);
|
|
44265
44265
|
}
|
|
44266
|
-
clearPoll(
|
|
44267
|
-
const poll = this.mergedLogPollByServerId.get(
|
|
44266
|
+
clearPoll(environmentId) {
|
|
44267
|
+
const poll = this.mergedLogPollByServerId.get(environmentId);
|
|
44268
44268
|
if (poll) {
|
|
44269
44269
|
clearInterval(poll);
|
|
44270
|
-
this.mergedLogPollByServerId.delete(
|
|
44270
|
+
this.mergedLogPollByServerId.delete(environmentId);
|
|
44271
44271
|
}
|
|
44272
44272
|
}
|
|
44273
|
-
abortSpawn(
|
|
44274
|
-
this.abortControllersByServerId.get(
|
|
44275
|
-
this.abortControllersByServerId.delete(
|
|
44273
|
+
abortSpawn(environmentId) {
|
|
44274
|
+
this.abortControllersByServerId.get(environmentId)?.abort();
|
|
44275
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
44276
44276
|
}
|
|
44277
|
-
stop(
|
|
44278
|
-
const tails = this.snapshotTails(
|
|
44279
|
-
if (this.processes.has(
|
|
44280
|
-
this.sendStatus(
|
|
44277
|
+
stop(environmentId) {
|
|
44278
|
+
const tails = this.snapshotTails(environmentId);
|
|
44279
|
+
if (this.processes.has(environmentId)) {
|
|
44280
|
+
this.sendStatus(environmentId, "stopping", void 0, tails);
|
|
44281
44281
|
}
|
|
44282
|
-
this.bumpGeneration(
|
|
44283
|
-
this.abortSpawn(
|
|
44284
|
-
this.clearPoll(
|
|
44285
|
-
const proc = this.processes.get(
|
|
44282
|
+
this.bumpGeneration(environmentId);
|
|
44283
|
+
this.abortSpawn(environmentId);
|
|
44284
|
+
this.clearPoll(environmentId);
|
|
44285
|
+
const proc = this.processes.get(environmentId);
|
|
44286
44286
|
if (proc) {
|
|
44287
44287
|
proc.removeAllListeners();
|
|
44288
44288
|
try {
|
|
44289
44289
|
proc.kill("SIGTERM");
|
|
44290
44290
|
} catch {
|
|
44291
44291
|
}
|
|
44292
|
-
this.processes.delete(
|
|
44292
|
+
this.processes.delete(environmentId);
|
|
44293
44293
|
}
|
|
44294
|
-
this.clearTails(
|
|
44295
|
-
this.pipedCaptureByServerId.delete(
|
|
44296
|
-
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId,
|
|
44297
|
-
this.sendStatus(
|
|
44294
|
+
this.clearTails(environmentId);
|
|
44295
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
44296
|
+
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId, environmentId);
|
|
44297
|
+
this.sendStatus(environmentId, "stopped", void 0, tails);
|
|
44298
44298
|
}
|
|
44299
|
-
start(
|
|
44300
|
-
const def = this.defsById.get(
|
|
44299
|
+
start(environmentId) {
|
|
44300
|
+
const def = this.defsById.get(environmentId);
|
|
44301
44301
|
if (!def) {
|
|
44302
|
-
this.log(`[
|
|
44303
|
-
this.sendStatus(
|
|
44302
|
+
this.log(`[preview-environment] Unknown server id ${environmentId.slice(0, 8)}\u2026`);
|
|
44303
|
+
this.sendStatus(environmentId, "error", "Unknown server", emptyTails());
|
|
44304
44304
|
return;
|
|
44305
44305
|
}
|
|
44306
44306
|
if (!def.command.trim()) {
|
|
44307
|
-
this.sendStatus(
|
|
44307
|
+
this.sendStatus(environmentId, "idle", "No command configured", emptyTails());
|
|
44308
44308
|
return;
|
|
44309
44309
|
}
|
|
44310
|
-
this.stop(
|
|
44311
|
-
this.sendStatus(
|
|
44310
|
+
this.stop(environmentId);
|
|
44311
|
+
this.sendStatus(environmentId, "starting", void 0, emptyTails());
|
|
44312
44312
|
const ac = new AbortController();
|
|
44313
|
-
this.abortControllersByServerId.set(
|
|
44313
|
+
this.abortControllersByServerId.set(environmentId, ac);
|
|
44314
44314
|
const cwd = this.getBridgeRoot();
|
|
44315
44315
|
const childEnv = envForSpawn(process.env, def.env, def.ports);
|
|
44316
44316
|
const cmd = substituteCommand(def.command.trim(), childEnv);
|
|
44317
|
-
const title = def.name.trim() ||
|
|
44318
|
-
this.log(`[
|
|
44319
|
-
const scheduledGen = this.spawnGenerationByServerId.get(
|
|
44317
|
+
const title = def.name.trim() || environmentId.slice(0, 8);
|
|
44318
|
+
this.log(`[preview-environment] Starting ${title}: ${cmd.slice(0, 120)}${cmd.length > 120 ? "\u2026" : ""}`);
|
|
44319
|
+
const scheduledGen = this.spawnGenerationByServerId.get(environmentId) ?? 0;
|
|
44320
44320
|
setImmediate(() => {
|
|
44321
|
-
if ((this.spawnGenerationByServerId.get(
|
|
44321
|
+
if ((this.spawnGenerationByServerId.get(environmentId) ?? 0) !== scheduledGen) {
|
|
44322
44322
|
return;
|
|
44323
44323
|
}
|
|
44324
44324
|
let proc;
|
|
@@ -44335,12 +44335,12 @@ var DevServerManager = class {
|
|
|
44335
44335
|
mergedCleanupDir = spawned.mergedLogCleanupDir;
|
|
44336
44336
|
} catch (e) {
|
|
44337
44337
|
const msg = e instanceof Error ? e.message : String(e);
|
|
44338
|
-
this.log(`[
|
|
44339
|
-
this.abortControllersByServerId.delete(
|
|
44340
|
-
this.sendStatus(
|
|
44338
|
+
this.log(`[preview-environment] Failed to start ${title}: ${msg}`);
|
|
44339
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
44340
|
+
this.sendStatus(environmentId, "error", msg, emptyTails());
|
|
44341
44341
|
return;
|
|
44342
44342
|
}
|
|
44343
|
-
if ((this.spawnGenerationByServerId.get(
|
|
44343
|
+
if ((this.spawnGenerationByServerId.get(environmentId) ?? 0) !== scheduledGen) {
|
|
44344
44344
|
try {
|
|
44345
44345
|
proc.removeAllListeners();
|
|
44346
44346
|
proc.kill("SIGTERM");
|
|
@@ -44349,89 +44349,89 @@ var DevServerManager = class {
|
|
|
44349
44349
|
return;
|
|
44350
44350
|
}
|
|
44351
44351
|
if (!pipedStdoutStderr) {
|
|
44352
|
-
this.log(`[
|
|
44352
|
+
this.log(`[preview-environment] ${title} running (inherited stdio; bridge log preview disabled)`);
|
|
44353
44353
|
} else if (mergedLogPath && mergedCleanupDir) {
|
|
44354
44354
|
this.log(
|
|
44355
|
-
`[
|
|
44355
|
+
`[preview-environment] ${title} running (logs captured via temp file; open the browser log viewer for live output)`
|
|
44356
44356
|
);
|
|
44357
44357
|
}
|
|
44358
|
-
this.pipedCaptureByServerId.set(
|
|
44358
|
+
this.pipedCaptureByServerId.set(environmentId, pipedStdoutStderr);
|
|
44359
44359
|
const stdoutTail = new StreamTail();
|
|
44360
44360
|
const stderrTail = new StreamTail();
|
|
44361
|
-
this.streamTailsByServerId.set(
|
|
44361
|
+
this.streamTailsByServerId.set(environmentId, { stdout: stdoutTail, stderr: stderrTail });
|
|
44362
44362
|
if (mergedLogPath && mergedCleanupDir) {
|
|
44363
|
-
this.mergedLogCleanupDirByServerId.set(
|
|
44363
|
+
this.mergedLogCleanupDirByServerId.set(environmentId, mergedCleanupDir);
|
|
44364
44364
|
}
|
|
44365
44365
|
const mergedReadPos = { value: 0 };
|
|
44366
|
-
this.processes.set(
|
|
44367
|
-
|
|
44368
|
-
|
|
44366
|
+
this.processes.set(environmentId, proc);
|
|
44367
|
+
wirePreviewEnvironmentChildProcess({
|
|
44368
|
+
environmentId,
|
|
44369
44369
|
title,
|
|
44370
44370
|
proc,
|
|
44371
44371
|
mergedLogPath,
|
|
44372
44372
|
mergedCleanupDir,
|
|
44373
44373
|
mergedReadPos,
|
|
44374
44374
|
scheduledGen,
|
|
44375
|
-
getSpawnGeneration: () => this.spawnGenerationByServerId.get(
|
|
44375
|
+
getSpawnGeneration: () => this.spawnGenerationByServerId.get(environmentId) ?? 0,
|
|
44376
44376
|
log: this.log,
|
|
44377
44377
|
stdoutTail,
|
|
44378
44378
|
stderrTail,
|
|
44379
44379
|
pushRemoteLogChunk: (sid, stream, chunk) => this.firehoseSink.pushLogChunk(sid, stream, chunk),
|
|
44380
|
-
sendStatus: (status, detail, tails) => this.sendStatus(
|
|
44380
|
+
sendStatus: (status, detail, tails) => this.sendStatus(environmentId, status, detail, tails),
|
|
44381
44381
|
setPollInterval: (iv) => {
|
|
44382
|
-
if (iv) this.mergedLogPollByServerId.set(
|
|
44383
|
-
else this.mergedLogPollByServerId.delete(
|
|
44382
|
+
if (iv) this.mergedLogPollByServerId.set(environmentId, iv);
|
|
44383
|
+
else this.mergedLogPollByServerId.delete(environmentId);
|
|
44384
44384
|
},
|
|
44385
|
-
getPollInterval: () => this.mergedLogPollByServerId.get(
|
|
44385
|
+
getPollInterval: () => this.mergedLogPollByServerId.get(environmentId),
|
|
44386
44386
|
detachProcessFromManager: () => {
|
|
44387
|
-
this.processes.delete(
|
|
44388
|
-
this.pipedCaptureByServerId.delete(
|
|
44389
|
-
this.abortControllersByServerId.delete(
|
|
44390
|
-
this.mergedLogCleanupDirByServerId.delete(
|
|
44387
|
+
this.processes.delete(environmentId);
|
|
44388
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
44389
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
44390
|
+
this.mergedLogCleanupDirByServerId.delete(environmentId);
|
|
44391
44391
|
},
|
|
44392
44392
|
rmMergedCleanupDir: (dir) => {
|
|
44393
44393
|
void rm2(dir, { recursive: true, force: true }).catch(() => {
|
|
44394
44394
|
});
|
|
44395
44395
|
},
|
|
44396
|
-
clearTailBuffers: () => this.clearTails(
|
|
44396
|
+
clearTailBuffers: () => this.clearTails(environmentId)
|
|
44397
44397
|
});
|
|
44398
|
-
this.sendStatus(
|
|
44398
|
+
this.sendStatus(environmentId, "running", `pid=${proc.pid ?? "?"}`, {
|
|
44399
44399
|
stdout: stdoutTail.getTail(),
|
|
44400
44400
|
stderr: stderrTail.getTail()
|
|
44401
44401
|
});
|
|
44402
44402
|
});
|
|
44403
44403
|
}
|
|
44404
|
-
handleControl(
|
|
44404
|
+
handleControl(environmentId, action) {
|
|
44405
44405
|
if (action === "stop") {
|
|
44406
|
-
this.stop(
|
|
44406
|
+
this.stop(environmentId);
|
|
44407
44407
|
return;
|
|
44408
44408
|
}
|
|
44409
|
-
this.start(
|
|
44409
|
+
this.start(environmentId);
|
|
44410
44410
|
}
|
|
44411
44411
|
async shutdownAllGraceful(opts) {
|
|
44412
44412
|
const graceMs = opts?.graceMs ?? BRIDGE_SHUTDOWN_GRACE_MS;
|
|
44413
44413
|
const pairs = [...this.processes.entries()];
|
|
44414
44414
|
if (pairs.length === 0) return;
|
|
44415
44415
|
this.log(
|
|
44416
|
-
`[
|
|
44416
|
+
`[preview-environment] Stopping ${pairs.length} local preview environment process${pairs.length === 1 ? "" : "es"}\u2026`
|
|
44417
44417
|
);
|
|
44418
|
-
await Promise.all(pairs.map(([
|
|
44418
|
+
await Promise.all(pairs.map(([environmentId, proc]) => this.gracefulTerminateOrUnknown(environmentId, proc, graceMs)));
|
|
44419
44419
|
}
|
|
44420
|
-
async gracefulTerminateOrUnknown(
|
|
44421
|
-
const shortId = `${
|
|
44420
|
+
async gracefulTerminateOrUnknown(environmentId, proc, graceMs) {
|
|
44421
|
+
const shortId = `${environmentId.slice(0, 8)}\u2026`;
|
|
44422
44422
|
await sigtermAndWaitForExit(proc, graceMs, this.log, shortId);
|
|
44423
|
-
if (!this.processes.has(
|
|
44423
|
+
if (!this.processes.has(environmentId) || this.processes.get(environmentId) !== proc) {
|
|
44424
44424
|
return;
|
|
44425
44425
|
}
|
|
44426
|
-
this.bumpGeneration(
|
|
44426
|
+
this.bumpGeneration(environmentId);
|
|
44427
44427
|
forceKillChild(proc, this.log, shortId, graceMs);
|
|
44428
|
-
this.processes.delete(
|
|
44429
|
-
this.clearPoll(
|
|
44430
|
-
this.pipedCaptureByServerId.delete(
|
|
44431
|
-
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId,
|
|
44432
|
-
const tails = this.snapshotTails(
|
|
44433
|
-
this.clearTails(
|
|
44434
|
-
this.sendStatus(
|
|
44428
|
+
this.processes.delete(environmentId);
|
|
44429
|
+
this.clearPoll(environmentId);
|
|
44430
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
44431
|
+
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId, environmentId);
|
|
44432
|
+
const tails = this.snapshotTails(environmentId);
|
|
44433
|
+
this.clearTails(environmentId);
|
|
44434
|
+
this.sendStatus(environmentId, "unknown", "Bridge closed before process exited", tails);
|
|
44435
44435
|
}
|
|
44436
44436
|
};
|
|
44437
44437
|
|
|
@@ -44657,20 +44657,20 @@ function createFirehoseMessageRouter() {
|
|
|
44657
44657
|
};
|
|
44658
44658
|
}
|
|
44659
44659
|
|
|
44660
|
-
// src/firehose/routing/handlers/
|
|
44661
|
-
var
|
|
44662
|
-
const
|
|
44660
|
+
// src/firehose/routing/handlers/preview-environment-logs-viewer-open.ts
|
|
44661
|
+
var handlePreviewEnvironmentLogsViewerOpen = (msg, deps) => {
|
|
44662
|
+
const environmentId = typeof msg.environmentId === "string" ? msg.environmentId : "";
|
|
44663
44663
|
const viewerId = typeof msg.viewerId === "string" ? msg.viewerId : "";
|
|
44664
|
-
if (!
|
|
44665
|
-
deps.
|
|
44664
|
+
if (!environmentId || !viewerId) return;
|
|
44665
|
+
deps.previewEnvironmentManager.handleFirehoseLogViewerOpen(environmentId, viewerId);
|
|
44666
44666
|
};
|
|
44667
44667
|
|
|
44668
|
-
// src/firehose/routing/handlers/
|
|
44669
|
-
var
|
|
44670
|
-
const
|
|
44668
|
+
// src/firehose/routing/handlers/preview-environment-logs-viewer-close.ts
|
|
44669
|
+
var handlePreviewEnvironmentLogsViewerClose = (msg, deps) => {
|
|
44670
|
+
const environmentId = typeof msg.environmentId === "string" ? msg.environmentId : "";
|
|
44671
44671
|
const viewerId = typeof msg.viewerId === "string" ? msg.viewerId : "";
|
|
44672
|
-
if (!
|
|
44673
|
-
deps.
|
|
44672
|
+
if (!environmentId || !viewerId) return;
|
|
44673
|
+
deps.previewEnvironmentManager.handleFirehoseLogViewerClose(environmentId, viewerId);
|
|
44674
44674
|
};
|
|
44675
44675
|
|
|
44676
44676
|
// src/firehose/routing/handlers/proxy-message.ts
|
|
@@ -44719,8 +44719,8 @@ var handleFirehoseIdentified = (_msg, _deps) => {
|
|
|
44719
44719
|
// src/firehose/routing/dispatch-firehose-message.ts
|
|
44720
44720
|
var router = createFirehoseMessageRouter();
|
|
44721
44721
|
router.register("identified", handleFirehoseIdentified);
|
|
44722
|
-
router.register("log_viewer_open",
|
|
44723
|
-
router.register("log_viewer_close",
|
|
44722
|
+
router.register("log_viewer_open", handlePreviewEnvironmentLogsViewerOpen);
|
|
44723
|
+
router.register("log_viewer_close", handlePreviewEnvironmentLogsViewerClose);
|
|
44724
44724
|
router.register("proxy", handleProxyMessage);
|
|
44725
44725
|
function dispatchFirehoseJsonMessage(msg, deps) {
|
|
44726
44726
|
router.dispatch(msg, deps);
|
|
@@ -44750,7 +44750,7 @@ function connectFirehose(options) {
|
|
|
44750
44750
|
bridgeName,
|
|
44751
44751
|
proxyPorts,
|
|
44752
44752
|
log: log2,
|
|
44753
|
-
|
|
44753
|
+
previewEnvironmentManager,
|
|
44754
44754
|
onOpen,
|
|
44755
44755
|
onClose,
|
|
44756
44756
|
suppressWebSocketErrors
|
|
@@ -44770,7 +44770,7 @@ function connectFirehose(options) {
|
|
|
44770
44770
|
const deps = {
|
|
44771
44771
|
ws,
|
|
44772
44772
|
log: log2,
|
|
44773
|
-
|
|
44773
|
+
previewEnvironmentManager,
|
|
44774
44774
|
pendingProxyBody,
|
|
44775
44775
|
startStreamingProxy: (pr) => startStreamingProxy(ws, log2, pr)
|
|
44776
44776
|
};
|
|
@@ -44778,7 +44778,7 @@ function connectFirehose(options) {
|
|
|
44778
44778
|
disposeClientPing();
|
|
44779
44779
|
clearClientPing = attachWebSocketClientPing(ws, CLI_WEBSOCKET_CLIENT_PING_MS);
|
|
44780
44780
|
onOpen?.();
|
|
44781
|
-
|
|
44781
|
+
previewEnvironmentManager.attachFirehose(firehoseSend);
|
|
44782
44782
|
sendWsMessage(ws, { type: "identify", workspaceId, bridgeName, proxyPorts });
|
|
44783
44783
|
});
|
|
44784
44784
|
ws.on("message", (raw) => {
|
|
@@ -44795,7 +44795,7 @@ function connectFirehose(options) {
|
|
|
44795
44795
|
});
|
|
44796
44796
|
ws.on("close", (code, reason) => {
|
|
44797
44797
|
disposeClientPing();
|
|
44798
|
-
|
|
44798
|
+
previewEnvironmentManager.detachFirehose();
|
|
44799
44799
|
const reasonStr = typeof reason === "string" ? reason : reason.toString();
|
|
44800
44800
|
onClose?.(code, reasonStr);
|
|
44801
44801
|
});
|
|
@@ -44811,7 +44811,7 @@ function connectFirehose(options) {
|
|
|
44811
44811
|
return {
|
|
44812
44812
|
close() {
|
|
44813
44813
|
disposeClientPing();
|
|
44814
|
-
|
|
44814
|
+
previewEnvironmentManager.detachFirehose();
|
|
44815
44815
|
safeCloseWebSocket(ws);
|
|
44816
44816
|
},
|
|
44817
44817
|
isConnected: () => ws.readyState === wrapper_default.OPEN
|
|
@@ -44820,7 +44820,7 @@ function connectFirehose(options) {
|
|
|
44820
44820
|
|
|
44821
44821
|
// src/connection/attach-firehose-after-identified.ts
|
|
44822
44822
|
function attachFirehoseAfterIdentified(ctx, params) {
|
|
44823
|
-
const { state,
|
|
44823
|
+
const { state, previewEnvironmentManager, logFn } = ctx;
|
|
44824
44824
|
function clearFirehoseReconnectTimer() {
|
|
44825
44825
|
if (state.firehoseReconnectTimeout != null) {
|
|
44826
44826
|
clearTimeout(state.firehoseReconnectTimeout);
|
|
@@ -44886,7 +44886,7 @@ function attachFirehoseAfterIdentified(ctx, params) {
|
|
|
44886
44886
|
bridgeName: params.bridgeName,
|
|
44887
44887
|
proxyPorts: params.proxyPorts,
|
|
44888
44888
|
log: logFn,
|
|
44889
|
-
|
|
44889
|
+
previewEnvironmentManager,
|
|
44890
44890
|
suppressWebSocketErrors: () => !state.closedByUser && state.firehoseOutage.startedAt != null,
|
|
44891
44891
|
onOpen: () => {
|
|
44892
44892
|
if (myGen !== state.firehoseGeneration) return;
|
|
@@ -44929,14 +44929,14 @@ function attachFirehoseAfterIdentified(ctx, params) {
|
|
|
44929
44929
|
|
|
44930
44930
|
// src/connection/create-bridge-identified-handler.ts
|
|
44931
44931
|
function createOnBridgeIdentified(opts) {
|
|
44932
|
-
const {
|
|
44933
|
-
const firehoseCtx = { state,
|
|
44932
|
+
const { previewEnvironmentManager, firehoseServerUrl, workspaceId, state, logFn } = opts;
|
|
44933
|
+
const firehoseCtx = { state, previewEnvironmentManager, logFn };
|
|
44934
44934
|
return (msg) => {
|
|
44935
44935
|
const bridgeName = msg.bridgeName;
|
|
44936
44936
|
const proxyPorts = Array.isArray(msg.proxyPorts) ? msg.proxyPorts : [];
|
|
44937
|
-
const
|
|
44937
|
+
const previewEnvironments = msg.previewEnvironments ?? [];
|
|
44938
44938
|
setImmediate(() => {
|
|
44939
|
-
|
|
44939
|
+
previewEnvironmentManager.applyConfig(previewEnvironments);
|
|
44940
44940
|
if (!firehoseServerUrl || typeof bridgeName !== "string" || !bridgeName) return;
|
|
44941
44941
|
state.firehoseReconnectAttempt = 0;
|
|
44942
44942
|
attachFirehoseAfterIdentified(firehoseCtx, {
|
|
@@ -45112,8 +45112,8 @@ var API_TO_BRIDGE_MESSAGE_TYPES = [
|
|
|
45112
45112
|
"auth_token",
|
|
45113
45113
|
"bridge_identified",
|
|
45114
45114
|
"ha",
|
|
45115
|
-
"
|
|
45116
|
-
"
|
|
45115
|
+
"preview_environments_config",
|
|
45116
|
+
"preview_environment_control",
|
|
45117
45117
|
"agent_config",
|
|
45118
45118
|
"prompt_queue_state",
|
|
45119
45119
|
"prompt",
|
|
@@ -45173,7 +45173,7 @@ var handleBridgeIdentified = (msg, deps) => {
|
|
|
45173
45173
|
deps.onBridgeIdentified({
|
|
45174
45174
|
bridgeName: msg.bridgeName,
|
|
45175
45175
|
proxyPorts: msg.proxyPorts,
|
|
45176
|
-
|
|
45176
|
+
previewEnvironments: msg.previewEnvironments
|
|
45177
45177
|
});
|
|
45178
45178
|
setImmediate(() => {
|
|
45179
45179
|
void (async () => {
|
|
@@ -47610,26 +47610,26 @@ var handleRevertTurnSnapshotMessage = (msg, deps) => {
|
|
|
47610
47610
|
})();
|
|
47611
47611
|
};
|
|
47612
47612
|
|
|
47613
|
-
// src/routing/handlers/
|
|
47614
|
-
var
|
|
47613
|
+
// src/routing/handlers/preview-environment-control.ts
|
|
47614
|
+
var handlePreviewEnvironmentControl = (msg, deps) => {
|
|
47615
47615
|
let wire;
|
|
47616
47616
|
try {
|
|
47617
47617
|
wire = deps.e2ee ? deps.e2ee.decryptMessage(msg) : msg;
|
|
47618
47618
|
} catch (e) {
|
|
47619
|
-
deps.log(`[E2EE] Could not decrypt
|
|
47619
|
+
deps.log(`[E2EE] Could not decrypt preview environment command: ${e instanceof Error ? e.message : String(e)}`);
|
|
47620
47620
|
return;
|
|
47621
47621
|
}
|
|
47622
|
-
const
|
|
47622
|
+
const environmentId = typeof wire.environmentId === "string" ? wire.environmentId : "";
|
|
47623
47623
|
const action = wire.action === "start" || wire.action === "stop" ? wire.action : null;
|
|
47624
|
-
if (!
|
|
47625
|
-
deps.
|
|
47624
|
+
if (!environmentId || !action) return;
|
|
47625
|
+
deps.previewEnvironmentManager?.handleControl(environmentId, action);
|
|
47626
47626
|
};
|
|
47627
47627
|
|
|
47628
|
-
// src/routing/handlers/
|
|
47629
|
-
var
|
|
47630
|
-
const
|
|
47628
|
+
// src/routing/handlers/preview-environments-config.ts
|
|
47629
|
+
var handlePreviewEnvironmentsConfig = (msg, deps) => {
|
|
47630
|
+
const previewEnvironments = msg.previewEnvironments;
|
|
47631
47631
|
setImmediate(() => {
|
|
47632
|
-
deps.
|
|
47632
|
+
deps.previewEnvironmentManager?.applyConfig(previewEnvironments ?? []);
|
|
47633
47633
|
});
|
|
47634
47634
|
};
|
|
47635
47635
|
|
|
@@ -47789,11 +47789,11 @@ function dispatchBridgeMessage(msg, deps) {
|
|
|
47789
47789
|
case "ha":
|
|
47790
47790
|
handleBridgeHeartbeatAck(msg, deps);
|
|
47791
47791
|
break;
|
|
47792
|
-
case "
|
|
47793
|
-
|
|
47792
|
+
case "preview_environments_config":
|
|
47793
|
+
handlePreviewEnvironmentsConfig(msg, deps);
|
|
47794
47794
|
break;
|
|
47795
|
-
case "
|
|
47796
|
-
|
|
47795
|
+
case "preview_environment_control":
|
|
47796
|
+
handlePreviewEnvironmentControl(msg, deps);
|
|
47797
47797
|
break;
|
|
47798
47798
|
case "agent_config":
|
|
47799
47799
|
handleAgentConfigMessage(msg, deps);
|
|
@@ -48901,7 +48901,7 @@ function createBridgeMessageDeps(params) {
|
|
|
48901
48901
|
sendLocalSkillsReport,
|
|
48902
48902
|
reportAutoDetectedAgents,
|
|
48903
48903
|
warmupAgentCapabilitiesOnConnect: warmupAgentCapabilitiesOnConnect2,
|
|
48904
|
-
|
|
48904
|
+
previewEnvironmentManager,
|
|
48905
48905
|
e2ee,
|
|
48906
48906
|
cloudApiBaseUrl,
|
|
48907
48907
|
getCloudAccessToken
|
|
@@ -48918,7 +48918,7 @@ function createBridgeMessageDeps(params) {
|
|
|
48918
48918
|
sendLocalSkillsReport,
|
|
48919
48919
|
reportAutoDetectedAgents,
|
|
48920
48920
|
warmupAgentCapabilitiesOnConnect: warmupAgentCapabilitiesOnConnect2,
|
|
48921
|
-
|
|
48921
|
+
previewEnvironmentManager,
|
|
48922
48922
|
e2ee,
|
|
48923
48923
|
cloudApiBaseUrl,
|
|
48924
48924
|
getCloudAccessToken
|
|
@@ -48988,10 +48988,10 @@ async function createBridgeConnection(options) {
|
|
|
48988
48988
|
initialIndexBuildsScheduled = true;
|
|
48989
48989
|
scheduleInitialIndexBuilds(getBridgeRoot());
|
|
48990
48990
|
};
|
|
48991
|
-
const
|
|
48991
|
+
const previewEnvironmentManager = new PreviewEnvironmentManager({ getWs, log: logFn, getBridgeRoot, e2ee });
|
|
48992
48992
|
const bridgeHeartbeat = createBridgeHeartbeatController({ getWs, log: logFn });
|
|
48993
48993
|
const baseOnBridgeIdentified = createOnBridgeIdentified({
|
|
48994
|
-
|
|
48994
|
+
previewEnvironmentManager,
|
|
48995
48995
|
firehoseServerUrl,
|
|
48996
48996
|
workspaceId,
|
|
48997
48997
|
state,
|
|
@@ -49017,7 +49017,7 @@ async function createBridgeConnection(options) {
|
|
|
49017
49017
|
log: logFn,
|
|
49018
49018
|
getWs
|
|
49019
49019
|
}),
|
|
49020
|
-
|
|
49020
|
+
previewEnvironmentManager,
|
|
49021
49021
|
e2ee,
|
|
49022
49022
|
cloudApiBaseUrl: apiUrl,
|
|
49023
49023
|
getCloudAccessToken: () => tokens.accessToken
|
|
@@ -49050,7 +49050,7 @@ async function createBridgeConnection(options) {
|
|
|
49050
49050
|
requestCliImmediateShutdown();
|
|
49051
49051
|
stopFileIndexWatcher();
|
|
49052
49052
|
bridgeHeartbeat.stop();
|
|
49053
|
-
await closeBridgeConnection(state, acpManager,
|
|
49053
|
+
await closeBridgeConnection(state, acpManager, previewEnvironmentManager, logFn);
|
|
49054
49054
|
await bridgeAccess.close();
|
|
49055
49055
|
}
|
|
49056
49056
|
};
|