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): honor empty authoritative assistant finals

david89e45d0f9703
diff --git a/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts b/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts
index d1cc633c28..b4d81c53ea 100644
--- a/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts
+++ b/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts
@@ -992,6 +992,24 @@ describe('streamed assistant final calibration', () => {
);
});
+ it('drops stale streamed deltas when the authoritative final text is empty', async () => {
+ const persistId = onAssistantTextEvent(
+ SESSION,
+ { text: '撤回前的流式内容', isFinal: false },
+ null,
+ );
+ expect(onAssistantTextEvent(
+ SESSION,
+ { text: '', isFinal: true, isFullText: true },
+ null,
+ )).toBe(persistId);
+
+ flushAssistantBlock(SESSION, null);
+ await flushWrites();
+
+ expect(createMessage).not.toHaveBeenCalled();
+ });
+
it('does not treat a shorter unmarked isFinal tail as a complete replacement', async () => {
const persistId = onAssistantTextEvent(
SESSION,
diff --git a/apps/desktop/src/main/messagePersistBroadcaster.ts b/apps/desktop/src/main/messagePersistBroadcaster.ts
index 4471f4230a..913d1fdaff 100644
--- a/apps/desktop/src/main/messagePersistBroadcaster.ts
+++ b/apps/desktop/src/main/messagePersistBroadcaster.ts
@@ -1119,8 +1119,8 @@ export function onAssistantTextEvent(
// 已完整的、更长前缀文本。只接受以当前增量为前缀的更长文本,避免同一 assistant
// 消息中相邻 text block 互相覆盖。
if (
- text &&
- (isFullText || (text.length > block.text.length && text.startsWith(block.text)))
+ isFullText ||
+ (text.length > block.text.length && text.startsWith(block.text))
) {
block.text = text;
}