feat(session): 重构会话管理和消息存储功能

This commit is contained in:
2026-06-09 15:46:09 +08:00
parent 9410199fbe
commit 78114f99c7
8 changed files with 221 additions and 203 deletions

View File

@@ -66,5 +66,5 @@ type GetPromptTextReq struct {
}
type GetPromptTextRes struct {
Messages any `json:"messages" dc:"最终消息数组"`
Messages any `json:"messages" dc:"历史消息"`
}

View File

@@ -2,11 +2,22 @@ package dto
import "github.com/gogf/gf/v2/frame/g"
// HistoryRound 一轮对话
type HistoryRound struct {
Id int64 `json:"id" dc:"记录ID"`
SessionId string `json:"sessionId" dc:"会话ID"`
NodeId string `json:"nodeId" dc:"节点ID"`
User map[string]any `json:"user" dc:"用户消息"`
Assistant map[string]any `json:"assistant" dc:"助手回复"`
CreatedAt string `json:"createdAt" dc:"创建时间"`
UpdatedAt string `json:"updatedAt" dc:"更新时间"`
}
// SessionCallbackReq 会话回调请求
type SessionCallbackReq struct {
g.Meta `path:"/callback" method:"post" tags:"会话管理" summary:"会话回调"`
Messages map[string]any `json:"messages" dc:"消息数组"`
EpicycleId int64 `json:"epicycleId" dc:"轮次ID"`
Messages map[string]any `json:"messages" v:"required" dc:"消息数组"`
EpicycleId int64 `json:"epicycleId" v:"required" dc:"轮次ID"`
}
// SessionCallbackRes 会话回调响应
@@ -15,36 +26,55 @@ type SessionCallbackRes struct {
SessionId string `json:"sessionId" dc:"会话ID"`
}
// GetHistoryMessagesReq 获取历史消息请求
// GetHistoryListReq 获取历史列表请求(前端)
type GetHistoryListReq struct {
g.Meta `path:"/historyList" method:"get" tags:"会话管理" summary:"获取历史列表"`
Page int `json:"page" d:"1" dc:"页码"`
Size int `json:"size" d:"10" dc:"每页条数"`
}
// GetHistoryListRes 获取历史列表响应
type GetHistoryListRes struct {
List []HistoryRound `json:"list" dc:"历史列表"`
Total int `json:"total" dc:"总数"`
}
// GetHistoryMessagesReq 获取历史消息请求(提示词拼接)
type GetHistoryMessagesReq struct {
g.Meta `path:"/history" method:"get" tags:"会话管理" summary:"获取历史消息"`
g.Meta `path:"/historyMessages" 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:"历史消息列表"`
Messages []FlatMessage `json:"messages"`
}
// 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:"创建时间"`
type FlatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
// DeleteSessionReq 删除会话请求
type DeleteSessionReq struct {
g.Meta `path:"/delete" method:"post" tags:"会话管理" summary:"删除会话"`
TenantId uint64 `json:"tenantId" dc:"租户ID"`
// DeleteMessagesReq 批量删除消息请求
type DeleteMessagesReq struct {
g.Meta `path:"/deleteMessages" method:"post" tags:"会话管理" summary:"批量删除消息"`
SessionId string `json:"sessionId" v:"required" dc:"会话ID"`
NodeId string `json:"nodeId" dc:"节点ID"`
MsgIds []int64 `json:"msgIds" dc:"消息ID列表传则删单条不传删整个会话"`
MsgIds []int64 `json:"msgIds" v:"required" dc:"消息ID列表"`
}
// DeleteSessionRes 删除会话响应
// DeleteMessagesRes 批量删除消息响应
type DeleteMessagesRes struct {
Ok bool `json:"ok" dc:"是否成功"`
}
// DeleteSessionReq 删除整个会话请求
type DeleteSessionReq struct {
g.Meta `path:"/deleteSession" method:"post" tags:"会话管理" summary:"删除整个会话"`
SessionId string `json:"sessionId" v:"required" dc:"会话ID"`
}
// DeleteSessionRes 删除整个会话响应
type DeleteSessionRes struct {
Ok bool `json:"ok" dc:"是否成功"`
}