feat: add Timestamp field to Message struct

- Add Timestamp field to Message struct in pkg/providers/types.go
- Automatically set timestamp in AddMessage and AddFullMessage methods in pkg/session/manager.go
- Timestamp is stored as Unix timestamp (int64)
This commit is contained in:
Shingwha 2026-02-18 11:51:28 +08:00
parent 8807d8254f
commit 15beffc98c
2 changed files with 7 additions and 0 deletions

View file

@ -33,6 +33,7 @@ type Message struct {
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
}
type LLMProvider interface {

View file

@ -63,6 +63,7 @@ func (sm *SessionManager) AddMessage(sessionKey, role, content string) {
sm.AddFullMessage(sessionKey, providers.Message{
Role: role,
Content: content,
Timestamp: time.Now().Unix(),
})
}
@ -82,6 +83,11 @@ func (sm *SessionManager) AddFullMessage(sessionKey string, msg providers.Messag
sm.sessions[sessionKey] = session
}
// Set timestamp if not already set
if msg.Timestamp == 0 {
msg.Timestamp = time.Now().Unix()
}
session.Messages = append(session.Messages, msg)
session.Updated = time.Now()
}