























@@ -180,6 +180,27 @@ function compareSessionCandidatesByUpdatedAt(left: SessionCandidate, right: Sess
180180return (right.updatedAt ?? 0) - (left.updatedAt ?? 0);
181181}
182182183+function selectRecentSessionCandidates(
184+candidates: SessionCandidate[],
185+limit: number,
186+): SessionCandidate[] {
187+const selected: SessionCandidate[] = [];
188+for (const candidate of candidates) {
189+const insertAt = selected.findIndex(
190+(selectedCandidate) => compareSessionCandidatesByUpdatedAt(candidate, selectedCandidate) < 0,
191+);
192+if (insertAt >= 0) {
193+selected.splice(insertAt, 0, candidate);
194+if (selected.length > limit) {
195+selected.pop();
196+}
197+} else if (selected.length < limit) {
198+selected.push(candidate);
199+}
200+}
201+return selected;
202+}
203+183204function listSessionCandidates(storePath: string, agentId?: string) {
184205return (
185206listSessionEntries({
@@ -193,7 +214,6 @@ function listSessionCandidates(storePath: string, agentId?: string) {
193214 entry,
194215updatedAt: entry?.updatedAt ?? null,
195216}))
196-.toSorted(compareSessionCandidatesByUpdatedAt)
197217);
198218}
199219@@ -471,9 +491,10 @@ export async function getStatusSummary(
471491agentList.agents.map(async (agent) => {
472492const storePath = resolveStorePath(cfg.session?.store, { agentId: agent.id });
473493const candidates = loadSessionCandidates(storePath, agent.id);
474-const sessions = await buildSessionRows(candidates.slice(0, RECENT_SESSION_LIMIT), {
475-agentIdOverride: agent.id,
476-});
494+const sessions = await buildSessionRows(
495+selectRecentSessionCandidates(candidates, RECENT_SESSION_LIMIT),
496+{ agentIdOverride: agent.id },
497+);
477498return {
478499agentId: agent.id,
479500path: storePath,
@@ -492,9 +513,10 @@ export async function getStatusSummary(
492513source.storePath,
493514pathCounts.get(source.storePath) === 1 ? source.agentId : undefined,
494515),
495-)
496-.toSorted((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));
497-const recent = await buildSessionRows(allSessions.slice(0, RECENT_SESSION_LIMIT));
516+);
517+const recent = await buildSessionRows(
518+selectRecentSessionCandidates(allSessions, RECENT_SESSION_LIMIT),
519+);
498520const totalSessions = allSessions.length;
499521500522const summary: StatusSummary = {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。