mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-05-25 16:00:35 +00:00
fix(session): normalize CreatedAt in SessionManager AddFullMessage/SetHistory
This commit is contained in:
@@ -105,9 +105,10 @@ func TestTurnProfile_DisabledPreservesDefaultHistoryAndPrompt(t *testing.T) {
|
||||
al := newTurnProfileAgentLoop(t, cfg, provider)
|
||||
agent := al.GetRegistry().GetDefaultAgent()
|
||||
sessionKey := "agent:default:test-default"
|
||||
ts := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
initialHistory := []providers.Message{
|
||||
{Role: "user", Content: "old user"},
|
||||
{Role: "assistant", Content: "old assistant"},
|
||||
{Role: "user", Content: "old user", CreatedAt: &ts},
|
||||
{Role: "assistant", Content: "old assistant", CreatedAt: &ts},
|
||||
}
|
||||
agent.Sessions.SetHistory(sessionKey, initialHistory)
|
||||
agent.Sessions.SetSummary(sessionKey, "old summary")
|
||||
@@ -154,9 +155,10 @@ func TestTurnProfile_HistoryOffSuppressesHistoryAndPersistence(t *testing.T) {
|
||||
al := newTurnProfileAgentLoop(t, cfg, provider)
|
||||
agent := al.GetRegistry().GetDefaultAgent()
|
||||
sessionKey := "agent:default:test-history-off"
|
||||
ts := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
initialHistory := []providers.Message{
|
||||
{Role: "user", Content: "old user"},
|
||||
{Role: "assistant", Content: "old assistant"},
|
||||
{Role: "user", Content: "old user", CreatedAt: &ts},
|
||||
{Role: "assistant", Content: "old assistant", CreatedAt: &ts},
|
||||
}
|
||||
agent.Sessions.SetHistory(sessionKey, initialHistory)
|
||||
agent.Sessions.SetSummary(sessionKey, "old summary")
|
||||
|
||||
+13
-2
@@ -87,8 +87,13 @@ func (sm *SessionManager) AddFullMessage(sessionKey string, msg providers.Messag
|
||||
sm.sessions[sessionKey] = session
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if msg.CreatedAt == nil {
|
||||
msg.CreatedAt = &now
|
||||
}
|
||||
|
||||
session.Messages = append(session.Messages, msg)
|
||||
session.Updated = time.Now()
|
||||
session.Updated = now
|
||||
}
|
||||
|
||||
func (sm *SessionManager) GetHistory(key string) []providers.Message {
|
||||
@@ -300,7 +305,13 @@ func (sm *SessionManager) SetHistory(key string, history []providers.Message) {
|
||||
// from the caller's slice.
|
||||
msgs := make([]providers.Message, len(history))
|
||||
copy(msgs, history)
|
||||
now := time.Now()
|
||||
for i := range msgs {
|
||||
if msgs[i].CreatedAt == nil {
|
||||
msgs[i].CreatedAt = &now
|
||||
}
|
||||
}
|
||||
session.Messages = msgs
|
||||
session.Updated = time.Now()
|
||||
session.Updated = now
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,7 +732,11 @@ func visibleAssistantToolArgsPreview(
|
||||
return utils.VisibleToolCallArgumentsPreview(tc, toolFeedbackMaxArgsLength)
|
||||
}
|
||||
|
||||
func visibleAssistantToolMessages(toolCalls []providers.ToolCall, modelName string, createdAt *time.Time) []sessionChatMessage {
|
||||
func visibleAssistantToolMessages(
|
||||
toolCalls []providers.ToolCall,
|
||||
modelName string,
|
||||
createdAt *time.Time,
|
||||
) []sessionChatMessage {
|
||||
if len(toolCalls) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user