feat: add restart gateway and update Hermes action buttons to web dashboard
All checks were successful
Lint / lint (pull_request) Successful in 29s

Implements the update/restart action buttons called out in issue #961:

- Backend (web_server.py): two new POST endpoints
  - /api/actions/restart-gateway — sends SIGUSR1 to the running gateway PID
  - /api/actions/update-hermes  — runs `hermes update --yes` in a subprocess
- Frontend (api.ts): restartGateway() / updateHermes() API helpers + ActionResponse type
- UI (StatusPage.tsx): "Actions" card with Restart Gateway and Update Hermes buttons
  - idle → running (spinner) → success/failure states
  - feedback detail text; auto-resets to idle after 8 s
- i18n: new status.actions / restartGateway / updateHermes strings in en, zh, and types

Refs #961

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexander Whitestone
2026-04-21 22:30:22 -04:00
parent a2a40429bd
commit a8a086548d
6 changed files with 204 additions and 1 deletions

View File

@@ -86,6 +86,15 @@ export const en: Translations = {
lastUpdate: "Last update",
platformError: "error",
platformDisconnected: "disconnected",
actions: "Actions",
restartGateway: "Restart Gateway",
restarting: "Restarting…",
restartSuccess: "Gateway restart signal sent",
restartFailed: "Restart failed",
updateHermes: "Update Hermes",
updating: "Updating…",
updateSuccess: "Update complete",
updateFailed: "Update failed",
},
sessions: {

View File

@@ -89,6 +89,15 @@ export interface Translations {
lastUpdate: string;
platformError: string;
platformDisconnected: string;
actions: string;
restartGateway: string;
restarting: string;
restartSuccess: string;
restartFailed: string;
updateHermes: string;
updating: string;
updateSuccess: string;
updateFailed: string;
};
// ── Sessions page ──

View File

@@ -86,6 +86,15 @@ export const zh: Translations = {
lastUpdate: "最后更新",
platformError: "错误",
platformDisconnected: "已断开",
actions: "操作",
restartGateway: "重启网关",
restarting: "重启中…",
restartSuccess: "重启信号已发送",
restartFailed: "重启失败",
updateHermes: "更新 Hermes",
updating: "更新中…",
updateSuccess: "更新完成",
updateFailed: "更新失败",
},
sessions: {

View File

@@ -182,6 +182,12 @@ export const api = {
},
);
},
// Dashboard actions
restartGateway: () =>
fetchJSON<ActionResponse>("/api/actions/restart-gateway", { method: "POST" }),
updateHermes: () =>
fetchJSON<ActionResponse>("/api/actions/update-hermes", { method: "POST" }),
};
export interface PlatformStatus {
@@ -409,6 +415,11 @@ export interface OAuthSubmitResponse {
message?: string;
}
export interface ActionResponse {
ok: boolean;
detail: string;
}
export interface OAuthPollResponse {
session_id: string;
status: "pending" | "approved" | "denied" | "expired" | "error";

View File

@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import {
Activity,
AlertTriangle,
@@ -6,19 +6,30 @@ import {
Cpu,
Database,
Radio,
RefreshCw,
TriangleAlert,
Wifi,
WifiOff,
Zap,
} from "lucide-react";
import { api } from "@/lib/api";
import type { PlatformStatus, SessionInfo, StatusResponse } from "@/lib/api";
import { timeAgo, isoTimeAgo } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { useI18n } from "@/i18n";
type ActionState = "idle" | "running" | "success" | "failure";
export default function StatusPage() {
const [status, setStatus] = useState<StatusResponse | null>(null);
const [sessions, setSessions] = useState<SessionInfo[]>([]);
const [restartState, setRestartState] = useState<ActionState>("idle");
const [restartDetail, setRestartDetail] = useState("");
const [updateState, setUpdateState] = useState<ActionState>("idle");
const [updateDetail, setUpdateDetail] = useState("");
const resetTimers = useRef<Record<string, ReturnType<typeof setTimeout>>>({});
const { t } = useI18n();
useEffect(() => {
@@ -31,6 +42,39 @@ export default function StatusPage() {
return () => clearInterval(interval);
}, []);
function scheduleReset(key: string, setter: (s: ActionState) => void) {
clearTimeout(resetTimers.current[key]);
resetTimers.current[key] = setTimeout(() => setter("idle"), 8000);
}
async function handleRestartGateway() {
setRestartState("running");
setRestartDetail("");
try {
const resp = await api.restartGateway();
setRestartState(resp.ok ? "success" : "failure");
setRestartDetail(resp.detail);
} catch (err: unknown) {
setRestartState("failure");
setRestartDetail(err instanceof Error ? err.message : String(err));
}
scheduleReset("restart", setRestartState);
}
async function handleUpdateHermes() {
setUpdateState("running");
setUpdateDetail("");
try {
const resp = await api.updateHermes();
setUpdateState(resp.ok ? "success" : "failure");
setUpdateDetail(resp.detail);
} catch (err: unknown) {
setUpdateState("failure");
setUpdateDetail(err instanceof Error ? err.message : String(err));
}
scheduleReset("update", setUpdateState);
}
if (!status) {
return (
<div className="flex items-center justify-center py-24">
@@ -159,6 +203,60 @@ export default function StatusPage() {
))}
</div>
{/* Action buttons — restart gateway / update Hermes */}
<Card>
<CardHeader>
<div className="flex items-center gap-2">
<Zap className="h-5 w-5 text-muted-foreground" />
<CardTitle className="text-base">{t.status.actions}</CardTitle>
</div>
</CardHeader>
<CardContent className="flex flex-wrap gap-3">
{/* Restart Gateway */}
<div className="flex flex-col gap-1">
<Button
variant="outline"
size="sm"
disabled={restartState === "running"}
onClick={handleRestartGateway}
>
<RefreshCw className={`h-3.5 w-3.5 mr-1 ${restartState === "running" ? "animate-spin" : ""}`} />
{restartState === "running" ? t.status.restarting : t.status.restartGateway}
</Button>
{restartDetail && (
<p className={`text-xs max-w-xs truncate ${restartState === "failure" ? "text-destructive" : "text-muted-foreground"}`}>
{restartState === "failure" && <TriangleAlert className="inline h-3 w-3 mr-1" />}
{restartState === "success" ? t.status.restartSuccess : restartState === "failure" ? t.status.restartFailed : ""}
{restartDetail && `${restartDetail}`}
</p>
)}
{restartState === "success" && !restartDetail && (
<p className="text-xs text-muted-foreground">{t.status.restartSuccess}</p>
)}
</div>
{/* Update Hermes */}
<div className="flex flex-col gap-1">
<Button
variant="outline"
size="sm"
disabled={updateState === "running"}
onClick={handleUpdateHermes}
>
<RefreshCw className={`h-3.5 w-3.5 mr-1 ${updateState === "running" ? "animate-spin" : ""}`} />
{updateState === "running" ? t.status.updating : t.status.updateHermes}
</Button>
{(updateDetail || updateState === "success" || updateState === "failure") && (
<p className={`text-xs max-w-xs ${updateState === "failure" ? "text-destructive" : "text-muted-foreground"}`}>
{updateState === "failure" && <TriangleAlert className="inline h-3 w-3 mr-1" />}
{updateState === "success" ? t.status.updateSuccess : updateState === "failure" ? t.status.updateFailed : ""}
{updateDetail && `${updateDetail}`}
</p>
)}
</div>
</CardContent>
</Card>
{platforms.length > 0 && (
<PlatformsCard platforms={platforms} platformStateBadge={PLATFORM_STATE_BADGE} />
)}