feat(dashboard): "Migrate to a single multiplexed gateway" on the System page
GET /api/gateway/migrate/plan returns the CLI plan JSON; POST /api/gateway/migrate spawns `hermes gateway migrate --multiplex --yes` detached (action log gateway-migrate.log). The Gateway card shows the button only for a multi-profile install that is not yet multiplexed, and disables it while listing the blockers.
This commit is contained in:
@@ -143,6 +143,24 @@ async def restart_gateway(profile: Optional[str] = None):
|
||||
return {"ok": True, "pid": proc.pid, "name": "gateway-restart"}
|
||||
|
||||
|
||||
@router.get("/api/gateway/migrate/plan")
|
||||
async def gateway_migrate_plan():
|
||||
"""Preflight for folding per-profile gateways into one multiplexer (same JSON as the CLI plan)."""
|
||||
from hermes_cli.gateway_migrate import build_migration_plan
|
||||
plan = await asyncio.to_thread(build_migration_plan)
|
||||
return plan.to_dict()
|
||||
|
||||
|
||||
@router.post("/api/gateway/migrate")
|
||||
async def gateway_migrate():
|
||||
"""Run ``hermes gateway migrate --multiplex --yes`` detached; the CLI re-runs the preflight and
|
||||
refuses (exit 1 into the action log) when blocked, so the UI should gate on the plan first."""
|
||||
from hermes_cli.web_server_gateway import _spawn_hermes_action
|
||||
with http_failure("Failed to spawn gateway migrate", 500, "Failed to start gateway migration"):
|
||||
proc = _spawn_hermes_action(["gateway", "migrate", "--multiplex", "--yes"], "gateway-migrate")
|
||||
return {"ok": True, "pid": proc.pid, "name": "gateway-migrate"}
|
||||
|
||||
|
||||
@router.post("/api/gateway/drain")
|
||||
async def gateway_drain(request: Request):
|
||||
"""Begin or cancel an external (NAS-driven) gateway drain.
|
||||
|
||||
@@ -262,6 +262,7 @@ _ACTION_LOG_FILES: Dict[str, str] = {
|
||||
"gateway-restart": "gateway-restart.log",
|
||||
"gateway-start": "gateway-start.log",
|
||||
"gateway-stop": "gateway-stop.log",
|
||||
"gateway-migrate": "gateway-migrate.log",
|
||||
"hermes-update": "hermes-update.log",
|
||||
**{name: f"action-{name}.log" for name in (
|
||||
"doctor", "security-audit", "backup", "import", "checkpoints-prune", "skills-install",
|
||||
|
||||
@@ -956,6 +956,10 @@ export const api = {
|
||||
// Gateway / update actions
|
||||
restartGateway: () =>
|
||||
fetchJSON<ActionResponse>("/api/gateway/restart", { method: "POST" }),
|
||||
getGatewayMigratePlan: () =>
|
||||
fetchJSON<GatewayMigratePlan>("/api/gateway/migrate/plan"),
|
||||
migrateGatewayToMultiplex: () =>
|
||||
fetchJSON<ActionResponse>("/api/gateway/migrate", { method: "POST" }),
|
||||
updateHermes: () =>
|
||||
fetchJSON<ActionResponse>("/api/hermes/update", { method: "POST" }),
|
||||
checkHermesUpdate: (force = false) =>
|
||||
@@ -1355,6 +1359,16 @@ export interface AuthMeResponse {
|
||||
expires_at: number;
|
||||
}
|
||||
|
||||
/** Preflight for `hermes gateway migrate --multiplex` (mirrors the CLI plan JSON). */
|
||||
export interface GatewayMigratePlan {
|
||||
already_multiplexed: boolean;
|
||||
blockers: string[];
|
||||
command: string;
|
||||
eligible: boolean;
|
||||
notices: string[];
|
||||
profiles: { profile: string; pid: number | null; service: { kind: string; system: boolean } | null }[];
|
||||
}
|
||||
|
||||
export interface ActionResponse {
|
||||
archive?: string;
|
||||
name: string;
|
||||
|
||||
@@ -59,6 +59,7 @@ import type {
|
||||
CuratorStatus,
|
||||
PortalStatus,
|
||||
DebugShareResponse,
|
||||
GatewayMigratePlan,
|
||||
} from "@/lib/api";
|
||||
|
||||
function formatBytes(n: number): string {
|
||||
@@ -207,6 +208,7 @@ export default function SystemPage() {
|
||||
|
||||
const [activeAction, setActiveAction] = useState<string | null>(null);
|
||||
const [consoleOpen, setConsoleOpen] = useState(false);
|
||||
const [migratePlan, setMigratePlan] = useState<GatewayMigratePlan | null>(null);
|
||||
|
||||
// Add-credential form.
|
||||
const [credProvider, setCredProvider] = useState("openrouter");
|
||||
@@ -266,8 +268,9 @@ export default function SystemPage() {
|
||||
// Cached (non-forced) check so the version row shows update status on
|
||||
// load without a separate effect / a forced network round-trip.
|
||||
api.checkHermesUpdate(false),
|
||||
api.getGatewayMigratePlan(),
|
||||
])
|
||||
.then(([s, st, m, p, c, h, cur, prt, upd]) => {
|
||||
.then(([s, st, m, p, c, h, cur, prt, upd, mig]) => {
|
||||
if (s.status === "fulfilled") setStatus(s.value);
|
||||
if (st.status === "fulfilled") setStats(st.value);
|
||||
if (m.status === "fulfilled") setMemory(m.value);
|
||||
@@ -277,6 +280,7 @@ export default function SystemPage() {
|
||||
if (cur.status === "fulfilled") setCurator(cur.value);
|
||||
if (prt.status === "fulfilled") setPortal(prt.value);
|
||||
if (upd.status === "fulfilled") setUpdateInfo(upd.value);
|
||||
if (mig.status === "fulfilled") setMigratePlan(mig.value);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
@@ -305,6 +309,17 @@ export default function SystemPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const migrateToMultiplex = async () => {
|
||||
try {
|
||||
await api.migrateGatewayToMultiplex();
|
||||
setActiveAction("gateway-migrate");
|
||||
showToast("Migrating to a single multiplexed gateway", "success");
|
||||
setTimeout(loadAll, 5000);
|
||||
} catch (e) {
|
||||
showToast(`Gateway migration failed: ${e}`, "error");
|
||||
}
|
||||
};
|
||||
|
||||
// ── Curator ────────────────────────────────────────────────────────
|
||||
const toggleCuratorPaused = async () => {
|
||||
if (!curator) return;
|
||||
@@ -1081,6 +1096,29 @@ export default function SystemPage() {
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
{migratePlan && !migratePlan.already_multiplexed && migratePlan.profiles.length > 1 && (
|
||||
migratePlan.eligible || migratePlan.blockers.length > 0
|
||||
) && (
|
||||
<CardContent className="flex flex-col gap-2 border-t border-border py-4 text-sm">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-muted-foreground">
|
||||
Your profiles each run their own gateway. One multiplexed gateway serves every profile from a single process.
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
className="uppercase"
|
||||
onClick={migrateToMultiplex}
|
||||
disabled={!migratePlan.eligible}
|
||||
title={migratePlan.eligible ? undefined : "Fix the blockers below first"}
|
||||
>
|
||||
Migrate to a single multiplexed gateway
|
||||
</Button>
|
||||
</div>
|
||||
{migratePlan.blockers.map((b) => (
|
||||
<div key={b} className="text-warning">• {b}</div>
|
||||
))}
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user