feat(gateway): 修改会话历史接口路径并增加租户隔离

This commit is contained in:
WangLiZhao
2026-07-06 15:12:49 +08:00
parent 85f4c70ae8
commit c5e3450c79
3 changed files with 65 additions and 1 deletions
+5
View File
@@ -25,6 +25,11 @@ func (c *session) GetHistoryList(ctx context.Context, req *dto.GetHistoryListReq
return sessionService.GetHistoryList(ctx, req)
}
// GetSessionHistory 获取会话历史(服务调用)
func (c *session) GetSessionHistory(ctx context.Context, req *dto.GetSessionHistoryReq) (res *dto.GetSessionHistoryRes, err error) {
return sessionService.GetSessionHistory(ctx, req)
}
// DeleteMessages 批量删除消息
func (c *session) DeleteMessages(ctx context.Context, req *dto.DeleteMessagesReq) (res *dto.DeleteMessagesRes, err error) {
return sessionService.DeleteMessages(ctx, req)
+16
View File
@@ -43,6 +43,22 @@ type GetHistoryListRes struct {
Total int `json:"total" dc:"总数"`
}
type GetSessionHistoryReq struct {
g.Meta `path:"/sessionHistory" method:"get" tags:"会话管理" summary:"获取会话历史"`
SessionId string `json:"sessionId" v:"required#sessionId不能为空" dc:"会话ID"`
NodeId string `json:"nodeId" dc:"节点ID"`
Size int `json:"size" d:"50" dc:"条数"`
}
type GetSessionHistoryRes struct {
List []SessionHistoryItem `json:"list" dc:"历史消息列表"`
}
type SessionHistoryItem struct {
Role string `json:"role" dc:"角色:user/assistant"`
Content string `json:"content" dc:"消息内容"`
}
// GetHistoryMessagesReq 获取历史消息请求(提示词拼接)
type GetHistoryMessagesReq struct {
g.Meta `path:"/historyMessages" method:"get" tags:"会话管理" summary:"获取历史消息"`
+44 -1
View File
@@ -85,7 +85,10 @@ func GetHistoryList(ctx context.Context, req *dto.GetHistoryListReq) (*dto.GetHi
return nil, err
}
sessions, total, err := dao.ComposeSession.List(ctx, &entity.ComposeSession{
SQLBaseDO: beans.SQLBaseDO{Creator: user.UserName},
SQLBaseDO: beans.SQLBaseDO{
TenantId: user.TenantId,
Creator: user.UserName,
},
}, req.Page, req.Size)
if err != nil {
return nil, fmt.Errorf("DB获取历史列表失败: %w", err)
@@ -94,6 +97,46 @@ func GetHistoryList(ctx context.Context, req *dto.GetHistoryListReq) (*dto.GetHi
return &dto.GetHistoryListRes{List: rounds, Total: total}, nil
}
// GetSessionHistory 获取会话历史
func GetSessionHistory(ctx context.Context, req *dto.GetSessionHistoryReq) (*dto.GetSessionHistoryRes, error) {
user, err := utils.GetUserInfo(ctx)
if err != nil {
return nil, err
}
sessions, _, err := dao.ComposeSession.List(ctx, &entity.ComposeSession{
SQLBaseDO: beans.SQLBaseDO{
TenantId: user.TenantId,
Creator: user.UserName,
},
SessionId: req.SessionId,
NodeId: req.NodeId,
}, 1, req.Size)
if err != nil {
return nil, fmt.Errorf("DB获取历史失败: %w", err)
}
var items []dto.SessionHistoryItem
for _, s := range sessions {
// 提取 user 消息
if userMsg := util.ExtractUserText(s.RequestContent); userMsg != nil {
items = append(items, dto.SessionHistoryItem{
Role: "user",
Content: gconv.String(userMsg["content"]),
})
}
// 提取 assistant 消息
if s.ResponseContent != nil {
items = append(items, dto.SessionHistoryItem{
Role: "assistant",
Content: gconv.String(s.ResponseContent["content"]),
})
}
}
return &dto.GetSessionHistoryRes{List: items}, nil
}
// ============================================
// 场景2:提示词拼接(按 sessionId + nodeId
// ============================================