Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

feat(resilience): add model cooldowns dashboard card with real-time list and re-enable

diegosouzapwe4c8c14fb327
diff --git a/src/app/(dashboard)/dashboard/settings/components/ModelCooldownsCard.tsx b/src/app/(dashboard)/dashboard/settings/components/ModelCooldownsCard.tsx
new file mode 100644
index 0000000000..5ca9122b93
--- /dev/null
+++ b/src/app/(dashboard)/dashboard/settings/components/ModelCooldownsCard.tsx
@@ -0,0 +1,155 @@
+"use client";
+
+import { useCallback, useEffect, useMemo, useState } from "react";
+import { Button, Card } from "@/shared/components";
+import { useNotificationStore } from "@/store/notificationStore";
+
+type CooldownItem = {
+ provider: string;
+ model: string;
+ reason: string;
+ remainingMs: number;
+ unavailableSince: string;
+};
+
+function formatRemaining(ms: number): string {
+ const totalSec = Math.max(0, Math.ceil(ms / 1000));
+ const min = Math.floor(totalSec / 60);
+ const sec = totalSec % 60;
+ return `${min}m ${sec}s`;
+}
+
+export default function ModelCooldownsCard() {
+ const notify = useNotificationStore();
+ const [items, setItems] = useState<CooldownItem[]>([]);
+ const [loading, setLoading] = useState(true);
+ const [busyKey, setBusyKey] = useState<string | null>(null);
+
+ const load = useCallback(async () => {
+ try {
+ const res = await fetch("/api/resilience/model-cooldowns", { cache: "no-store" });
+ const json = await res.json();
+ if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`);
+ setItems(Array.isArray(json.items) ? json.items : []);
+ } catch (error) {
+ notify.error(error instanceof Error ? error.message : "Failed to load cooldowns");
+ } finally {
+ setLoading(false);
+ }
+ }, [notify]);
+
+ useEffect(() => {
+ void load();
+ const timer = setInterval(() => {
+ void load();
+ }, 5000);
+ return () => clearInterval(timer);
+ }, [load]);
+
+ const clearOne = useCallback(
+ async (provider: string, model: string) => {
+ const key = `${provider}::${model}`;
+ setBusyKey(key);
+ try {
+ const res = await fetch("/api/resilience/model-cooldowns", {
+ method: "DELETE",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ provider, model }),
+ });
+ const json = await res.json();
+ if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`);
+ notify.success(`Modelo reativado: ${provider}/${model}`);
+ await load();
+ } catch (error) {
+ notify.error(error instanceof Error ? error.message : "Failed to clear cooldown");
+ } finally {
+ setBusyKey(null);
+ }
+ },
+ [load, notify]
+ );
+
+ const clearAll = useCallback(async () => {
+ setBusyKey("ALL");
+ try {
+ const res = await fetch("/api/resilience/model-cooldowns", {
+ method: "DELETE",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ all: true }),
+ });
+ const json = await res.json();
+ if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`);
+ notify.success("Todos os modelos em cooldown foram reativados.");
+ await load();
+ } catch (error) {
+ notify.error(error instanceof Error ? error.message : "Failed to clear cooldowns");
+ } finally {
+ setBusyKey(null);
+ }
+ }, [load, notify]);
+
+ const hasItems = items.length > 0;
+ const sorted = useMemo(() => [...items].sort((a, b) => b.remainingMs - a.remainingMs), [items]);
+
+ return (
+ <Card className="p-6">
+ <div className="flex items-start justify-between gap-4">
+ <div>
+ <h2 className="text-lg font-bold text-text-main">Modelos em cooldown</h2>
+ <p className="mt-1 text-sm text-text-muted">
+ Lista de modelos temporariamente isolados por falha. Quando o cooldown expira, eles
+ voltam automaticamente.
+ </p>
+ </div>
+ <div className="flex gap-2">
+ <Button size="sm" variant="secondary" onClick={() => void load()} disabled={loading}>
+ Atualizar
+ </Button>
+ <Button
+ size="sm"
+ variant="primary"
+ onClick={() => void clearAll()}
+ disabled={!hasItems || busyKey === "ALL"}
+ >
+ Reativar todos
+ </Button>
+ </div>
+ </div>
+
+ <div className="mt-4 space-y-2">
+ {loading ? (
+ <p className="text-sm text-text-muted">Carregando...</p>
+ ) : !hasItems ? (
+ <p className="text-sm text-text-muted">Nenhum modelo em cooldown no momento.</p>
+ ) : (
+ sorted.map((item) => {
+ const rowKey = `${item.provider}::${item.model}`;
+ return (
+ <div
+ key={rowKey}
+ className="rounded-lg border border-border bg-bg-subtle px-3 py-2 flex items-center justify-between gap-3"
+ >
+ <div className="min-w-0">
+ <p className="text-sm font-medium text-text-main truncate">
+ {item.provider}/{item.model}
+ </p>
+ <p className="text-xs text-text-muted">
+ motivo: {item.reason} • restante: {formatRemaining(item.remainingMs)}
+ </p>
+ </div>
+ <Button
+ size="sm"
+ variant="secondary"
+ onClick={() => void clearOne(item.provider, item.model)}
+ disabled={busyKey === rowKey}
+ >
+ Reativar
+ </Button>
+ </div>
+ );
+ })
+ )}
+ </div>
+ </Card>
+ );
+}
diff --git a/src/app/(dashboard)/dashboard/settings/components/ResilienceTab.tsx b/src/app/(dashboard)/dashboard/settings/components/ResilienceTab.tsx
index 744aedb3f0..62ac307345 100644
--- a/src/app/(dashboard)/dashboard/settings/components/ResilienceTab.tsx
+++ b/src/app/(dashboard)/dashboard/settings/components/ResilienceTab.tsx
@@ -1,9 +1,11 @@
"use client";
-import { type ReactNode, useEffect, useState } from "react";
+import { type ReactNode, useCallback, useEffect, useState } from "react";
import { Button, Card } from "@/shared/components";
import { useNotificationStore } from "@/store/notificationStore";
import { useTranslations } from "next-intl";
+import AutoDisableCard from "./AutoDisableCard";
+import ModelCooldownsCard from "./ModelCooldownsCard";
type RequestQueueSettings = {
autoEnableApiKeyProviders: boolean;
@@ -788,6 +790,8 @@ export default function ResilienceTab() {
return (
<div className="space-y-6">
+ <ModelCooldownsCard />
+ <AutoDisableCard />
<Card className="p-6">
<div className="flex items-start gap-3">
<span className="material-symbols-outlined text-xl text-primary">info</span>
diff --git a/src/app/api/resilience/model-cooldowns/route.ts b/src/app/api/resilience/model-cooldowns/route.ts
new file mode 100644
index 0000000000..f225614b38
--- /dev/null
+++ b/src/app/api/resilience/model-cooldowns/route.ts
@@ -0,0 +1,53 @@
+import { NextResponse } from "next/server";
+import {
+ clearModelUnavailability,
+ getAvailabilityReport,
+ resetAllAvailability,
+} from "@/domain/modelAvailability";
+
+function getErrorMessage(error: unknown, fallback: string): string {
+ return error instanceof Error && error.message ? error.message : fallback;
+}
+
+export async function GET() {
+ try {
+ const items = getAvailabilityReport().sort((a, b) => b.remainingMs - a.remainingMs);
+ return NextResponse.json({ items });
+ } catch (error: unknown) {
+ console.error("[API] GET /api/resilience/model-cooldowns error:", error);
+ return NextResponse.json(
+ { error: getErrorMessage(error, "Failed to load cooldowns") },
+ { status: 500 }
+ );
+ }
+}
+
+export async function DELETE(request: Request) {
+ try {
+ const body = (await request.json().catch(() => ({}))) as {
+ provider?: string;
+ model?: string;
+ all?: boolean;
+ };
+
+ if (body.all) {
+ resetAllAvailability();
+ return NextResponse.json({ ok: true, clearedAll: true });
+ }
+
+ const provider = typeof body.provider === "string" ? body.provider.trim() : "";
+ const model = typeof body.model === "string" ? body.model.trim() : "";
+ if (!provider || !model) {
+ return NextResponse.json({ error: "provider and model are required" }, { status: 400 });
+ }
+
+ const removed = clearModelUnavailability(provider, model);
+ return NextResponse.json({ ok: true, removed });
+ } catch (error: unknown) {
+ console.error("[API] DELETE /api/resilience/model-cooldowns error:", error);
+ return NextResponse.json(
+ { error: getErrorMessage(error, "Failed to clear cooldown") },
+ { status: 500 }
+ );
+ }
+}