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

52 lines
1.5 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,
difyApiUrl: data.difyApiUrl || null,
difyApiKey: data.difyApiKey || null,
features: data.features || "",
hotQuestions: data.hotQuestions || "[]",
quickQuestions: data.quickQuestions || "[]",
status: data.status || "active",
isFeatured: data.isFeatured ?? false,
featuredOrder: data.featuredOrder ?? 0,
},
})
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 })
}
}