feat: 增强会话管理和 Agent 服务

- 优化 session_handler 会话处理逻辑
- 增强 agent_service Agent 服务功能
- 新增 chat_repository 仓储方法
- 更新 agent_handler 和 chat_group_handler
- 更新数据模型 agent 和 chat_session

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 19:49:27 +08:00
parent bce8b9240b
commit 31f0feafb5
8 changed files with 146 additions and 30 deletions

View File

@@ -32,7 +32,7 @@ type ChatRequest struct {
// ChatResponse 对话响应
type ChatResponse struct {
AgentID int `json:"agent_id"`
AgentID string `json:"agent_id"` // 支持 UUID 字符串
Reply string `json:"reply"`
ToolsUsed []string `json:"tools_used"`
SessionID string `json:"session_id"`
@@ -73,11 +73,9 @@ func (h *AgentHandler) Chat(c *gin.Context) {
userIDStr := "1" // TODO: 从 c.Get("user_id") 获取
userID, _ := strconv.Atoi(userIDStr)
// 将前端传来的字符串 agent_id 转换为 int
agentID, _ := strconv.Atoi(req.AgentID)
// 直接使用字符串类型的 agent_id,支持 UUID
pythonReq := service.AgentChatRequest{
AgentID: agentID,
AgentID: req.AgentID,
Message: req.Message,
UserID: userID,
SessionID: req.SessionID,
@@ -130,8 +128,8 @@ func (h *AgentHandler) ChatStream(c *gin.Context) {
userIDStr := "1" // TODO: 从 c.Get("user_id") 获取
userID, _ := strconv.Atoi(userIDStr)
// 将前端传来的字符串 agent_id 转换为 int
agentID, _ := strconv.Atoi(req.AgentID)
// 直接使用字符串类型的 agent_id,支持 UUID
agentID := req.AgentID
// 构建 SSE 流
c.Header("Content-Type", "text/event-stream")
@@ -317,6 +315,7 @@ func (h *AgentHandler) DeleteAgent(c *gin.Context) {
type UpdateAgentRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Avatar string `json:"avatar"`
Skills []string `json:"skills"`
RoleDescription string `json:"role_description"`
ModelProvider string `json:"model_provider"`
@@ -345,7 +344,7 @@ func (h *AgentHandler) UpdateAgent(c *gin.Context) {
return
}
err := h.agentService.UpdateAgent(agentID, req.Name, req.Description, req.Skills, req.RoleDescription, req.ModelProvider, req.ModelName)
err := h.agentService.UpdateAgent(agentID, req.Name, req.Description, req.Avatar, req.Skills, req.RoleDescription, req.ModelProvider, req.ModelName)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return