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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(activity): add /dashboard/activity timeline page + ActivityFeed (B/F4)
diegosouzapw319f52b98861
diff --git a/src/app/(dashboard)/dashboard/activity/ActivityFeedClient.tsx b/src/app/(dashboard)/dashboard/activity/ActivityFeedClient.tsxnew file mode 100644index 0000000000..fd301f54f4--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/ActivityFeedClient.tsx@@ -0,0 +1,125 @@+"use client";++import { useState, useEffect, useCallback, useRef } from "react";+import { useTranslations } from "next-intl";+import type { AuditLogEntry } from "@/lib/compliance/index";+import ActivityFeed from "./components/ActivityFeed";+import EventTypeFilter, {+ type EventCategory,+ matchesCategory,+} from "./components/EventTypeFilter";++const FEED_LIMIT = 200;++export default function ActivityFeedClient() {+ const t = useTranslations("activity");+ const [allEntries, setAllEntries] = useState<AuditLogEntry[]>([]);+ const [loading, setLoading] = useState(true);+ const [error, setError] = useState<string | null>(null);+ const [category, setCategory] = useState<EventCategory>("all");+ const referenceNowMs = useRef<number>(Date.now());++ const fetchEntries = useCallback(async () => {+ setLoading(true);+ setError(null);+ try {+ const params = new URLSearchParams({+ level: "high",+ limit: String(FEED_LIMIT),+ });+ const res = await fetch(`/api/compliance/audit-log?${params.toString()}`);+ if (!res.ok) {+ throw new Error(t("description"));+ }+ const data = (await res.json()) as AuditLogEntry[];+ // Reset reference time on fresh load so relative timestamps are stable+ referenceNowMs.current = Date.now();+ setAllEntries(Array.isArray(data) ? data : []);+ } catch (err: unknown) {+ const msg = err instanceof Error ? err.message : "Failed to fetch activity";+ setError(msg);+ } finally {+ setLoading(false);+ }+ }, [t]);++ useEffect(() => {+ fetchEntries();+ }, [fetchEntries]);++ const filtered =+ category === "all"+ ? allEntries+ : allEntries.filter((e) => {+ const action = typeof e.action === "string" ? e.action : "";+ return matchesCategory(action, category);+ });++ return (+ <div className="space-y-6">+ {/* Header */}+ <div className="flex items-start justify-between gap-4 flex-wrap">+ <div>+ <h1 className="text-xl font-bold text-[var(--color-text-main)]">{t("title")}</h1>+ <p className="text-sm text-[var(--color-text-muted)] mt-1">{t("description")}</p>+ </div>+ <button+ type="button"+ onClick={() => fetchEntries()}+ disabled={loading}+ className="px-4 py-2 rounded-lg text-sm font-medium bg-[var(--color-surface)] border border-[var(--color-border)] text-[var(--color-text-main)] hover:bg-[var(--color-bg-alt)] transition-colors disabled:opacity-50"+ aria-label="Refresh activity feed"+ >+ {loading ? (+ <span className="flex items-center gap-2">+ <span+ className="material-symbols-outlined text-[16px] animate-spin"+ aria-hidden="true"+ >+ progress_activity+ </span>+ Loading+ </span>+ ) : (+ <span className="flex items-center gap-2">+ <span className="material-symbols-outlined text-[16px]" aria-hidden="true">+ refresh+ </span>+ Refresh+ </span>+ )}+ </button>+ </div>++ {/* Filter */}+ <EventTypeFilter value={category} onChange={setCategory} />++ {/* Error */}+ {error && (+ <div+ className="p-4 rounded-lg bg-red-500/10 border border-red-500/30 text-red-400 text-sm"+ role="alert"+ >+ {error}+ </div>+ )}++ {/* Feed */}+ <div className="rounded-xl border border-[var(--color-border)] overflow-hidden bg-[var(--color-surface)]">+ {loading ? (+ <div className="flex items-center justify-center py-20 text-[var(--color-text-muted)]">+ <span+ className="material-symbols-outlined text-[32px] animate-spin mr-3"+ aria-hidden="true"+ >+ progress_activity+ </span>+ <span className="text-sm">Loading activity…</span>+ </div>+ ) : (+ <ActivityFeed entries={filtered} referenceNowMs={referenceNowMs.current} />+ )}+ </div>+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/activity/components/ActivityFeed.tsx b/src/app/(dashboard)/dashboard/activity/components/ActivityFeed.tsxnew file mode 100644index 0000000000..8f90cf4ef1--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/components/ActivityFeed.tsx@@ -0,0 +1,55 @@+"use client";++import { useTranslations } from "next-intl";+import { groupByDay } from "@/lib/audit/timeline";+import type { AuditLogEntry } from "@/lib/compliance/index";+import DayHeader from "./DayHeader";+import ActivityItem from "./ActivityItem";++interface ActivityFeedProps {+ entries: AuditLogEntry[];+ referenceNowMs?: number;+}++export default function ActivityFeed({ entries, referenceNowMs }: ActivityFeedProps) {+ const t = useTranslations("activity");++ if (!entries.length) {+ return (+ <div+ className="flex flex-col items-center justify-center py-20 text-center"+ role="status"+ aria-live="polite"+ >+ <span className="material-symbols-outlined text-[48px] text-[var(--color-text-muted)] mb-4" aria-hidden="true">+ timeline+ </span>+ <h3 className="text-base font-semibold text-[var(--color-text-main)] mb-1">+ {t("emptyTitle")}+ </h3>+ <p className="text-sm text-[var(--color-text-muted)] max-w-sm">{t("emptyDescription")}</p>+ </div>+ );+ }++ const groups = groupByDay(entries, referenceNowMs);++ return (+ <div className="divide-y divide-[var(--color-border)]">+ {groups.map((group) => (+ <section key={group.dayKey} aria-label={group.label}>+ <DayHeader label={group.label} dayKey={group.dayKey} />+ <ul className="divide-y divide-[var(--color-border)]">+ {group.entries.map((entry, idx) => (+ <ActivityItem+ key={typeof entry.id === "number" ? entry.id : `${group.dayKey}-${idx}`}+ entry={entry}+ referenceNowMs={referenceNowMs}+ />+ ))}+ </ul>+ </section>+ ))}+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/activity/components/ActivityItem.tsx b/src/app/(dashboard)/dashboard/activity/components/ActivityItem.tsxnew file mode 100644index 0000000000..c19e12371c--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/components/ActivityItem.tsx@@ -0,0 +1,60 @@+"use client";++import { useTranslations, useLocale } from "next-intl";+import { getActivityIcon } from "@/lib/audit/activityIcons";+import { relativeTime } from "@/lib/audit/timeline";+import type { AuditLogEntry } from "@/lib/compliance/index";++interface ActivityItemProps {+ entry: AuditLogEntry;+ referenceNowMs?: number;+}++export default function ActivityItem({ entry, referenceNowMs }: ActivityItemProps) {+ const t = useTranslations("activity");+ const locale = useLocale();++ const action = typeof entry.action === "string" ? entry.action : "";+ const actor = typeof entry.actor === "string" ? entry.actor : "system";+ const target = typeof entry.target === "string" ? entry.target : "";+ const timestamp = typeof entry.timestamp === "string" ? entry.timestamp : "";++ const { icon, i18nKeyVerb } = getActivityIcon(action);++ const safeLocale = locale === "pt-BR" ? "pt-BR" : "en";+ const timeAgo = timestamp ? relativeTime(timestamp, safeLocale, referenceNowMs) : "";++ // Build human phrase — fall back to raw action if key not found+ let phrase: string;+ try {+ phrase = t(`eventVerb.${i18nKeyVerb}`, { actor, target: target || action });+ } catch {+ phrase = `${actor} — ${action}`;+ }++ return (+ <li className="flex items-start gap-3 px-4 py-3 hover:bg-[var(--color-bg-alt)] transition-colors">+ <span+ className="material-symbols-outlined flex-shrink-0 mt-0.5 text-[20px] text-[var(--color-accent)]"+ aria-hidden="true"+ >+ {icon}+ </span>+ <div className="flex-1 min-w-0">+ <p className="text-sm text-[var(--color-text-main)] truncate" title={phrase}>+ {phrase}+ </p>+ {target && (+ <p className="text-xs text-[var(--color-text-muted)] truncate mt-0.5">{target}</p>+ )}+ </div>+ <time+ dateTime={timestamp}+ className="flex-shrink-0 text-xs text-[var(--color-text-muted)] whitespace-nowrap mt-0.5"+ title={timestamp}+ >+ {timeAgo}+ </time>+ </li>+ );+}diff --git a/src/app/(dashboard)/dashboard/activity/components/DayHeader.tsx b/src/app/(dashboard)/dashboard/activity/components/DayHeader.tsxnew file mode 100644index 0000000000..85f5e6d0bf--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/components/DayHeader.tsx@@ -0,0 +1,34 @@+"use client";++import { useTranslations } from "next-intl";++interface DayHeaderProps {+ label: string;+ dayKey: string;+}++export default function DayHeader({ label, dayKey }: DayHeaderProps) {+ const t = useTranslations("activity");++ const displayLabel =+ label === "today"+ ? t("todayHeader")+ : label === "yesterday"+ ? t("yesterdayHeader")+ : label;++ return (+ <div+ className="sticky top-0 z-10 flex items-center gap-3 py-2 px-4 bg-[var(--color-bg)] border-b border-[var(--color-border)]"+ aria-label={displayLabel}+ >+ <span className="text-xs font-semibold uppercase tracking-widest text-[var(--color-text-muted)]">+ {displayLabel}+ </span>+ {label !== "today" && label !== "yesterday" && (+ <span className="text-xs text-[var(--color-text-muted)] opacity-60">{dayKey}</span>+ )}+ <div className="flex-1 h-px bg-[var(--color-border)]" />+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/activity/components/EventTypeFilter.tsx b/src/app/(dashboard)/dashboard/activity/components/EventTypeFilter.tsxnew file mode 100644index 0000000000..080e3ae36b--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/components/EventTypeFilter.tsx@@ -0,0 +1,86 @@+"use client";++import { useTranslations } from "next-intl";++export type EventCategory =+ | "all"+ | "providers"+ | "combos"+ | "apikeys"+ | "settings"+ | "quota"+ | "auth"+ | "system";++interface EventTypeFilterProps {+ value: EventCategory;+ onChange: (category: EventCategory) => void;+}++const CATEGORIES: EventCategory[] = [+ "all",+ "providers",+ "combos",+ "apikeys",+ "settings",+ "quota",+ "auth",+ "system",+];++const CATEGORY_PREFIXES: Record<EventCategory, string[]> = {+ all: [],+ providers: ["provider."],+ combos: ["combo."],+ apikeys: ["apikey."],+ settings: ["setting."],+ quota: ["quota.", "budget."],+ auth: ["auth."],+ system: ["update.", "deploy.", "skill.", "cloud_agent.", "mcp.", "webhook."],+};++export function matchesCategory(action: string, category: EventCategory): boolean {+ if (category === "all") return true;+ const prefixes = CATEGORY_PREFIXES[category];+ return prefixes.some((prefix) => action.startsWith(prefix));+}++export default function EventTypeFilter({ value, onChange }: EventTypeFilterProps) {+ const t = useTranslations("activity");++ const labelKey: Record<EventCategory, string> = {+ all: "filterAll",+ providers: "filterProviders",+ combos: "filterCombos",+ apikeys: "filterApiKeys",+ settings: "filterSettings",+ quota: "filterQuota",+ auth: "filterAuth",+ system: "filterSystem",+ };++ return (+ <div+ className="flex flex-wrap gap-2"+ role="group"+ aria-label="Filter by event type"+ >+ {CATEGORIES.map((cat) => (+ <button+ key={cat}+ type="button"+ onClick={() => onChange(cat)}+ aria-pressed={value === cat}+ className={[+ "px-3 py-1 rounded-full text-xs font-medium border transition-colors",+ value === cat+ ? "bg-[var(--color-accent)] text-white border-[var(--color-accent)]"+ : "bg-[var(--color-surface)] text-[var(--color-text-muted)] border-[var(--color-border)] hover:bg-[var(--color-bg-alt)]",+ ].join(" ")}+ >+ {t(labelKey[cat])}+ </button>+ ))}+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/activity/page.tsx b/src/app/(dashboard)/dashboard/activity/page.tsxnew file mode 100644index 0000000000..849fc3f642--- /dev/null+++ b/src/app/(dashboard)/dashboard/activity/page.tsx@@ -0,0 +1,7 @@+import ActivityFeedClient from "./ActivityFeedClient";++export const dynamic = "force-dynamic";++export default function ActivityPage() {+ return <ActivityFeedClient />;+}