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
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
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);
|
||
});
|
||
}
|
||
|