feat: 更新后端服务

- agent_handler.go: 新增agent管理接口
- agent_service.go: 扩展agent服务逻辑
- skill_handler.go: 更新skill接口
- chat_service.go: 更新chat服务
- model相关: 新增model仓库和服务
- main.go: 更新路由配置

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 23:18:46 +08:00
parent 5b50d6ff9a
commit 5dc2e403e9
11 changed files with 335 additions and 109 deletions

View File

@@ -147,7 +147,28 @@ func main() {
}
// 3. 自动迁移表
db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{}, &model.ModelInfo{}, &model.KnowledgeBase{}, &model.KnowledgeDocument{}, &model.User{}, &model.Role{}, &model.Tool{}, &model.MCP{}, &model.Skill{}, &model.Agent{}, &model.AgentSkill{}, &model.AgentKnowledgeBase{}, &model.AgentMemory{}, &model.AgentTeam{}, &model.AgentTask{})
if err := db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{}, &model.ModelInfo{}, &model.KnowledgeBase{}, &model.KnowledgeDocument{}, &model.User{}, &model.Role{}, &model.Tool{}, &model.MCP{}, &model.Skill{}, &model.Agent{}, &model.AgentSkill{}, &model.AgentKnowledgeBase{}, &model.AgentMemory{}, &model.AgentTeam{}, &model.AgentTask{}).Error; err != nil {
log.Printf("Warning: AutoMigrate error: %v", err)
}
// 3.2 确保 agents 表存在(使用 SQL 强制创建)
db.Exec(`
CREATE TABLE IF NOT EXISTS agents (
id VARCHAR(191) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
owner_id VARCHAR(50) NOT NULL,
INDEX idx_owner_id (owner_id),
skills TEXT,
role_description TEXT,
model_provider VARCHAR(50),
model_name VARCHAR(100),
is_supervisor TINYINT(1) DEFAULT 0,
is_active TINYINT(1) DEFAULT 1,
created_at DATETIME(3),
updated_at DATETIME(3)
)
`)
// 3.1 确保 users 和 roles 表存在(使用 SQL 强制创建)
db.Exec(`
@@ -297,7 +318,7 @@ func main() {
toolService := service.NewToolService(toolRepo)
mcpService := service.NewMCPService(mcpRepo)
skillService := service.NewSkillService(skillRepo)
agentService := service.NewAgentService(cfg.PythonServiceURL, modelRepo)
agentService := service.NewAgentService(cfg.PythonServiceURL, modelRepo, agentRepo)
memoryService := service.NewMemoryService(agentRepo)
// 4.2 初始化默认工具
@@ -502,6 +523,9 @@ func main() {
{
agentGroup.GET("/list", agentHandler.ListAgents)
agentGroup.POST("/create", agentHandler.CreateAgent)
agentGroup.PUT("/:id/status", agentHandler.UpdateAgentStatus)
agentGroup.PUT("/:id", agentHandler.UpdateAgent)
agentGroup.DELETE("/:id", agentHandler.DeleteAgent)
agentGroup.POST("/chat", agentHandler.Chat)
agentGroup.POST("/chat/stream", agentHandler.ChatStream)
agentGroup.POST("/team/chat", agentHandler.TeamChat)