fix(server): resolve latest available agent thread

This commit is contained in:
2026-07-10 14:46:30 +08:00
parent 9d47cb9bbd
commit f288eb1365
3 changed files with 54 additions and 10 deletions
+13 -9
View File
@@ -8,20 +8,24 @@ import (
"img_infinite_canvas/internal/types"
)
func latestLovartThreadID(project design.Project) string {
if threadID := strings.TrimSpace(project.LastThreadID); threadID != "" {
return threadID
}
for index := len(project.Messages) - 1; index >= 0; index-- {
message := project.Messages[index]
if isHiddenAgentMessage(message) {
func latestLovartThreadID(currentThreadID string, threads []design.AgentThreadSummary) string {
currentThreadID = strings.TrimSpace(currentThreadID)
latestThreadID := ""
var latestTimestamp int64
for _, thread := range threads {
threadID := strings.TrimSpace(thread.AgentThreadID)
if threadID == "" {
continue
}
if threadID := strings.TrimSpace(message.ThreadID); threadID != "" {
if threadID == currentThreadID {
return threadID
}
if latestThreadID == "" || thread.UpdateTimestamp >= latestTimestamp {
latestThreadID = threadID
latestTimestamp = thread.UpdateTimestamp
}
}
return ""
return latestThreadID
}
func toCandaChatHistoryItem(message design.Message, projectID string, threadID string) types.CandaChatHistoryItem {