Update application code and dependencies

This commit is contained in:
root
2026-05-06 17:22:50 +08:00
parent efc8f4bf78
commit a3ee04379d
60 changed files with 6793 additions and 860 deletions
@@ -0,0 +1,30 @@
import { prisma } from "@/app/lib/prisma"
import { NextResponse } from "next/server"
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const body = await request.json()
const { role, content } = body
if (!role || !content) {
return NextResponse.json({ error: "role and content are required" }, { status: 400 })
}
const message = await prisma.message.create({
data: {
conversationId: parseInt(id),
role,
content,
},
})
await prisma.conversation.update({
where: { id: parseInt(id) },
data: { updatedAt: new Date() },
})
return NextResponse.json(message)
}
+37
View File
@@ -0,0 +1,37 @@
import { prisma } from "@/app/lib/prisma"
import { NextResponse } from "next/server"
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const conversation = await prisma.conversation.findUnique({
where: { id: parseInt(id) },
include: {
messages: {
orderBy: { timestamp: "asc" },
},
},
})
if (!conversation) {
return NextResponse.json({ error: "Conversation not found" }, { status: 404 })
}
return NextResponse.json(conversation)
}
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
await prisma.conversation.delete({
where: { id: parseInt(id) },
})
return NextResponse.json({ success: true })
}
+42
View File
@@ -0,0 +1,42 @@
import { prisma } from "@/app/lib/prisma"
import { NextResponse } from "next/server"
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const agentId = searchParams.get("agentId")
if (!agentId) {
return NextResponse.json({ error: "agentId is required" }, { status: 400 })
}
const conversations = await prisma.conversation.findMany({
where: { agentId: parseInt(agentId) },
orderBy: { updatedAt: "desc" },
include: {
messages: {
orderBy: { timestamp: "asc" },
take: 1,
},
},
})
return NextResponse.json(conversations)
}
export async function POST(request: Request) {
const body = await request.json()
const { agentId, title } = body
if (!agentId) {
return NextResponse.json({ error: "agentId is required" }, { status: 400 })
}
const conversation = await prisma.conversation.create({
data: {
agentId: parseInt(agentId),
title: title || "新对话",
},
})
return NextResponse.json(conversation)
}