Files
root f2d7037ca2 feat: add save feedback prompts, featured agent fields, dynamic Dify API config, and chat improvements
- Add success/error feedback messages near submit buttons in all admin forms
- Display success prompt for 1s before redirect after save
- Show API error details on save failure
- Add isFeatured/featuredOrder fields to Agent model and admin UI
- Add difyApiUrl/difyApiKey fields for per-agent Dify API configuration
- Show featured badge column in agent admin list
- Display featured agents on homepage sorted by order
- Refactor chat page streaming with AbortController and stable userId
- Improve Dify API proxy to use per-agent credentials
2026-05-08 20:15:54 +08:00

110 lines
4.7 KiB
TypeScript
Raw Permalink 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-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">
{agent.isFeatured ? (
<span className="inline-flex px-2 py-1 text-xs font-medium rounded-full bg-orange-100 text-orange-700">
</span>
) : (
<span className="text-sm text-gray-400">-</span>
)}
</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>
)
}