优化历史会话排序逻辑,按首条消息时间排序
Build Push and Deploy / docker-image (push) Failing after 41s
Build Push and Deploy / deploy-fallback-log (push) Successful in 0s

This commit is contained in:
2026-05-19 16:48:56 +08:00
parent 9106b8d4a9
commit 2fbfba118f
3 changed files with 79 additions and 18 deletions
+18 -5
View File
@@ -73,7 +73,6 @@ const getSessionGroupLabel = (timestamp: number) => {
};
export const AgentHistoryPanel = ({
sessions,
activeSessionId,
isHydrating = false,
@@ -95,11 +94,25 @@ export const AgentHistoryPanel = ({
return sessions.filter((session) => session.title.toLowerCase().includes(normalizedKeyword));
}, [keyword, sessions]);
const sortedFilteredSessions = React.useMemo(
() =>
[...filteredSessions].sort((left, right) => {
const createdAtDiff = right.createdAt - left.createdAt;
if (createdAtDiff !== 0) return createdAtDiff;
const updatedAtDiff = right.updatedAt - left.updatedAt;
if (updatedAtDiff !== 0) return updatedAtDiff;
return right.id.localeCompare(left.id);
}),
[filteredSessions],
);
const groupedSessions = React.useMemo(() => {
const groups = new Map<string, ChatSessionSummary[]>();
filteredSessions.forEach((session) => {
const label = getSessionGroupLabel(session.updatedAt);
sortedFilteredSessions.forEach((session) => {
const label = getSessionGroupLabel(session.createdAt);
const existing = groups.get(label);
if (existing) {
existing.push(session);
@@ -109,7 +122,7 @@ export const AgentHistoryPanel = ({
});
return Array.from(groups.entries());
}, [filteredSessions]);
}, [sortedFilteredSessions]);
const pendingDeleteSession = filteredSessions.find(
(session) => session.id === pendingDeleteSessionId,
@@ -390,7 +403,7 @@ export const AgentHistoryPanel = ({
{session.title}
</Typography>
<Typography variant="caption" color="text.secondary" sx={{ mt: 0.5, display: "block" }}>
{formatRelativeDate(session.updatedAt)}
{formatRelativeDate(session.createdAt)}
</Typography>
</Box>
)}