Files
ai-portal/app/api/admin/agents/[id]/route.ts
T
root 362c37fb42 feat: enhance agent system with hot/quick questions, dynamic chat UI, and new enterprise agents
- Add hotQuestions and quickQuestions fields to agent model
- Update admin form with textarea inputs for hot/quick questions
- Make chat page display dynamic agent data (name, icon, questions)
- Widen center chat area to 60% for better readability
- Add enterprise service category and 3 new agents (jiaotou, promotion, group-policy)
- Update Prisma schema formatting and seed data
2026-05-07 22:14:43 +08:00

48 lines
1.3 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { prisma } from "@//app/lib/prisma"
// 更新智能体
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params
const data = await request.json()
const agent = await prisma.agent.update({
where: { id: parseInt(id) },
data: {
name: data.name,
slug: data.slug,
description: data.description,
icon: data.icon || null,
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
features: data.features || "",
hotQuestions: data.hotQuestions || "[]",
quickQuestions: data.quickQuestions || "[]",
status: data.status || "active",
},
})
return NextResponse.json(agent)
} catch (error) {
console.error('PUT /api/admin/agents error:', error)
return NextResponse.json({ error: "更新失败" }, { status: 500 })
}
}
// 删除智能体
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params
await prisma.agent.delete({
where: { id: parseInt(id) },
})
return NextResponse.json({ success: true })
} catch (error) {
return NextResponse.json({ error: "删除失败" }, { status: 500 })
}
}