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); }); }