feat: 更新 Server 后端服务
- 更新 agent handler 和 service 层 - 新增 chat_group handler 和 service - 删除废弃的 chat_handler - 更新 tool 相关处理 - 更新 API 文档和依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"x-agents/server/internal/service"
|
||||
|
||||
@@ -22,7 +23,7 @@ func NewAgentHandler(agentService *service.AgentService) *AgentHandler {
|
||||
|
||||
// ChatRequest 对话请求
|
||||
type ChatRequest struct {
|
||||
AgentID int `json:"agent_id" binding:"required"`
|
||||
AgentID string `json:"agent_id" binding:"required"` // 字符串类型
|
||||
Message string `json:"message" binding:"required"`
|
||||
SessionID string `json:"session_id"`
|
||||
ModelID string `json:"model_id"`
|
||||
@@ -69,10 +70,14 @@ func (h *AgentHandler) Chat(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 获取用户 ID(从认证中间件获取)
|
||||
userID := 1 // TODO: 从 c.Get("user_id") 获取
|
||||
userIDStr := "1" // TODO: 从 c.Get("user_id") 获取
|
||||
userID, _ := strconv.Atoi(userIDStr)
|
||||
|
||||
// 将前端传来的字符串 agent_id 转换为 int
|
||||
agentID, _ := strconv.Atoi(req.AgentID)
|
||||
|
||||
pythonReq := service.AgentChatRequest{
|
||||
AgentID: req.AgentID,
|
||||
AgentID: agentID,
|
||||
Message: req.Message,
|
||||
UserID: userID,
|
||||
SessionID: req.SessionID,
|
||||
@@ -122,7 +127,11 @@ func (h *AgentHandler) ChatStream(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 获取用户 ID
|
||||
userID := 1 // TODO: 从 c.Get("user_id") 获取
|
||||
userIDStr := "1" // TODO: 从 c.Get("user_id") 获取
|
||||
userID, _ := strconv.Atoi(userIDStr)
|
||||
|
||||
// 将前端传来的字符串 agent_id 转换为 int
|
||||
agentID, _ := strconv.Atoi(req.AgentID)
|
||||
|
||||
// 构建 SSE 流
|
||||
c.Header("Content-Type", "text/event-stream")
|
||||
@@ -131,7 +140,7 @@ func (h *AgentHandler) ChatStream(c *gin.Context) {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
|
||||
// 调用 Python 服务的流式端点
|
||||
err := h.agentService.ChatStream(c, req.AgentID, req.Message, req.SessionID, req.ModelID, userID)
|
||||
err := h.agentService.ChatStream(c, agentID, req.Message, req.SessionID, req.ModelID, userID)
|
||||
if err != nil && !c.IsAborted() {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
}
|
||||
@@ -173,7 +182,8 @@ func (h *AgentHandler) TeamChat(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 获取用户 ID
|
||||
userID := 1 // TODO: 从 c.Get("user_id") 获取
|
||||
userIDStr := "1" // TODO: 从 c.Get("user_id") 获取
|
||||
userID, _ := strconv.Atoi(userIDStr)
|
||||
|
||||
pythonReq := service.TeamChatRequest{
|
||||
SupervisorAgentID: req.SupervisorAgentID,
|
||||
|
||||
Reference in New Issue
Block a user