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:
@@ -243,3 +243,103 @@ func (h *AgentHandler) ListAgents(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// UpdateAgentStatusRequest 更新状态请求
|
||||
type UpdateAgentStatusRequest struct {
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
// UpdateAgentStatus 更新智能体状态
|
||||
// @Summary 更新智能体状态
|
||||
// @Tags 智能体管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Agent ID"
|
||||
// @Param request body UpdateAgentStatusRequest true "状态请求"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Router /api/agent/{id}/status [put]
|
||||
func (h *AgentHandler) UpdateAgentStatus(c *gin.Context) {
|
||||
agentID := c.Param("id")
|
||||
if agentID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "agent id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
var req UpdateAgentStatusRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.agentService.UpdateAgentStatus(agentID, req.IsActive)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "status updated successfully"})
|
||||
}
|
||||
|
||||
// DeleteAgent 删除智能体
|
||||
// @Summary 删除智能体
|
||||
// @Tags 智能体管理
|
||||
// @Produce json
|
||||
// @Param id path string true "Agent ID"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Router /api/agent/{id} [delete]
|
||||
func (h *AgentHandler) DeleteAgent(c *gin.Context) {
|
||||
agentID := c.Param("id")
|
||||
if agentID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "agent id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.agentService.DeleteAgent(agentID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "agent deleted successfully"})
|
||||
}
|
||||
|
||||
// UpdateAgentRequest 更新智能体请求
|
||||
type UpdateAgentRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Skills []string `json:"skills"`
|
||||
RoleDescription string `json:"role_description"`
|
||||
ModelProvider string `json:"model_provider"`
|
||||
ModelName string `json:"model_name"`
|
||||
}
|
||||
|
||||
// UpdateAgent 更新智能体
|
||||
// @Summary 更新智能体
|
||||
// @Tags 智能体管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Agent ID"
|
||||
// @Param request body UpdateAgentRequest true "更新请求"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Router /api/agent/{id} [put]
|
||||
func (h *AgentHandler) UpdateAgent(c *gin.Context) {
|
||||
agentID := c.Param("id")
|
||||
if agentID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "agent id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
var req UpdateAgentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.agentService.UpdateAgent(agentID, req.Name, req.Description, req.Skills, req.RoleDescription, req.ModelProvider, req.ModelName)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "agent updated successfully"})
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ func (h *SkillHandler) Create(c *gin.Context) {
|
||||
SkillType: skillType,
|
||||
SkillDesc: skillDesc,
|
||||
Path: filepath.Join(skillPath, "SKILL.md"),
|
||||
Status: "active",
|
||||
Status: 1,
|
||||
}
|
||||
|
||||
// 记录创建者
|
||||
@@ -386,7 +386,7 @@ func (h *SkillHandler) Update(c *gin.Context) {
|
||||
skillName := req.SkillName
|
||||
skillDesc := req.SkillDesc
|
||||
skillType := req.SkillType
|
||||
status := req.Status
|
||||
var status int
|
||||
|
||||
if skillName == "" {
|
||||
skillName = existingSkill.SkillName
|
||||
@@ -397,8 +397,18 @@ func (h *SkillHandler) Update(c *gin.Context) {
|
||||
if skillType == "" {
|
||||
skillType = existingSkill.SkillType
|
||||
}
|
||||
if status == "" {
|
||||
// 处理 status:如果是空字符串则使用现有值,否则转换为整数
|
||||
if req.Status == "" {
|
||||
status = existingSkill.Status
|
||||
} else {
|
||||
// 支持传入数字或字符串
|
||||
if req.Status == "1" || req.Status == "active" {
|
||||
status = 1
|
||||
} else if req.Status == "0" || req.Status == "inactive" {
|
||||
status = 0
|
||||
} else {
|
||||
status = existingSkill.Status
|
||||
}
|
||||
}
|
||||
|
||||
// 获取项目根目录
|
||||
|
||||
Reference in New Issue
Block a user