feat: 支付闭环 + 运营助手 Tool Calling + 管理后台完善
- 支付系统:微信支付 mock 自动完成、NATIVE 扫码支付、JSAPI 集成 - 运营助手:Tool Calling 架构,19 个可执行工具,AI 驱动操作 - 角色管理:表格布局 + Dialog 表单 + 权限勾选 - 配置统一:config.ts 单一数据源 - API 审计:补齐 status toggle / comments 端点 - 暗黑模式硬件编码颜色全部替换为 CSS 变量
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { Controller, Post, Get, Put, Body, UseGuards, Req, Param } from '@nestjs/common';
|
||||
import { Controller, Post, Get, Put, Body, UseGuards, Req, Param, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { AdminService } from './admin.service';
|
||||
import { AdminGuard } from './admin.guard';
|
||||
import { CoursesService } from '../courses/courses.service';
|
||||
import { PrismaService } from '../../prisma/prisma.service';
|
||||
import { AIGatewayService } from '../ai/ai-gateway.service';
|
||||
import { AdminAiAssistantService } from './ai-assistant.service';
|
||||
|
||||
@ApiTags('管理后台')
|
||||
@Controller('admin')
|
||||
@@ -13,6 +15,8 @@ export class AdminController {
|
||||
private adminService: AdminService,
|
||||
private coursesService: CoursesService,
|
||||
private prisma: PrismaService,
|
||||
private aiGateway: AIGatewayService,
|
||||
private aiAssistant: AdminAiAssistantService,
|
||||
) {}
|
||||
|
||||
@Post('login')
|
||||
@@ -83,4 +87,36 @@ export class AdminController {
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@Post('ai-assistant/chat')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async aiAssistantChat(@Body() body: { messages: { role: string; content: string }[] }) {
|
||||
try {
|
||||
const { messages } = body;
|
||||
const apiMessages = messages.map(m => ({ role: m.role as 'user' | 'assistant' | 'system', content: m.content }));
|
||||
const reply = await this.aiGateway.chat('general', apiMessages, { temperature: 0.7, max_tokens: 2000 });
|
||||
return { reply };
|
||||
} catch (err: any) {
|
||||
throw new HttpException(err.message || 'AI 助手请求失败', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('ai-assistant/action')
|
||||
@UseGuards(AuthGuard('jwt'), AdminGuard)
|
||||
@ApiBearerAuth()
|
||||
async aiAssistantAction(@Body() body: { tool: string; params: Record<string, any>; messages: { role: string; content: string }[] }) {
|
||||
const result = await this.aiAssistant.execute({ tool: body.tool, params: body.params });
|
||||
try {
|
||||
const apiMessages = [
|
||||
{ role: 'system' as const, content: '你是一个管理后台助手。下面是对用户请求的执行结果,请用自然语言总结给用户,语言简洁。' },
|
||||
...body.messages.map(m => ({ role: m.role as 'user' | 'assistant', content: m.content })),
|
||||
{ role: 'assistant' as const, content: `【工具执行结果】\n工具: ${body.tool}\n参数: ${JSON.stringify(body.params)}\n结果: ${result.summary}\n数据: ${JSON.stringify(result.data)}` },
|
||||
];
|
||||
const reply = await this.aiGateway.chat('general', apiMessages, { temperature: 0.3, max_tokens: 1000 });
|
||||
return { reply, result };
|
||||
} catch {
|
||||
return { reply: result.summary, result };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user