package memory import ( "encoding/json" "time" ) type Session struct { ID int64 `json:"id"` UUID string `json:"uuid"` Summary string `json:"summary"` SummaryEmbedding []byte `json:"-"` ChatIDs []int64 `json:"chat_ids"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } type Chat struct { ID int64 `json:"id"` SessionID int64 `json:"session_id"` UserInput string `json:"user_input"` AIReplies []string `json:"ai_replies"` Summary string `json:"summary"` SummaryEmbedding []byte `json:"-"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func NewSession(uuid string) *Session { now := time.Now().Unix() return &Session{ UUID: uuid, ChatIDs: []int64{}, CreatedAt: now, UpdatedAt: now, } } func NewChat(sessionID int64, userInput string) *Chat { now := time.Now().Unix() return &Chat{ SessionID: sessionID, UserInput: userInput, AIReplies: []string{}, CreatedAt: now, UpdatedAt: now, } } func (s *Session) AddChatID(chatID int64) { s.ChatIDs = append(s.ChatIDs, chatID) s.UpdatedAt = time.Now().Unix() } func (s *Session) GetChatIDsJSON() (string, error) { data, err := json.Marshal(s.ChatIDs) if err != nil { return "", err } return string(data), nil } func (s *Session) SetChatIDsFromJSON(data string) error { if data == "" { s.ChatIDs = []int64{} return nil } return json.Unmarshal([]byte(data), &s.ChatIDs) } func (c *Chat) AddAIReply(reply string) { c.AIReplies = append(c.AIReplies, reply) c.UpdatedAt = time.Now().Unix() } func (c *Chat) GetAIRepliesJSON() (string, error) { data, err := json.Marshal(c.AIReplies) if err != nil { return "", err } return string(data), nil } func (c *Chat) SetAIRepliesFromJSON(data string) error { if data == "" { c.AIReplies = []string{} return nil } return json.Unmarshal([]byte(data), &c.AIReplies) } func GenerateSummary(userInput, aiReply string) string { fullText := userInput + "\n" + aiReply if len(fullText) > 200 { fullText = fullText[:200] } return fullText }