feat: Day 10-11 - Agent Configuration System completed
Backend: - Create agents.yaml config file with 12 agents definition - Create Prompt templates for topic-evaluation agent - Implement agentService.ts for loading and managing agent configs - Create agentController.ts with CRUD operations - Create agent routes (GET /agents, /agents/:id, etc.) - Register agent routes in main server Frontend: - Create agentApi.ts service module - Update AgentChatPage to dynamically load agent config from API - Add loading state and error handling - Display agent details (description, category, model) Build: Both frontend and backend build successfully
This commit is contained in:
56
backend/src/routes/agents.ts
Normal file
56
backend/src/routes/agents.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
||||
import { agentController } from '../controllers/agentController.js';
|
||||
|
||||
interface AgentParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export async function agentRoutes(fastify: FastifyInstance) {
|
||||
// 获取所有智能体列表
|
||||
fastify.get('/agents', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return agentController.getAllAgents(request, reply);
|
||||
});
|
||||
|
||||
// 获取启用的智能体列表
|
||||
fastify.get('/agents/enabled', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return agentController.getEnabledAgents(request, reply);
|
||||
});
|
||||
|
||||
// 根据分类获取智能体
|
||||
fastify.get<{ Querystring: { category: string } }>(
|
||||
'/agents/by-category',
|
||||
async (request: FastifyRequest<{ Querystring: { category: string } }>, reply: FastifyReply) => {
|
||||
return agentController.getAgentsByCategory(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 获取单个智能体详情
|
||||
fastify.get<{ Params: AgentParams }>(
|
||||
'/agents/:id',
|
||||
async (request: FastifyRequest<{ Params: AgentParams }>, reply: FastifyReply) => {
|
||||
return agentController.getAgentById(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 获取智能体的系统Prompt
|
||||
fastify.get<{ Params: AgentParams }>(
|
||||
'/agents/:id/system-prompt',
|
||||
async (request: FastifyRequest<{ Params: AgentParams }>, reply: FastifyReply) => {
|
||||
return agentController.getSystemPrompt(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 渲染用户Prompt(预览)
|
||||
fastify.post<{ Params: AgentParams }>(
|
||||
'/agents/:id/render-prompt',
|
||||
async (request: FastifyRequest<{ Params: AgentParams }>, reply: FastifyReply) => {
|
||||
return agentController.renderPrompt(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 重新加载配置(管理员功能)
|
||||
fastify.post('/agents/reload-config', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return agentController.reloadConfig(request, reply);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user