@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/index.js
CHANGED
|
@@ -25272,7 +25272,7 @@ function installBridgeProcessResilience() {
|
|
|
25272
25272
|
}
|
|
25273
25273
|
|
|
25274
25274
|
// src/cli-version.ts
|
|
25275
|
-
var CLI_VERSION = "0.1.
|
|
25275
|
+
var CLI_VERSION = "0.1.60".length > 0 ? "0.1.60" : "0.0.0-dev";
|
|
25276
25276
|
|
|
25277
25277
|
// src/connection/heartbeat/constants.ts
|
|
25278
25278
|
var BRIDGE_APP_HEARTBEAT_INTERVAL_MS = 1e4;
|
|
@@ -26387,8 +26387,8 @@ function runPendingAuth(options) {
|
|
|
26387
26387
|
};
|
|
26388
26388
|
}
|
|
26389
26389
|
|
|
26390
|
-
// src/
|
|
26391
|
-
var
|
|
26390
|
+
// src/preview-environments/manager/preview-environment-constants.ts
|
|
26391
|
+
var BRIDGE_CLOSE_PREVIEW_ENVIRONMENT_GRACE_MS = 0;
|
|
26392
26392
|
var BRIDGE_SHUTDOWN_GRACE_MS = 8e3;
|
|
26393
26393
|
|
|
26394
26394
|
// src/runtime/cli-process-interrupt.ts
|
|
@@ -27095,7 +27095,7 @@ async function ensureCodeNavCacheSqliteInitialized() {
|
|
|
27095
27095
|
}
|
|
27096
27096
|
|
|
27097
27097
|
// src/connection/close-bridge-connection.ts
|
|
27098
|
-
async function closeBridgeConnection(state, acpManager,
|
|
27098
|
+
async function closeBridgeConnection(state, acpManager, previewEnvironmentManager, log2) {
|
|
27099
27099
|
requestCliImmediateShutdown();
|
|
27100
27100
|
const say = log2 ?? logImmediate;
|
|
27101
27101
|
say("Cleaning up connections\u2026");
|
|
@@ -27133,9 +27133,9 @@ async function closeBridgeConnection(state, acpManager, devServerManager, log2)
|
|
|
27133
27133
|
}
|
|
27134
27134
|
state.currentWs = null;
|
|
27135
27135
|
}
|
|
27136
|
-
if (
|
|
27137
|
-
say("Stopping local
|
|
27138
|
-
await
|
|
27136
|
+
if (previewEnvironmentManager) {
|
|
27137
|
+
say("Stopping local preview environment processes\u2026");
|
|
27138
|
+
await previewEnvironmentManager.shutdownAllGraceful({ graceMs: BRIDGE_CLOSE_PREVIEW_ENVIRONMENT_GRACE_MS });
|
|
27139
27139
|
}
|
|
27140
27140
|
try {
|
|
27141
27141
|
closeAllCliSqliteConnections();
|
|
@@ -40653,12 +40653,12 @@ function startFileIndexWatcher(cwd = getBridgeRoot()) {
|
|
|
40653
40653
|
// src/connection/create-bridge-connection.ts
|
|
40654
40654
|
import * as path73 from "node:path";
|
|
40655
40655
|
|
|
40656
|
-
// src/
|
|
40656
|
+
// src/preview-environments/manager/preview-environment-manager.ts
|
|
40657
40657
|
import { rm as rm2 } from "node:fs/promises";
|
|
40658
40658
|
|
|
40659
|
-
// src/
|
|
40660
|
-
function
|
|
40661
|
-
const payload = { type: "
|
|
40659
|
+
// src/preview-environments/process/send-preview-environment-status.ts
|
|
40660
|
+
function sendPreviewEnvironmentStatus(getWs, environmentId, status, options) {
|
|
40661
|
+
const payload = { type: "preview_environment_status", environmentId, status };
|
|
40662
40662
|
if (options?.detail) payload.detail = options.detail;
|
|
40663
40663
|
if (options?.tails) {
|
|
40664
40664
|
payload.stdoutTail = options.tails.stdout;
|
|
@@ -40671,12 +40671,12 @@ function sendDevServerStatus(getWs, serverId, status, options) {
|
|
|
40671
40671
|
});
|
|
40672
40672
|
}
|
|
40673
40673
|
|
|
40674
|
-
// src/
|
|
40674
|
+
// src/preview-environments/process/terminate-child-process.ts
|
|
40675
40675
|
async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
|
|
40676
40676
|
const exited = new Promise((resolve32) => {
|
|
40677
40677
|
proc.once("exit", () => resolve32());
|
|
40678
40678
|
});
|
|
40679
|
-
log2(`[
|
|
40679
|
+
log2(`[preview-environment] Sending SIGTERM to ${shortId} (pid=${proc.pid ?? "?"}).`);
|
|
40680
40680
|
try {
|
|
40681
40681
|
proc.kill("SIGTERM");
|
|
40682
40682
|
} catch {
|
|
@@ -40685,7 +40685,7 @@ async function sigtermAndWaitForExit(proc, graceMs, log2, shortId) {
|
|
|
40685
40685
|
}
|
|
40686
40686
|
function forceKillChild(proc, log2, shortId, graceMs) {
|
|
40687
40687
|
log2(
|
|
40688
|
-
`[
|
|
40688
|
+
`[preview-environment] ${shortId} did not exit within ${graceMs}ms; sending SIGKILL (pid=${proc.pid ?? "?"}).`
|
|
40689
40689
|
);
|
|
40690
40690
|
proc.removeAllListeners();
|
|
40691
40691
|
try {
|
|
@@ -40694,10 +40694,10 @@ function forceKillChild(proc, log2, shortId, graceMs) {
|
|
|
40694
40694
|
}
|
|
40695
40695
|
}
|
|
40696
40696
|
|
|
40697
|
-
// src/
|
|
40697
|
+
// src/preview-environments/process/wire-preview-environment-child-process.ts
|
|
40698
40698
|
import fs36 from "node:fs";
|
|
40699
40699
|
|
|
40700
|
-
// src/
|
|
40700
|
+
// src/preview-environments/manager/forward-pipe.ts
|
|
40701
40701
|
function forwardChildPipe(childReadable, terminal, onData) {
|
|
40702
40702
|
if (!childReadable) return;
|
|
40703
40703
|
childReadable.on("data", (chunk) => {
|
|
@@ -40713,16 +40713,16 @@ function forwardChildPipe(childReadable, terminal, onData) {
|
|
|
40713
40713
|
});
|
|
40714
40714
|
}
|
|
40715
40715
|
|
|
40716
|
-
// src/
|
|
40717
|
-
function
|
|
40718
|
-
const { proc,
|
|
40716
|
+
// src/preview-environments/process/wire-preview-environment-child-process.ts
|
|
40717
|
+
function wirePreviewEnvironmentChildProcess(d) {
|
|
40718
|
+
const { proc, environmentId, title } = d;
|
|
40719
40719
|
forwardChildPipe(proc.stdout, null, (chunk) => {
|
|
40720
40720
|
d.stdoutTail.push(chunk);
|
|
40721
|
-
d.pushRemoteLogChunk(
|
|
40721
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
40722
40722
|
});
|
|
40723
40723
|
forwardChildPipe(proc.stderr, null, (chunk) => {
|
|
40724
40724
|
d.stderrTail.push(chunk);
|
|
40725
|
-
d.pushRemoteLogChunk(
|
|
40725
|
+
d.pushRemoteLogChunk(environmentId, "stderr", chunk);
|
|
40726
40726
|
});
|
|
40727
40727
|
if (d.mergedLogPath && d.mergedCleanupDir) {
|
|
40728
40728
|
const pollIv = setInterval(() => {
|
|
@@ -40738,7 +40738,7 @@ function wireDevServerChildProcess(d) {
|
|
|
40738
40738
|
d.mergedReadPos.value = buf.length;
|
|
40739
40739
|
if (chunk.length === 0) return;
|
|
40740
40740
|
d.stdoutTail.push(chunk);
|
|
40741
|
-
d.pushRemoteLogChunk(
|
|
40741
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
40742
40742
|
});
|
|
40743
40743
|
}, 100);
|
|
40744
40744
|
d.setPollInterval(pollIv);
|
|
@@ -40756,10 +40756,10 @@ function wireDevServerChildProcess(d) {
|
|
|
40756
40756
|
d.rmMergedCleanupDir(cleanupDir);
|
|
40757
40757
|
}
|
|
40758
40758
|
if (signal) {
|
|
40759
|
-
d.log(`[
|
|
40759
|
+
d.log(`[preview-environment] ${title} stopped (signal: ${String(signal)}).`);
|
|
40760
40760
|
} else if (code !== null && code !== 0) {
|
|
40761
40761
|
const errTail = d.stderrTail.getTail().slice(-3).join("\n");
|
|
40762
|
-
d.log(`[
|
|
40762
|
+
d.log(`[preview-environment] ${title} exited with code ${code}${errTail ? `
|
|
40763
40763
|
${errTail}` : ""}`);
|
|
40764
40764
|
}
|
|
40765
40765
|
d.detachProcessFromManager();
|
|
@@ -40774,7 +40774,7 @@ ${errTail}` : ""}`);
|
|
|
40774
40774
|
const chunk = Buffer.from(buf.subarray(d.mergedReadPos.value));
|
|
40775
40775
|
if (chunk.length > 0) {
|
|
40776
40776
|
d.stdoutTail.push(chunk);
|
|
40777
|
-
d.pushRemoteLogChunk(
|
|
40777
|
+
d.pushRemoteLogChunk(environmentId, "stdout", chunk);
|
|
40778
40778
|
}
|
|
40779
40779
|
}
|
|
40780
40780
|
finishExit();
|
|
@@ -40798,12 +40798,12 @@ ${errTail}` : ""}`);
|
|
|
40798
40798
|
d.clearTailBuffers();
|
|
40799
40799
|
const msg = err instanceof Error ? err.message : String(err);
|
|
40800
40800
|
const errno = typeof err === "object" && err && "code" in err ? String(err.code) : "";
|
|
40801
|
-
d.log(`[
|
|
40801
|
+
d.log(`[preview-environment] ${title} process error: ${msg}${errno ? ` (${errno})` : ""}`);
|
|
40802
40802
|
d.sendStatus("error", msg, tails);
|
|
40803
40803
|
});
|
|
40804
40804
|
}
|
|
40805
40805
|
|
|
40806
|
-
// src/
|
|
40806
|
+
// src/preview-environments/manager/preview-environment-env.ts
|
|
40807
40807
|
function substituteCommand(cmd, env) {
|
|
40808
40808
|
return cmd.replace(/\$\{([^}]+)\}/g, (_, key) => env[key] != null ? String(env[key]) : "");
|
|
40809
40809
|
}
|
|
@@ -40839,15 +40839,15 @@ function envForSpawn(base, userEnv, ports) {
|
|
|
40839
40839
|
return out;
|
|
40840
40840
|
}
|
|
40841
40841
|
|
|
40842
|
-
// src/
|
|
40843
|
-
function
|
|
40842
|
+
// src/preview-environments/manager/parse-config.ts
|
|
40843
|
+
function parsePreviewEnvironmentDefs(servers) {
|
|
40844
40844
|
const out = [];
|
|
40845
40845
|
if (!Array.isArray(servers)) return out;
|
|
40846
40846
|
for (const s of servers) {
|
|
40847
40847
|
if (!s || typeof s !== "object") continue;
|
|
40848
40848
|
const o = s;
|
|
40849
|
-
const
|
|
40850
|
-
if (!
|
|
40849
|
+
const environmentId = typeof o.environmentId === "string" ? o.environmentId : "";
|
|
40850
|
+
if (!environmentId) continue;
|
|
40851
40851
|
const envRaw = o.env;
|
|
40852
40852
|
const env = Array.isArray(envRaw) ? envRaw.map((e) => {
|
|
40853
40853
|
if (!e || typeof e !== "object") return null;
|
|
@@ -40860,7 +40860,7 @@ function parseDevServerDefs(servers) {
|
|
|
40860
40860
|
const portsRaw = o.ports;
|
|
40861
40861
|
const ports = Array.isArray(portsRaw) ? portsRaw.filter((p) => typeof p === "number" && Number.isInteger(p) && p > 0 && p < 65536) : [];
|
|
40862
40862
|
out.push({
|
|
40863
|
-
|
|
40863
|
+
environmentId,
|
|
40864
40864
|
name: typeof o.name === "string" ? o.name : "",
|
|
40865
40865
|
command: typeof o.command === "string" ? o.command : "",
|
|
40866
40866
|
env,
|
|
@@ -40870,7 +40870,7 @@ function parseDevServerDefs(servers) {
|
|
|
40870
40870
|
return out;
|
|
40871
40871
|
}
|
|
40872
40872
|
|
|
40873
|
-
// src/
|
|
40873
|
+
// src/preview-environments/manager/shell-spawn/utils.ts
|
|
40874
40874
|
import fs37 from "node:fs";
|
|
40875
40875
|
function isSpawnEbadf(e) {
|
|
40876
40876
|
return typeof e === "object" && e !== null && "code" in e && e.code === "EBADF";
|
|
@@ -40893,7 +40893,7 @@ function pipedStdoutStderrFor(attemptStdio) {
|
|
|
40893
40893
|
return attemptStdio !== "inherit" && Array.isArray(attemptStdio) && attemptStdio[1] === "pipe" && attemptStdio[2] === "pipe";
|
|
40894
40894
|
}
|
|
40895
40895
|
|
|
40896
|
-
// src/
|
|
40896
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-piped-via-sh.ts
|
|
40897
40897
|
import { spawn as spawn6 } from "node:child_process";
|
|
40898
40898
|
function trySpawnPipedViaSh(command, env, cwd, signal) {
|
|
40899
40899
|
const attempts = [
|
|
@@ -40936,7 +40936,7 @@ function trySpawnPipedViaSh(command, env, cwd, signal) {
|
|
|
40936
40936
|
return { ok: false, lastErr };
|
|
40937
40937
|
}
|
|
40938
40938
|
|
|
40939
|
-
// src/
|
|
40939
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-shell-true-piped.ts
|
|
40940
40940
|
import { spawn as spawn7 } from "node:child_process";
|
|
40941
40941
|
function trySpawnShellTruePiped(command, env, cwd, devNullFd, signal) {
|
|
40942
40942
|
try {
|
|
@@ -40957,7 +40957,7 @@ function trySpawnShellTruePiped(command, env, cwd, devNullFd, signal) {
|
|
|
40957
40957
|
}
|
|
40958
40958
|
}
|
|
40959
40959
|
|
|
40960
|
-
// src/
|
|
40960
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-merged-log-file.ts
|
|
40961
40961
|
import { spawn as spawn8 } from "node:child_process";
|
|
40962
40962
|
import fs38 from "node:fs";
|
|
40963
40963
|
import { tmpdir } from "node:os";
|
|
@@ -41004,7 +41004,7 @@ function trySpawnMergedLogFile(command, env, cwd, signal) {
|
|
|
41004
41004
|
}
|
|
41005
41005
|
}
|
|
41006
41006
|
|
|
41007
|
-
// src/
|
|
41007
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-shell-script-log-redirect.ts
|
|
41008
41008
|
import { spawn as spawn9 } from "node:child_process";
|
|
41009
41009
|
import fs39 from "node:fs";
|
|
41010
41010
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
@@ -41080,7 +41080,7 @@ ${command} >> ${q(logPath)} 2>&1\r
|
|
|
41080
41080
|
}
|
|
41081
41081
|
}
|
|
41082
41082
|
|
|
41083
|
-
// src/
|
|
41083
|
+
// src/preview-environments/manager/shell-spawn/try-spawn-inherit.ts
|
|
41084
41084
|
import { spawn as spawn10 } from "node:child_process";
|
|
41085
41085
|
function trySpawnInheritStdio(command, env, cwd, signal) {
|
|
41086
41086
|
const opts = {
|
|
@@ -41100,7 +41100,7 @@ function trySpawnInheritStdio(command, env, cwd, signal) {
|
|
|
41100
41100
|
return { proc, pipedStdoutStderr: false };
|
|
41101
41101
|
}
|
|
41102
41102
|
|
|
41103
|
-
// src/
|
|
41103
|
+
// src/preview-environments/manager/shell-spawn/shell-spawn.ts
|
|
41104
41104
|
function shellSpawn(command, env, cwd, options) {
|
|
41105
41105
|
const signal = options?.signal;
|
|
41106
41106
|
const piped = trySpawnPipedViaSh(command, env, cwd, signal);
|
|
@@ -41127,7 +41127,7 @@ function shellSpawn(command, env, cwd, options) {
|
|
|
41127
41127
|
}
|
|
41128
41128
|
}
|
|
41129
41129
|
|
|
41130
|
-
// src/
|
|
41130
|
+
// src/preview-environments/manager/stream-tail.ts
|
|
41131
41131
|
var MAX_TAIL_LINES = 80;
|
|
41132
41132
|
var MAX_LINE_CHARS = 8192;
|
|
41133
41133
|
var MAX_PENDING_CHARS = 65536;
|
|
@@ -41163,11 +41163,11 @@ var StreamTail = class {
|
|
|
41163
41163
|
}
|
|
41164
41164
|
};
|
|
41165
41165
|
|
|
41166
|
-
// src/
|
|
41166
|
+
// src/preview-environments/manager/preview-environment-firehose-messages.ts
|
|
41167
41167
|
function buildFirehoseSnapshotMessage(params) {
|
|
41168
41168
|
const payload = {
|
|
41169
41169
|
type: "log_snapshot",
|
|
41170
|
-
|
|
41170
|
+
environmentId: params.environmentId,
|
|
41171
41171
|
viewerId: params.viewerId,
|
|
41172
41172
|
stdoutTail: params.tails.stdout,
|
|
41173
41173
|
stderrTail: params.tails.stderr
|
|
@@ -41177,15 +41177,15 @@ function buildFirehoseSnapshotMessage(params) {
|
|
|
41177
41177
|
function buildFirehoseLogChunkMessage(params) {
|
|
41178
41178
|
const payload = {
|
|
41179
41179
|
type: "log_chunk",
|
|
41180
|
-
|
|
41180
|
+
environmentId: params.environmentId,
|
|
41181
41181
|
stream: params.stream,
|
|
41182
41182
|
text: params.text
|
|
41183
41183
|
};
|
|
41184
41184
|
return params.e2ee ? params.e2ee.encryptFields(payload, ["text"]) : payload;
|
|
41185
41185
|
}
|
|
41186
41186
|
|
|
41187
|
-
// src/
|
|
41188
|
-
var
|
|
41187
|
+
// src/preview-environments/manager/preview-environment-firehose-sink.ts
|
|
41188
|
+
var PreviewEnvironmentFirehoseSink = class {
|
|
41189
41189
|
constructor(options) {
|
|
41190
41190
|
this.options = options;
|
|
41191
41191
|
}
|
|
@@ -41198,31 +41198,31 @@ var DevServerFirehoseSink = class {
|
|
|
41198
41198
|
this.firehoseSend = null;
|
|
41199
41199
|
this.logViewerRefCountByServerId.clear();
|
|
41200
41200
|
}
|
|
41201
|
-
openLogViewer(
|
|
41202
|
-
const next = (this.logViewerRefCountByServerId.get(
|
|
41203
|
-
this.logViewerRefCountByServerId.set(
|
|
41204
|
-
this.sendSnapshot(
|
|
41201
|
+
openLogViewer(environmentId, viewerId) {
|
|
41202
|
+
const next = (this.logViewerRefCountByServerId.get(environmentId) ?? 0) + 1;
|
|
41203
|
+
this.logViewerRefCountByServerId.set(environmentId, next);
|
|
41204
|
+
this.sendSnapshot(environmentId, viewerId);
|
|
41205
41205
|
}
|
|
41206
|
-
closeLogViewer(
|
|
41207
|
-
const n = (this.logViewerRefCountByServerId.get(
|
|
41208
|
-
if (n <= 0) this.logViewerRefCountByServerId.delete(
|
|
41209
|
-
else this.logViewerRefCountByServerId.set(
|
|
41206
|
+
closeLogViewer(environmentId) {
|
|
41207
|
+
const n = (this.logViewerRefCountByServerId.get(environmentId) ?? 0) - 1;
|
|
41208
|
+
if (n <= 0) this.logViewerRefCountByServerId.delete(environmentId);
|
|
41209
|
+
else this.logViewerRefCountByServerId.set(environmentId, n);
|
|
41210
41210
|
}
|
|
41211
|
-
pushLogChunk(
|
|
41212
|
-
if ((this.logViewerRefCountByServerId.get(
|
|
41213
|
-
if (!this.options.isPipedCaptureEnabled(
|
|
41211
|
+
pushLogChunk(environmentId, stream, chunk) {
|
|
41212
|
+
if ((this.logViewerRefCountByServerId.get(environmentId) ?? 0) <= 0) return;
|
|
41213
|
+
if (!this.options.isPipedCaptureEnabled(environmentId)) return;
|
|
41214
41214
|
if (!this.firehoseSend) return;
|
|
41215
41215
|
const text = chunk.toString("utf8");
|
|
41216
41216
|
setImmediate(() => {
|
|
41217
41217
|
if (!this.firehoseSend) return;
|
|
41218
|
-
this.firehoseSend(buildFirehoseLogChunkMessage({
|
|
41218
|
+
this.firehoseSend(buildFirehoseLogChunkMessage({ environmentId, stream, text, e2ee: this.options.e2ee }));
|
|
41219
41219
|
});
|
|
41220
41220
|
}
|
|
41221
|
-
sendSnapshot(
|
|
41221
|
+
sendSnapshot(environmentId, viewerId) {
|
|
41222
41222
|
const payload = buildFirehoseSnapshotMessage({
|
|
41223
|
-
|
|
41223
|
+
environmentId,
|
|
41224
41224
|
viewerId,
|
|
41225
|
-
tails: this.options.getTails(
|
|
41225
|
+
tails: this.options.getTails(environmentId),
|
|
41226
41226
|
e2ee: this.options.e2ee
|
|
41227
41227
|
});
|
|
41228
41228
|
setImmediate(() => {
|
|
@@ -41233,19 +41233,19 @@ var DevServerFirehoseSink = class {
|
|
|
41233
41233
|
}
|
|
41234
41234
|
};
|
|
41235
41235
|
|
|
41236
|
-
// src/
|
|
41236
|
+
// src/preview-environments/manager/cleanup-merged-log-dir.ts
|
|
41237
41237
|
import { rm } from "node:fs/promises";
|
|
41238
|
-
function cleanupMergedLogDirForServer(map2,
|
|
41239
|
-
const mergedDir = map2.get(
|
|
41238
|
+
function cleanupMergedLogDirForServer(map2, environmentId) {
|
|
41239
|
+
const mergedDir = map2.get(environmentId);
|
|
41240
41240
|
if (!mergedDir) return;
|
|
41241
|
-
map2.delete(
|
|
41241
|
+
map2.delete(environmentId);
|
|
41242
41242
|
void rm(mergedDir, { recursive: true, force: true }).catch(() => {
|
|
41243
41243
|
});
|
|
41244
41244
|
}
|
|
41245
41245
|
|
|
41246
|
-
// src/
|
|
41246
|
+
// src/preview-environments/manager/preview-environment-manager.ts
|
|
41247
41247
|
var emptyTails = () => ({ stdout: [], stderr: [] });
|
|
41248
|
-
var
|
|
41248
|
+
var PreviewEnvironmentManager = class {
|
|
41249
41249
|
defsById = /* @__PURE__ */ new Map();
|
|
41250
41250
|
processes = /* @__PURE__ */ new Map();
|
|
41251
41251
|
streamTailsByServerId = /* @__PURE__ */ new Map();
|
|
@@ -41264,9 +41264,9 @@ var DevServerManager = class {
|
|
|
41264
41264
|
this.log = options.log;
|
|
41265
41265
|
this.getBridgeRoot = options.getBridgeRoot ?? (() => process.cwd());
|
|
41266
41266
|
this.e2ee = options.e2ee;
|
|
41267
|
-
this.firehoseSink = new
|
|
41268
|
-
getTails: (
|
|
41269
|
-
isPipedCaptureEnabled: (
|
|
41267
|
+
this.firehoseSink = new PreviewEnvironmentFirehoseSink({
|
|
41268
|
+
getTails: (environmentId) => this.snapshotTails(environmentId),
|
|
41269
|
+
isPipedCaptureEnabled: (environmentId) => this.pipedCaptureByServerId.get(environmentId) === true,
|
|
41270
41270
|
e2ee: this.e2ee
|
|
41271
41271
|
});
|
|
41272
41272
|
}
|
|
@@ -41276,89 +41276,89 @@ var DevServerManager = class {
|
|
|
41276
41276
|
detachFirehose() {
|
|
41277
41277
|
this.firehoseSink.detach();
|
|
41278
41278
|
}
|
|
41279
|
-
handleFirehoseLogViewerOpen(
|
|
41280
|
-
this.firehoseSink.openLogViewer(
|
|
41279
|
+
handleFirehoseLogViewerOpen(environmentId, _viewerId) {
|
|
41280
|
+
this.firehoseSink.openLogViewer(environmentId, _viewerId);
|
|
41281
41281
|
}
|
|
41282
|
-
handleFirehoseLogViewerClose(
|
|
41283
|
-
this.firehoseSink.closeLogViewer(
|
|
41282
|
+
handleFirehoseLogViewerClose(environmentId, _viewerId) {
|
|
41283
|
+
this.firehoseSink.closeLogViewer(environmentId);
|
|
41284
41284
|
}
|
|
41285
41285
|
applyConfig(servers) {
|
|
41286
41286
|
this.defsById.clear();
|
|
41287
|
-
for (const d of
|
|
41288
|
-
this.defsById.set(d.
|
|
41287
|
+
for (const d of parsePreviewEnvironmentDefs(servers)) {
|
|
41288
|
+
this.defsById.set(d.environmentId, d);
|
|
41289
41289
|
}
|
|
41290
41290
|
}
|
|
41291
|
-
snapshotTails(
|
|
41292
|
-
const t = this.streamTailsByServerId.get(
|
|
41291
|
+
snapshotTails(environmentId) {
|
|
41292
|
+
const t = this.streamTailsByServerId.get(environmentId);
|
|
41293
41293
|
if (!t) return { stdout: [], stderr: [] };
|
|
41294
41294
|
return { stdout: t.stdout.getTail(), stderr: t.stderr.getTail() };
|
|
41295
41295
|
}
|
|
41296
|
-
clearTails(
|
|
41297
|
-
this.streamTailsByServerId.delete(
|
|
41296
|
+
clearTails(environmentId) {
|
|
41297
|
+
this.streamTailsByServerId.delete(environmentId);
|
|
41298
41298
|
}
|
|
41299
|
-
sendStatus(
|
|
41300
|
-
|
|
41299
|
+
sendStatus(environmentId, status, detail, tails) {
|
|
41300
|
+
sendPreviewEnvironmentStatus(this.getWs, environmentId, status, { detail, tails });
|
|
41301
41301
|
}
|
|
41302
|
-
bumpGeneration(
|
|
41303
|
-
const nextGen = (this.spawnGenerationByServerId.get(
|
|
41304
|
-
this.spawnGenerationByServerId.set(
|
|
41302
|
+
bumpGeneration(environmentId) {
|
|
41303
|
+
const nextGen = (this.spawnGenerationByServerId.get(environmentId) ?? 0) + 1;
|
|
41304
|
+
this.spawnGenerationByServerId.set(environmentId, nextGen);
|
|
41305
41305
|
}
|
|
41306
|
-
clearPoll(
|
|
41307
|
-
const poll = this.mergedLogPollByServerId.get(
|
|
41306
|
+
clearPoll(environmentId) {
|
|
41307
|
+
const poll = this.mergedLogPollByServerId.get(environmentId);
|
|
41308
41308
|
if (poll) {
|
|
41309
41309
|
clearInterval(poll);
|
|
41310
|
-
this.mergedLogPollByServerId.delete(
|
|
41310
|
+
this.mergedLogPollByServerId.delete(environmentId);
|
|
41311
41311
|
}
|
|
41312
41312
|
}
|
|
41313
|
-
abortSpawn(
|
|
41314
|
-
this.abortControllersByServerId.get(
|
|
41315
|
-
this.abortControllersByServerId.delete(
|
|
41313
|
+
abortSpawn(environmentId) {
|
|
41314
|
+
this.abortControllersByServerId.get(environmentId)?.abort();
|
|
41315
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
41316
41316
|
}
|
|
41317
|
-
stop(
|
|
41318
|
-
const tails = this.snapshotTails(
|
|
41319
|
-
if (this.processes.has(
|
|
41320
|
-
this.sendStatus(
|
|
41317
|
+
stop(environmentId) {
|
|
41318
|
+
const tails = this.snapshotTails(environmentId);
|
|
41319
|
+
if (this.processes.has(environmentId)) {
|
|
41320
|
+
this.sendStatus(environmentId, "stopping", void 0, tails);
|
|
41321
41321
|
}
|
|
41322
|
-
this.bumpGeneration(
|
|
41323
|
-
this.abortSpawn(
|
|
41324
|
-
this.clearPoll(
|
|
41325
|
-
const proc = this.processes.get(
|
|
41322
|
+
this.bumpGeneration(environmentId);
|
|
41323
|
+
this.abortSpawn(environmentId);
|
|
41324
|
+
this.clearPoll(environmentId);
|
|
41325
|
+
const proc = this.processes.get(environmentId);
|
|
41326
41326
|
if (proc) {
|
|
41327
41327
|
proc.removeAllListeners();
|
|
41328
41328
|
try {
|
|
41329
41329
|
proc.kill("SIGTERM");
|
|
41330
41330
|
} catch {
|
|
41331
41331
|
}
|
|
41332
|
-
this.processes.delete(
|
|
41332
|
+
this.processes.delete(environmentId);
|
|
41333
41333
|
}
|
|
41334
|
-
this.clearTails(
|
|
41335
|
-
this.pipedCaptureByServerId.delete(
|
|
41336
|
-
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId,
|
|
41337
|
-
this.sendStatus(
|
|
41334
|
+
this.clearTails(environmentId);
|
|
41335
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
41336
|
+
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId, environmentId);
|
|
41337
|
+
this.sendStatus(environmentId, "stopped", void 0, tails);
|
|
41338
41338
|
}
|
|
41339
|
-
start(
|
|
41340
|
-
const def = this.defsById.get(
|
|
41339
|
+
start(environmentId) {
|
|
41340
|
+
const def = this.defsById.get(environmentId);
|
|
41341
41341
|
if (!def) {
|
|
41342
|
-
this.log(`[
|
|
41343
|
-
this.sendStatus(
|
|
41342
|
+
this.log(`[preview-environment] Unknown server id ${environmentId.slice(0, 8)}\u2026`);
|
|
41343
|
+
this.sendStatus(environmentId, "error", "Unknown server", emptyTails());
|
|
41344
41344
|
return;
|
|
41345
41345
|
}
|
|
41346
41346
|
if (!def.command.trim()) {
|
|
41347
|
-
this.sendStatus(
|
|
41347
|
+
this.sendStatus(environmentId, "idle", "No command configured", emptyTails());
|
|
41348
41348
|
return;
|
|
41349
41349
|
}
|
|
41350
|
-
this.stop(
|
|
41351
|
-
this.sendStatus(
|
|
41350
|
+
this.stop(environmentId);
|
|
41351
|
+
this.sendStatus(environmentId, "starting", void 0, emptyTails());
|
|
41352
41352
|
const ac = new AbortController();
|
|
41353
|
-
this.abortControllersByServerId.set(
|
|
41353
|
+
this.abortControllersByServerId.set(environmentId, ac);
|
|
41354
41354
|
const cwd = this.getBridgeRoot();
|
|
41355
41355
|
const childEnv = envForSpawn(process.env, def.env, def.ports);
|
|
41356
41356
|
const cmd = substituteCommand(def.command.trim(), childEnv);
|
|
41357
|
-
const title = def.name.trim() ||
|
|
41358
|
-
this.log(`[
|
|
41359
|
-
const scheduledGen = this.spawnGenerationByServerId.get(
|
|
41357
|
+
const title = def.name.trim() || environmentId.slice(0, 8);
|
|
41358
|
+
this.log(`[preview-environment] Starting ${title}: ${cmd.slice(0, 120)}${cmd.length > 120 ? "\u2026" : ""}`);
|
|
41359
|
+
const scheduledGen = this.spawnGenerationByServerId.get(environmentId) ?? 0;
|
|
41360
41360
|
setImmediate(() => {
|
|
41361
|
-
if ((this.spawnGenerationByServerId.get(
|
|
41361
|
+
if ((this.spawnGenerationByServerId.get(environmentId) ?? 0) !== scheduledGen) {
|
|
41362
41362
|
return;
|
|
41363
41363
|
}
|
|
41364
41364
|
let proc;
|
|
@@ -41375,12 +41375,12 @@ var DevServerManager = class {
|
|
|
41375
41375
|
mergedCleanupDir = spawned.mergedLogCleanupDir;
|
|
41376
41376
|
} catch (e) {
|
|
41377
41377
|
const msg = e instanceof Error ? e.message : String(e);
|
|
41378
|
-
this.log(`[
|
|
41379
|
-
this.abortControllersByServerId.delete(
|
|
41380
|
-
this.sendStatus(
|
|
41378
|
+
this.log(`[preview-environment] Failed to start ${title}: ${msg}`);
|
|
41379
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
41380
|
+
this.sendStatus(environmentId, "error", msg, emptyTails());
|
|
41381
41381
|
return;
|
|
41382
41382
|
}
|
|
41383
|
-
if ((this.spawnGenerationByServerId.get(
|
|
41383
|
+
if ((this.spawnGenerationByServerId.get(environmentId) ?? 0) !== scheduledGen) {
|
|
41384
41384
|
try {
|
|
41385
41385
|
proc.removeAllListeners();
|
|
41386
41386
|
proc.kill("SIGTERM");
|
|
@@ -41389,89 +41389,89 @@ var DevServerManager = class {
|
|
|
41389
41389
|
return;
|
|
41390
41390
|
}
|
|
41391
41391
|
if (!pipedStdoutStderr) {
|
|
41392
|
-
this.log(`[
|
|
41392
|
+
this.log(`[preview-environment] ${title} running (inherited stdio; bridge log preview disabled)`);
|
|
41393
41393
|
} else if (mergedLogPath && mergedCleanupDir) {
|
|
41394
41394
|
this.log(
|
|
41395
|
-
`[
|
|
41395
|
+
`[preview-environment] ${title} running (logs captured via temp file; open the browser log viewer for live output)`
|
|
41396
41396
|
);
|
|
41397
41397
|
}
|
|
41398
|
-
this.pipedCaptureByServerId.set(
|
|
41398
|
+
this.pipedCaptureByServerId.set(environmentId, pipedStdoutStderr);
|
|
41399
41399
|
const stdoutTail = new StreamTail();
|
|
41400
41400
|
const stderrTail = new StreamTail();
|
|
41401
|
-
this.streamTailsByServerId.set(
|
|
41401
|
+
this.streamTailsByServerId.set(environmentId, { stdout: stdoutTail, stderr: stderrTail });
|
|
41402
41402
|
if (mergedLogPath && mergedCleanupDir) {
|
|
41403
|
-
this.mergedLogCleanupDirByServerId.set(
|
|
41403
|
+
this.mergedLogCleanupDirByServerId.set(environmentId, mergedCleanupDir);
|
|
41404
41404
|
}
|
|
41405
41405
|
const mergedReadPos = { value: 0 };
|
|
41406
|
-
this.processes.set(
|
|
41407
|
-
|
|
41408
|
-
|
|
41406
|
+
this.processes.set(environmentId, proc);
|
|
41407
|
+
wirePreviewEnvironmentChildProcess({
|
|
41408
|
+
environmentId,
|
|
41409
41409
|
title,
|
|
41410
41410
|
proc,
|
|
41411
41411
|
mergedLogPath,
|
|
41412
41412
|
mergedCleanupDir,
|
|
41413
41413
|
mergedReadPos,
|
|
41414
41414
|
scheduledGen,
|
|
41415
|
-
getSpawnGeneration: () => this.spawnGenerationByServerId.get(
|
|
41415
|
+
getSpawnGeneration: () => this.spawnGenerationByServerId.get(environmentId) ?? 0,
|
|
41416
41416
|
log: this.log,
|
|
41417
41417
|
stdoutTail,
|
|
41418
41418
|
stderrTail,
|
|
41419
41419
|
pushRemoteLogChunk: (sid, stream, chunk) => this.firehoseSink.pushLogChunk(sid, stream, chunk),
|
|
41420
|
-
sendStatus: (status, detail, tails) => this.sendStatus(
|
|
41420
|
+
sendStatus: (status, detail, tails) => this.sendStatus(environmentId, status, detail, tails),
|
|
41421
41421
|
setPollInterval: (iv) => {
|
|
41422
|
-
if (iv) this.mergedLogPollByServerId.set(
|
|
41423
|
-
else this.mergedLogPollByServerId.delete(
|
|
41422
|
+
if (iv) this.mergedLogPollByServerId.set(environmentId, iv);
|
|
41423
|
+
else this.mergedLogPollByServerId.delete(environmentId);
|
|
41424
41424
|
},
|
|
41425
|
-
getPollInterval: () => this.mergedLogPollByServerId.get(
|
|
41425
|
+
getPollInterval: () => this.mergedLogPollByServerId.get(environmentId),
|
|
41426
41426
|
detachProcessFromManager: () => {
|
|
41427
|
-
this.processes.delete(
|
|
41428
|
-
this.pipedCaptureByServerId.delete(
|
|
41429
|
-
this.abortControllersByServerId.delete(
|
|
41430
|
-
this.mergedLogCleanupDirByServerId.delete(
|
|
41427
|
+
this.processes.delete(environmentId);
|
|
41428
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
41429
|
+
this.abortControllersByServerId.delete(environmentId);
|
|
41430
|
+
this.mergedLogCleanupDirByServerId.delete(environmentId);
|
|
41431
41431
|
},
|
|
41432
41432
|
rmMergedCleanupDir: (dir) => {
|
|
41433
41433
|
void rm2(dir, { recursive: true, force: true }).catch(() => {
|
|
41434
41434
|
});
|
|
41435
41435
|
},
|
|
41436
|
-
clearTailBuffers: () => this.clearTails(
|
|
41436
|
+
clearTailBuffers: () => this.clearTails(environmentId)
|
|
41437
41437
|
});
|
|
41438
|
-
this.sendStatus(
|
|
41438
|
+
this.sendStatus(environmentId, "running", `pid=${proc.pid ?? "?"}`, {
|
|
41439
41439
|
stdout: stdoutTail.getTail(),
|
|
41440
41440
|
stderr: stderrTail.getTail()
|
|
41441
41441
|
});
|
|
41442
41442
|
});
|
|
41443
41443
|
}
|
|
41444
|
-
handleControl(
|
|
41444
|
+
handleControl(environmentId, action) {
|
|
41445
41445
|
if (action === "stop") {
|
|
41446
|
-
this.stop(
|
|
41446
|
+
this.stop(environmentId);
|
|
41447
41447
|
return;
|
|
41448
41448
|
}
|
|
41449
|
-
this.start(
|
|
41449
|
+
this.start(environmentId);
|
|
41450
41450
|
}
|
|
41451
41451
|
async shutdownAllGraceful(opts) {
|
|
41452
41452
|
const graceMs = opts?.graceMs ?? BRIDGE_SHUTDOWN_GRACE_MS;
|
|
41453
41453
|
const pairs = [...this.processes.entries()];
|
|
41454
41454
|
if (pairs.length === 0) return;
|
|
41455
41455
|
this.log(
|
|
41456
|
-
`[
|
|
41456
|
+
`[preview-environment] Stopping ${pairs.length} local preview environment process${pairs.length === 1 ? "" : "es"}\u2026`
|
|
41457
41457
|
);
|
|
41458
|
-
await Promise.all(pairs.map(([
|
|
41458
|
+
await Promise.all(pairs.map(([environmentId, proc]) => this.gracefulTerminateOrUnknown(environmentId, proc, graceMs)));
|
|
41459
41459
|
}
|
|
41460
|
-
async gracefulTerminateOrUnknown(
|
|
41461
|
-
const shortId = `${
|
|
41460
|
+
async gracefulTerminateOrUnknown(environmentId, proc, graceMs) {
|
|
41461
|
+
const shortId = `${environmentId.slice(0, 8)}\u2026`;
|
|
41462
41462
|
await sigtermAndWaitForExit(proc, graceMs, this.log, shortId);
|
|
41463
|
-
if (!this.processes.has(
|
|
41463
|
+
if (!this.processes.has(environmentId) || this.processes.get(environmentId) !== proc) {
|
|
41464
41464
|
return;
|
|
41465
41465
|
}
|
|
41466
|
-
this.bumpGeneration(
|
|
41466
|
+
this.bumpGeneration(environmentId);
|
|
41467
41467
|
forceKillChild(proc, this.log, shortId, graceMs);
|
|
41468
|
-
this.processes.delete(
|
|
41469
|
-
this.clearPoll(
|
|
41470
|
-
this.pipedCaptureByServerId.delete(
|
|
41471
|
-
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId,
|
|
41472
|
-
const tails = this.snapshotTails(
|
|
41473
|
-
this.clearTails(
|
|
41474
|
-
this.sendStatus(
|
|
41468
|
+
this.processes.delete(environmentId);
|
|
41469
|
+
this.clearPoll(environmentId);
|
|
41470
|
+
this.pipedCaptureByServerId.delete(environmentId);
|
|
41471
|
+
cleanupMergedLogDirForServer(this.mergedLogCleanupDirByServerId, environmentId);
|
|
41472
|
+
const tails = this.snapshotTails(environmentId);
|
|
41473
|
+
this.clearTails(environmentId);
|
|
41474
|
+
this.sendStatus(environmentId, "unknown", "Bridge closed before process exited", tails);
|
|
41475
41475
|
}
|
|
41476
41476
|
};
|
|
41477
41477
|
|
|
@@ -41529,20 +41529,20 @@ function createFirehoseMessageRouter() {
|
|
|
41529
41529
|
};
|
|
41530
41530
|
}
|
|
41531
41531
|
|
|
41532
|
-
// src/firehose/routing/handlers/
|
|
41533
|
-
var
|
|
41534
|
-
const
|
|
41532
|
+
// src/firehose/routing/handlers/preview-environment-logs-viewer-open.ts
|
|
41533
|
+
var handlePreviewEnvironmentLogsViewerOpen = (msg, deps) => {
|
|
41534
|
+
const environmentId = typeof msg.environmentId === "string" ? msg.environmentId : "";
|
|
41535
41535
|
const viewerId = typeof msg.viewerId === "string" ? msg.viewerId : "";
|
|
41536
|
-
if (!
|
|
41537
|
-
deps.
|
|
41536
|
+
if (!environmentId || !viewerId) return;
|
|
41537
|
+
deps.previewEnvironmentManager.handleFirehoseLogViewerOpen(environmentId, viewerId);
|
|
41538
41538
|
};
|
|
41539
41539
|
|
|
41540
|
-
// src/firehose/routing/handlers/
|
|
41541
|
-
var
|
|
41542
|
-
const
|
|
41540
|
+
// src/firehose/routing/handlers/preview-environment-logs-viewer-close.ts
|
|
41541
|
+
var handlePreviewEnvironmentLogsViewerClose = (msg, deps) => {
|
|
41542
|
+
const environmentId = typeof msg.environmentId === "string" ? msg.environmentId : "";
|
|
41543
41543
|
const viewerId = typeof msg.viewerId === "string" ? msg.viewerId : "";
|
|
41544
|
-
if (!
|
|
41545
|
-
deps.
|
|
41544
|
+
if (!environmentId || !viewerId) return;
|
|
41545
|
+
deps.previewEnvironmentManager.handleFirehoseLogViewerClose(environmentId, viewerId);
|
|
41546
41546
|
};
|
|
41547
41547
|
|
|
41548
41548
|
// src/firehose/routing/handlers/proxy-message.ts
|
|
@@ -41591,8 +41591,8 @@ var handleFirehoseIdentified = (_msg, _deps) => {
|
|
|
41591
41591
|
// src/firehose/routing/dispatch-firehose-message.ts
|
|
41592
41592
|
var router = createFirehoseMessageRouter();
|
|
41593
41593
|
router.register("identified", handleFirehoseIdentified);
|
|
41594
|
-
router.register("log_viewer_open",
|
|
41595
|
-
router.register("log_viewer_close",
|
|
41594
|
+
router.register("log_viewer_open", handlePreviewEnvironmentLogsViewerOpen);
|
|
41595
|
+
router.register("log_viewer_close", handlePreviewEnvironmentLogsViewerClose);
|
|
41596
41596
|
router.register("proxy", handleProxyMessage);
|
|
41597
41597
|
function dispatchFirehoseJsonMessage(msg, deps) {
|
|
41598
41598
|
router.dispatch(msg, deps);
|
|
@@ -41622,7 +41622,7 @@ function connectFirehose(options) {
|
|
|
41622
41622
|
bridgeName,
|
|
41623
41623
|
proxyPorts,
|
|
41624
41624
|
log: log2,
|
|
41625
|
-
|
|
41625
|
+
previewEnvironmentManager,
|
|
41626
41626
|
onOpen,
|
|
41627
41627
|
onClose,
|
|
41628
41628
|
suppressWebSocketErrors
|
|
@@ -41642,7 +41642,7 @@ function connectFirehose(options) {
|
|
|
41642
41642
|
const deps = {
|
|
41643
41643
|
ws,
|
|
41644
41644
|
log: log2,
|
|
41645
|
-
|
|
41645
|
+
previewEnvironmentManager,
|
|
41646
41646
|
pendingProxyBody,
|
|
41647
41647
|
startStreamingProxy: (pr) => startStreamingProxy(ws, log2, pr)
|
|
41648
41648
|
};
|
|
@@ -41650,7 +41650,7 @@ function connectFirehose(options) {
|
|
|
41650
41650
|
disposeClientPing();
|
|
41651
41651
|
clearClientPing = attachWebSocketClientPing(ws, CLI_WEBSOCKET_CLIENT_PING_MS);
|
|
41652
41652
|
onOpen?.();
|
|
41653
|
-
|
|
41653
|
+
previewEnvironmentManager.attachFirehose(firehoseSend);
|
|
41654
41654
|
sendWsMessage(ws, { type: "identify", workspaceId, bridgeName, proxyPorts });
|
|
41655
41655
|
});
|
|
41656
41656
|
ws.on("message", (raw) => {
|
|
@@ -41667,7 +41667,7 @@ function connectFirehose(options) {
|
|
|
41667
41667
|
});
|
|
41668
41668
|
ws.on("close", (code, reason) => {
|
|
41669
41669
|
disposeClientPing();
|
|
41670
|
-
|
|
41670
|
+
previewEnvironmentManager.detachFirehose();
|
|
41671
41671
|
const reasonStr = typeof reason === "string" ? reason : reason.toString();
|
|
41672
41672
|
onClose?.(code, reasonStr);
|
|
41673
41673
|
});
|
|
@@ -41683,7 +41683,7 @@ function connectFirehose(options) {
|
|
|
41683
41683
|
return {
|
|
41684
41684
|
close() {
|
|
41685
41685
|
disposeClientPing();
|
|
41686
|
-
|
|
41686
|
+
previewEnvironmentManager.detachFirehose();
|
|
41687
41687
|
safeCloseWebSocket(ws);
|
|
41688
41688
|
},
|
|
41689
41689
|
isConnected: () => ws.readyState === wrapper_default.OPEN
|
|
@@ -41692,7 +41692,7 @@ function connectFirehose(options) {
|
|
|
41692
41692
|
|
|
41693
41693
|
// src/connection/attach-firehose-after-identified.ts
|
|
41694
41694
|
function attachFirehoseAfterIdentified(ctx, params) {
|
|
41695
|
-
const { state,
|
|
41695
|
+
const { state, previewEnvironmentManager, logFn } = ctx;
|
|
41696
41696
|
function clearFirehoseReconnectTimer() {
|
|
41697
41697
|
if (state.firehoseReconnectTimeout != null) {
|
|
41698
41698
|
clearTimeout(state.firehoseReconnectTimeout);
|
|
@@ -41758,7 +41758,7 @@ function attachFirehoseAfterIdentified(ctx, params) {
|
|
|
41758
41758
|
bridgeName: params.bridgeName,
|
|
41759
41759
|
proxyPorts: params.proxyPorts,
|
|
41760
41760
|
log: logFn,
|
|
41761
|
-
|
|
41761
|
+
previewEnvironmentManager,
|
|
41762
41762
|
suppressWebSocketErrors: () => !state.closedByUser && state.firehoseOutage.startedAt != null,
|
|
41763
41763
|
onOpen: () => {
|
|
41764
41764
|
if (myGen !== state.firehoseGeneration) return;
|
|
@@ -41801,14 +41801,14 @@ function attachFirehoseAfterIdentified(ctx, params) {
|
|
|
41801
41801
|
|
|
41802
41802
|
// src/connection/create-bridge-identified-handler.ts
|
|
41803
41803
|
function createOnBridgeIdentified(opts) {
|
|
41804
|
-
const {
|
|
41805
|
-
const firehoseCtx = { state,
|
|
41804
|
+
const { previewEnvironmentManager, firehoseServerUrl, workspaceId, state, logFn } = opts;
|
|
41805
|
+
const firehoseCtx = { state, previewEnvironmentManager, logFn };
|
|
41806
41806
|
return (msg) => {
|
|
41807
41807
|
const bridgeName = msg.bridgeName;
|
|
41808
41808
|
const proxyPorts = Array.isArray(msg.proxyPorts) ? msg.proxyPorts : [];
|
|
41809
|
-
const
|
|
41809
|
+
const previewEnvironments = msg.previewEnvironments ?? [];
|
|
41810
41810
|
setImmediate(() => {
|
|
41811
|
-
|
|
41811
|
+
previewEnvironmentManager.applyConfig(previewEnvironments);
|
|
41812
41812
|
if (!firehoseServerUrl || typeof bridgeName !== "string" || !bridgeName) return;
|
|
41813
41813
|
state.firehoseReconnectAttempt = 0;
|
|
41814
41814
|
attachFirehoseAfterIdentified(firehoseCtx, {
|
|
@@ -41984,8 +41984,8 @@ var API_TO_BRIDGE_MESSAGE_TYPES = [
|
|
|
41984
41984
|
"auth_token",
|
|
41985
41985
|
"bridge_identified",
|
|
41986
41986
|
"ha",
|
|
41987
|
-
"
|
|
41988
|
-
"
|
|
41987
|
+
"preview_environments_config",
|
|
41988
|
+
"preview_environment_control",
|
|
41989
41989
|
"agent_config",
|
|
41990
41990
|
"prompt_queue_state",
|
|
41991
41991
|
"prompt",
|
|
@@ -42045,7 +42045,7 @@ var handleBridgeIdentified = (msg, deps) => {
|
|
|
42045
42045
|
deps.onBridgeIdentified({
|
|
42046
42046
|
bridgeName: msg.bridgeName,
|
|
42047
42047
|
proxyPorts: msg.proxyPorts,
|
|
42048
|
-
|
|
42048
|
+
previewEnvironments: msg.previewEnvironments
|
|
42049
42049
|
});
|
|
42050
42050
|
setImmediate(() => {
|
|
42051
42051
|
void (async () => {
|
|
@@ -44308,26 +44308,26 @@ var handleRevertTurnSnapshotMessage = (msg, deps) => {
|
|
|
44308
44308
|
})();
|
|
44309
44309
|
};
|
|
44310
44310
|
|
|
44311
|
-
// src/routing/handlers/
|
|
44312
|
-
var
|
|
44311
|
+
// src/routing/handlers/preview-environment-control.ts
|
|
44312
|
+
var handlePreviewEnvironmentControl = (msg, deps) => {
|
|
44313
44313
|
let wire;
|
|
44314
44314
|
try {
|
|
44315
44315
|
wire = deps.e2ee ? deps.e2ee.decryptMessage(msg) : msg;
|
|
44316
44316
|
} catch (e) {
|
|
44317
|
-
deps.log(`[E2EE] Could not decrypt
|
|
44317
|
+
deps.log(`[E2EE] Could not decrypt preview environment command: ${e instanceof Error ? e.message : String(e)}`);
|
|
44318
44318
|
return;
|
|
44319
44319
|
}
|
|
44320
|
-
const
|
|
44320
|
+
const environmentId = typeof wire.environmentId === "string" ? wire.environmentId : "";
|
|
44321
44321
|
const action = wire.action === "start" || wire.action === "stop" ? wire.action : null;
|
|
44322
|
-
if (!
|
|
44323
|
-
deps.
|
|
44322
|
+
if (!environmentId || !action) return;
|
|
44323
|
+
deps.previewEnvironmentManager?.handleControl(environmentId, action);
|
|
44324
44324
|
};
|
|
44325
44325
|
|
|
44326
|
-
// src/routing/handlers/
|
|
44327
|
-
var
|
|
44328
|
-
const
|
|
44326
|
+
// src/routing/handlers/preview-environments-config.ts
|
|
44327
|
+
var handlePreviewEnvironmentsConfig = (msg, deps) => {
|
|
44328
|
+
const previewEnvironments = msg.previewEnvironments;
|
|
44329
44329
|
setImmediate(() => {
|
|
44330
|
-
deps.
|
|
44330
|
+
deps.previewEnvironmentManager?.applyConfig(previewEnvironments ?? []);
|
|
44331
44331
|
});
|
|
44332
44332
|
};
|
|
44333
44333
|
|
|
@@ -44487,11 +44487,11 @@ function dispatchBridgeMessage(msg, deps) {
|
|
|
44487
44487
|
case "ha":
|
|
44488
44488
|
handleBridgeHeartbeatAck(msg, deps);
|
|
44489
44489
|
break;
|
|
44490
|
-
case "
|
|
44491
|
-
|
|
44490
|
+
case "preview_environments_config":
|
|
44491
|
+
handlePreviewEnvironmentsConfig(msg, deps);
|
|
44492
44492
|
break;
|
|
44493
|
-
case "
|
|
44494
|
-
|
|
44493
|
+
case "preview_environment_control":
|
|
44494
|
+
handlePreviewEnvironmentControl(msg, deps);
|
|
44495
44495
|
break;
|
|
44496
44496
|
case "agent_config":
|
|
44497
44497
|
handleAgentConfigMessage(msg, deps);
|
|
@@ -45678,7 +45678,7 @@ function createBridgeMessageDeps(params) {
|
|
|
45678
45678
|
sendLocalSkillsReport,
|
|
45679
45679
|
reportAutoDetectedAgents,
|
|
45680
45680
|
warmupAgentCapabilitiesOnConnect: warmupAgentCapabilitiesOnConnect2,
|
|
45681
|
-
|
|
45681
|
+
previewEnvironmentManager,
|
|
45682
45682
|
e2ee,
|
|
45683
45683
|
cloudApiBaseUrl,
|
|
45684
45684
|
getCloudAccessToken
|
|
@@ -45695,7 +45695,7 @@ function createBridgeMessageDeps(params) {
|
|
|
45695
45695
|
sendLocalSkillsReport,
|
|
45696
45696
|
reportAutoDetectedAgents,
|
|
45697
45697
|
warmupAgentCapabilitiesOnConnect: warmupAgentCapabilitiesOnConnect2,
|
|
45698
|
-
|
|
45698
|
+
previewEnvironmentManager,
|
|
45699
45699
|
e2ee,
|
|
45700
45700
|
cloudApiBaseUrl,
|
|
45701
45701
|
getCloudAccessToken
|
|
@@ -45765,10 +45765,10 @@ async function createBridgeConnection(options) {
|
|
|
45765
45765
|
initialIndexBuildsScheduled = true;
|
|
45766
45766
|
scheduleInitialIndexBuilds(getBridgeRoot());
|
|
45767
45767
|
};
|
|
45768
|
-
const
|
|
45768
|
+
const previewEnvironmentManager = new PreviewEnvironmentManager({ getWs, log: logFn, getBridgeRoot, e2ee });
|
|
45769
45769
|
const bridgeHeartbeat = createBridgeHeartbeatController({ getWs, log: logFn });
|
|
45770
45770
|
const baseOnBridgeIdentified = createOnBridgeIdentified({
|
|
45771
|
-
|
|
45771
|
+
previewEnvironmentManager,
|
|
45772
45772
|
firehoseServerUrl,
|
|
45773
45773
|
workspaceId,
|
|
45774
45774
|
state,
|
|
@@ -45794,7 +45794,7 @@ async function createBridgeConnection(options) {
|
|
|
45794
45794
|
log: logFn,
|
|
45795
45795
|
getWs
|
|
45796
45796
|
}),
|
|
45797
|
-
|
|
45797
|
+
previewEnvironmentManager,
|
|
45798
45798
|
e2ee,
|
|
45799
45799
|
cloudApiBaseUrl: apiUrl,
|
|
45800
45800
|
getCloudAccessToken: () => tokens.accessToken
|
|
@@ -45827,7 +45827,7 @@ async function createBridgeConnection(options) {
|
|
|
45827
45827
|
requestCliImmediateShutdown();
|
|
45828
45828
|
stopFileIndexWatcher();
|
|
45829
45829
|
bridgeHeartbeat.stop();
|
|
45830
|
-
await closeBridgeConnection(state, acpManager,
|
|
45830
|
+
await closeBridgeConnection(state, acpManager, previewEnvironmentManager, logFn);
|
|
45831
45831
|
await bridgeAccess.close();
|
|
45832
45832
|
}
|
|
45833
45833
|
};
|