Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 仅在补载出回合起点时撤销「起点未知」未读键

Dashd7a317b42f41
diff --git a/apps/desktop/src/renderer/__tests__/unreadCount.test.ts b/apps/desktop/src/renderer/__tests__/unreadCount.test.ts
index 18ee93567e..c5543ccc05 100644
--- a/apps/desktop/src/renderer/__tests__/unreadCount.test.ts
+++ b/apps/desktop/src/renderer/__tests__/unreadCount.test.ts
@@ -45,6 +45,19 @@ describe('countUnreadAdded', () => {
expect(
collectUnreadKeys({ prevIds: new Set(['a1', 'a2']), messages: loaded, nearBottom: false }),
).toEqual({ keys: ['turn:u0'], supersedes: ['turn:'] });
+ // 起点早已见过的回合(外部 user 之后的又一批回复)续接时,不得撤销更早回复的未知键。
+ expect(
+ collectUnreadKeys({
+ prevIds: new Set(['a1', 'u9', 'a9']),
+ messages: [
+ msg('a1', 'assistant'),
+ msg('u9', 'user'),
+ msg('a9', 'assistant'),
+ msg('a10', 'assistant'),
+ ],
+ nearBottom: false,
+ }),
+ ).toEqual({ keys: ['turn:u9'], supersedes: [] });
// 新到的外部 user 开启的新回复在本轮行内,不得撤销旧键。
expect(
collectUnreadKeys({
diff --git a/apps/desktop/src/renderer/components/chat/unreadCount.ts b/apps/desktop/src/renderer/components/chat/unreadCount.ts
index e3b240a09f..a36ee37c0f 100644
--- a/apps/desktop/src/renderer/components/chat/unreadCount.ts
+++ b/apps/desktop/src/renderer/components/chat/unreadCount.ts
@@ -96,12 +96,13 @@ export function collectUnreadKeys({
start = lastSeenIdx + 1;
}
let turnKey = UNKNOWN_TURN_KEY;
- // 起点在已见区域内(而非本轮新增行里):新增行续接的是已见回合。
+ // 续接已见回合,且该回合起点是这一轮才补载出来的(不在 prevIds 里):此前给这些
+ // 行记的是「起点未知」键。起点早已见过的回合(如之后新到的 user)不属于此类。
let boundaryBeforeStart = false;
for (let i = start - 1; i >= 0; i--) {
if (isTurnBoundary(messages[i])) {
turnKey = `turn:${messages[i].clientId}`;
- boundaryBeforeStart = true;
+ boundaryBeforeStart = !prevIds.has(messages[i].clientId);
break;
}
}