Files
X-Agents/server/internal/model/chat_session.go

72 lines
2.3 KiB
Go
Raw Normal View History

package model
import "time"
// ChatSession 会话
type ChatSession struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
UserID string `json:"user_id" gorm:"type:varchar(36);index"`
AgentID string `json:"agent_id" gorm:"type:varchar(36);index"`
Title string `json:"title" gorm:"type:varchar(255)"`
ModelID string `json:"model_id" gorm:"type:varchar(36)"`
Status string `json:"status" gorm:"type:varchar(20);default:'active'"` // active/archived
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (ChatSession) TableName() string {
return "chat_sessions"
}
// ChatMessage 消息
type ChatMessage struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
SessionID string `json:"session_id" gorm:"type:varchar(36);index"`
Role string `json:"role" gorm:"type:varchar(20)"` // user/assistant/system
Content string `json:"content" gorm:"type:text"`
TokensUsed int `json:"tokens_used" gorm:"default:0"`
DurationMs int `json:"duration_ms" gorm:"default:0"`
Metadata string `json:"metadata" gorm:"type:text"` // JSON格式存储额外信息
CreatedAt time.Time `json:"created_at"`
}
func (ChatMessage) TableName() string {
return "chat_messages"
}
// CreateSessionRequest 创建会话请求
type CreateSessionRequest struct {
UserID string `json:"user_id"`
AgentID string `json:"agent_id"`
Title string `json:"title"`
ModelID string `json:"model_id"`
}
// UpdateSessionRequest 更新会话请求
type UpdateSessionRequest struct {
Title string `json:"title"`
Status string `json:"status"`
}
// CreateMessageRequest 创建消息请求
type CreateMessageRequest struct {
SessionID string `json:"session_id" binding:"required"`
Role string `json:"role" binding:"required"` // user/assistant
Content string `json:"content"`
TokensUsed int `json:"tokens_used"`
DurationMs int `json:"duration_ms"`
Metadata string `json:"metadata"`
}
// SessionListResponse 会话列表响应
type SessionListResponse struct {
List []ChatSession `json:"list"`
Total int64 `json:"total"`
}
// MessageListResponse 消息列表响应
type MessageListResponse struct {
List []ChatMessage `json:"list"`
Total int64 `json:"total"`
}