Gateway: optional canvas host

This commit is contained in:
Peter Steinberger
2025-12-18 11:35:21 +01:00
parent cfb36525ab
commit cd729e83b6
6 changed files with 383 additions and 0 deletions

View File

@@ -18,6 +18,10 @@ import {
startBrowserControlServerFromConfig,
stopBrowserControlServer,
} from "../browser/server.js";
import {
type CanvasHostServer,
startCanvasHost,
} from "../canvas-host/server.js";
import { createDefaultDeps } from "../cli/deps.js";
import { agentCommand } from "../commands/agent.js";
import { getHealthSnapshot, type HealthSummary } from "../commands/health.js";
@@ -533,6 +537,7 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
const httpServer: HttpServer = createHttpServer();
let bonjourStop: (() => Promise<void>) | null = null;
let bridge: Awaited<ReturnType<typeof startNodeBridgeServer>> | null = null;
let canvasHost: CanvasHostServer | null = null;
const bridgeNodeSubscriptions = new Map<string, Set<string>>();
const bridgeSessionSubscribers = new Map<string, Set<string>>();
try {
@@ -587,6 +592,19 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
const cfgAtStart = loadConfig();
setCommandLaneConcurrency("cron", cfgAtStart.cron?.maxConcurrentRuns ?? 1);
if (cfgAtStart.canvasHost?.enabled === true) {
try {
canvasHost = await startCanvasHost({
runtime: defaultRuntime,
rootDir: cfgAtStart.canvasHost.root,
port: cfgAtStart.canvasHost.port ?? 18793,
bind: cfgAtStart.canvasHost.bind ?? "lan",
});
} catch (err) {
logWarn(`gateway: canvas host failed to start: ${String(err)}`);
}
}
const cronStorePath = resolveCronStorePath(cfgAtStart.cron?.store);
const cronLogger = getChildLogger({
module: "cron",
@@ -1602,6 +1620,7 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
instanceName: formatBonjourInstanceName(machineDisplayName),
gatewayPort: port,
bridgePort: bridge?.port,
canvasPort: canvasHost?.port,
sshPort,
tailnetDns,
});
@@ -3575,6 +3594,13 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
/* ignore */
}
}
if (canvasHost) {
try {
await canvasHost.close();
} catch {
/* ignore */
}
}
if (bridge) {
try {
await bridge.close();