"use client"; import { useState } from "react"; import { useTranslations } from "next-intl"; import { Button } from "@/shared/components"; type LaunchState = "idle" | "checking" | "launching" | "ready" | "error"; type Status = { exists?: boolean; running?: boolean; reachable?: boolean; message?: string; detail?: string; }; async function apiCall(endpoint: string, options: RequestInit = {}) { const res = await fetch(`/api/local/redis${endpoint}`, { method: options.method || "GET", headers: { "Content-Type": "application/json" }, body: options.body, cache: "no-store", }); if (!res.ok) { let detail = `HTTP ${res.status}`; try { const json = await res.json(); if (json?.error) detail = json.error; } catch { // ignore } throw new Error(detail); } return res.json(); } /** * Compact 1-click Redis control. Sits inside the resilience settings tab and * shells out to the same logic exposed via the `omniroute redis` CLI command. * The actual container management is delegated to the server-side endpoint * at /api/local/redis/* so the browser never executes podman/docker directly. */ export default function RedisLauncherPanel() { const t = useTranslations("settings"); const [state, setState] = useState("idle"); const [status, setStatus] = useState(null); const [error, setError] = useState(null); async function refresh() { setState("checking"); setError(null); try { const data = await apiCall("/status"); setStatus(data); setState(data.running ? "ready" : "idle"); } catch (err) { setError(err instanceof Error ? err.message : "Failed to query status"); setState("error"); } } async function launch() { setState("launching"); setError(null); try { const data = await apiCall("/start", { method: "POST" }); setStatus(data); setState("ready"); } catch (err) { setError(err instanceof Error ? err.message : "Failed to launch Redis"); setState("error"); } } async function stop() { setState("launching"); setError(null); try { await apiCall("/stop", { method: "POST" }); setStatus({ exists: false, running: false, reachable: false }); setState("idle"); } catch (err) { setError(err instanceof Error ? err.message : "Failed to stop Redis"); setState("error"); } } return (

{t("redisLauncherTitle", "Local Redis")}

{t( "redisLauncherDesc", "One-click launch a Redis 7 container (Podman or Docker) for response cache, quota tracking, and rate limiting." )}

{status?.running ? ( ) : ( )}
{status && (
)} {error && (

{t("redisLauncherError", "Error: {{message}}", { message: error })}

)}

{t( "redisLauncherHint", "Equivalent to running `omniroute redis up`. The container is named `omniroute-redis` and listens on 127.0.0.1:6379." )}

); } function Stat({ label, value, tone, }: { label: string; value: string; tone: "ok" | "warn"; }) { const color = tone === "ok" ? "text-emerald-400" : "text-amber-400"; return (
{label}
{value}
); }