Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Claude Code Review

on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
# Optional: Only run on specific file changes
# paths:
# - "src/**/*.ts"
# - "src/**/*.tsx"
# - "src/**/*.js"
# - "src/**/*.jsx"

jobs:
claude-review:
# Optional: Filter by PR author
# if: |
# github.event.pull_request.user.login == 'external-contributor' ||
# github.event.pull_request.user.login == 'new-developer' ||
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'

runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
plugins: 'code-review@claude-code-plugins'
prompt: '/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}'
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://code.claude.com/docs/en/cli-reference for available options

50 changes: 50 additions & 0 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Claude Code

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]

jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read # Required for Claude to read CI results on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

# This is an optional setting that allows Claude to read CI results on PRs
additional_permissions: |
actions: read
# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
# prompt: 'Update the pull request description to include a summary of changes.'

# Optional: Add claude_args to customize behavior and configuration
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://code.claude.com/docs/en/cli-reference for available options
# claude_args: '--allowed-tools Bash(gh pr *)'

Original file line number Diff line number Diff line change
@@ -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);
Comment on lines +43 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using setInterval for polling can lead to overlapping requests if the network is slow or the server response time exceeds the interval (5 seconds). It is generally safer to use a recursive setTimeout pattern or check the loading state before initiating a new fetch to ensure only one request is active at a time.

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>
Comment on lines +98 to +102

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This component contains hardcoded Portuguese strings (e.g., "Modelos em cooldown"). Since the project uses next-intl for internationalization, these strings should be moved to the translation files (e.g., en.json, pt-BR.json) and accessed via the useTranslations hook. This ensures the UI remains consistent for users with different language settings.

</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>
);
}
Loading