Files
ai-portal/app/admin/agents/page.tsx
T
2026-05-06 17:22:50 +08:00

100 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { getServerSession } from "next-auth/next"
import { redirect } from "next/navigation"
import { prisma } from "@//app/lib/prisma"
import Link from "next/link"
import DeleteButton from "./DeleteButton"
export default async function AdminAgentsPage() {
const session = await getServerSession()
if (!session) {
redirect("/admin/login")
}
const agents = await prisma.agent.findMany({
include: { category: true },
orderBy: { createdAt: "desc" },
})
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white border-b border-gray-200">
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
<h1 className="text-xl font-bold text-gray-900"></h1>
<div className="flex items-center gap-4">
<Link href="/admin" className="text-sm text-gray-600 hover:text-gray-900">
</Link>
<Link href="/admin/agents/new" className="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-blue-700">
</Link>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-6 py-8">
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase"></th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">使</th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase"></th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{agents.map((agent) => (
<tr key={agent.id} className="hover:bg-gray-50">
<td className="px-6 py-4">
<div className="flex items-center gap-3">
<span className="text-2xl">{agent.icon || "🤖"}</span>
<div>
<div className="font-medium text-gray-900">{agent.name}</div>
<div className="text-sm text-gray-500">{agent.slug}</div>
</div>
</div>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{agent.category?.name || "-"}
</td>
<td className="px-6 py-4">
<span className={`inline-flex px-2 py-1 text-xs font-medium rounded-full ${
agent.status === "active"
? "bg-green-100 text-green-700"
: "bg-gray-100 text-gray-700"
}`}>
{agent.status === "active" ? "运行中" : agent.status}
</span>
</td>
<td className="px-6 py-4 text-sm text-gray-600">
{agent.usageCount}
</td>
<td className="px-6 py-4 text-right">
<div className="flex items-center justify-end gap-2">
<Link
href={`/admin/agents/${agent.id}/edit`}
className="text-blue-600 hover:text-blue-700 text-sm"
>
</Link>
<DeleteButton id={agent.id} />
</div>
</td>
</tr>
))}
</tbody>
</table>
{agents.length === 0 && (
<div className="text-center py-12 text-gray-500">
<Link href="/admin/agents/new" className="text-blue-600"></Link>
</div>
)}
</div>
</main>
</div>
)
}