Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 33s
- ChatSession/ChatMessage/ChatCitation Prisma models - CAPI: create/list sessions, send message, get history, delete - Admin AAPI: view user sessions and messages - Content safety integration on user input - Placeholder RAG pipeline (real pipeline in M3) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
|
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
|
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
|
|
import { AdminRoles } from '../../common/decorators/admin-roles.decorator';
|
|
import type { AdminRole } from '../../common/types/admin-role.enum';
|
|
|
|
@ApiTags('admin-rag-chat')
|
|
@Controller('admin-api/rag-chat')
|
|
@UseGuards(AdminAuthGuard, AdminRolesGuard)
|
|
@ApiBearerAuth()
|
|
export class AdminRagChatController {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
@Get('sessions')
|
|
@AdminRoles('ADMIN' as AdminRole)
|
|
@ApiOperation({ summary: '用户对话列表' })
|
|
async sessions(@Query('userId') userId?: string) {
|
|
return this.prisma.chatSession.findMany({
|
|
where: userId ? { userId } : undefined,
|
|
orderBy: { updatedAt: 'desc' },
|
|
take: 100,
|
|
include: { _count: { select: { messages: true } } },
|
|
});
|
|
}
|
|
|
|
@Get('sessions/:id/messages')
|
|
@AdminRoles('ADMIN' as AdminRole)
|
|
@ApiOperation({ summary: '对话消息详情' })
|
|
async messages(@Param('id') id: string) {
|
|
return this.prisma.chatMessage.findMany({
|
|
where: { sessionId: id },
|
|
orderBy: { createdAt: 'asc' },
|
|
include: { citations: true },
|
|
});
|
|
}
|
|
}
|