feat(session): 重构会话管理和Redis缓存机制

This commit is contained in:
2026-06-09 14:00:01 +08:00
parent 1f9a2b9b5f
commit 9410199fbe
8 changed files with 324 additions and 196 deletions

View File

@@ -2,13 +2,49 @@ package dto
import "github.com/gogf/gf/v2/frame/g"
// SessionCallbackReq 会话回调请求
type SessionCallbackReq struct {
g.Meta `path:"/sessionCallback" method:"post" tags:"提示词处理"`
g.Meta `path:"/callback" method:"post" tags:"会话管理" summary:"会话回调"`
Messages map[string]any `json:"messages" dc:"消息数组"`
EpicycleId int64 `json:"epicycleId" dc:"轮次ID"`
}
// SessionCallbackRes 会话回调响应
type SessionCallbackRes struct {
Status bool `json:"status" dc:"状态"`
SessionId string `json:"sessionId" dc:"会话ID"`
}
// GetHistoryMessagesReq 获取历史消息请求
type GetHistoryMessagesReq struct {
g.Meta `path:"/history" method:"get" tags:"会话管理" summary:"获取历史消息"`
SessionId string `json:"sessionId" v:"required" dc:"会话ID"`
NodeId string `json:"nodeId" dc:"节点ID"`
}
// GetHistoryMessagesRes 获取历史消息响应
type GetHistoryMessagesRes struct {
Messages []HistoryRound `json:"messages" dc:"历史消息列表"`
}
// HistoryRound 一轮对话
type HistoryRound struct {
Id int64 `json:"id" dc:"记录ID"`
User map[string]any `json:"user" dc:"用户消息"`
Assistant map[string]any `json:"assistant" dc:"助手回复"`
CreatedAt string `json:"createdAt" dc:"创建时间"`
}
// DeleteSessionReq 删除会话请求
type DeleteSessionReq struct {
g.Meta `path:"/delete" method:"post" tags:"会话管理" summary:"删除会话"`
TenantId uint64 `json:"tenantId" dc:"租户ID"`
SessionId string `json:"sessionId" v:"required" dc:"会话ID"`
NodeId string `json:"nodeId" dc:"节点ID"`
MsgIds []int64 `json:"msgIds" dc:"消息ID列表传则删单条不传删整个会话"`
}
// DeleteSessionRes 删除会话响应
type DeleteSessionRes struct {
Ok bool `json:"ok" dc:"是否成功"`
}