Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): preserve loaded messages across adjacent pages
Chris63b945b4f292
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.tsindex d0cf347996..67023787c3 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts+++ b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts@@ -87,10 +87,10 @@ export function mergeBotGroupLatestPage(const floor = page.reduce((min, message) => Math.min(min, message.sequence), Number.POSITIVE_INFINITY);const ceiling = previous.group.messages.reduce((max, message) => Math.max(max, message.sequence), Number.NEGATIVE_INFINITY);// More than a page arrived at once (e.g. while the window was in the background): the new page- // does not reach the one on screen, and messages may sit between them. Keeping the old rows+ // neither overlaps nor directly adjoins the one on screen. Keeping the old rows// would hide that gap for good, so start over from the new page, as on first load; 「查看更早」// then reads on from right below it.- if (next.hasMoreBefore && page.length > 0 && previous.group.messages.length > 0 && floor > ceiling) {+ if (next.hasMoreBefore && page.length > 0 && previous.group.messages.length > 0 && floor > ceiling + 1) {return {group: { ...next, messages: stabilizeById(previous.group.messages, page, previous.older),plans: stabilizeById(previous.group.plans, next.plans, previous.olderPlans) },diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsxindex 97d6cf2576..a2bafe4645 100644--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx@@ -104,10 +104,10 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,setError('');setExecutionFailures(result.executionFailures ?? []);const floor = result.replies.reduce((min, reply) => Math.min(min, reply.sequence), Number.POSITIVE_INFINITY);- // A latest page that does not reach the replies on screen may leave replies between them:+ // A latest page that neither overlaps nor directly adjoins the shown replies may leave a gap:// start over from it, as on first load, so 「查看更早」 reads on from right below it.const gap = !before && result.hasMore && result.replies.length > 0 && shown.length > 0- && floor > shown.reduce((max, reply) => Math.max(max, reply.sequence), Number.NEGATIVE_INFINITY);+ && floor > shown.reduce((max, reply) => Math.max(max, reply.sequence), Number.NEGATIVE_INFINITY) + 1;if (!anchored(repliesRef.current)) return;setReplies(previous => (anchored(previous)? stabilizeById(previous, gap ? result.replies : mergeBotGroupMessages(previous, result.replies))diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.tsindex 77d14381c4..f1b8b5e027 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts@@ -71,6 +71,16 @@ describe('push refresh merge', () => {expect(merged.older).toBe(first.older);});+ it('retains loaded history when exactly one full latest page arrives with no missing sequence', () => {+ const first: BotGroupLoadedTimeline = { group: detail(page(101, 200), true), older: page(1, 100), olderPlans: [], olderHasMore: false };+ const merged = mergeBotGroupLatestPage(first, detail(page(201, 300), true));+ expect(merged.older).toEqual([...first.older, ...first.group.messages]);+ expect(merged.older[0]).toBe(first.older[0]);+ expect(merged.older[199]).toBe(first.group.messages[99]);+ expect(merged.olderHasMore).toBe(false);+ expect(merged.group.messages).toEqual(page(201, 300));+ });+it('starts over from a latest page that no longer reaches the rows on screen, so no gap hides between them', () => {// Opened older pages and the old latest page; then more than a page arrives at once (4-6 never seen).const first: BotGroupLoadedTimeline = { group: detail(page(10, 12), true), older: page(1, 3), olderPlans: [], olderHasMore: true };diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsxindex a0d30fbd6a..377a29cb80 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx@@ -150,6 +150,22 @@ describe('chat interaction controls', () => {expect(screen.getByText('Root message')).toBeTruthy();});+ it('retains the loaded Thread when a full adjacent page of replies arrives', async () => {+ const replies = (start: number) => Array.from({ length: 50 }, (_, i) => ({+ ...message, id: `reply-${start + i}`, sequence: start + i, content: `Reply ${start + i}`, reactions: [],+ }));+ mocks.thread.mockResolvedValueOnce({ ok: true, root: message, replies: replies(2), hasMore: false })+ .mockResolvedValue({ ok: true, root: message, replies: replies(52), hasMore: true });+ render(<ChatThreadPanel group={group} rootId="root" onClose={vi.fn()} />);+ const oldRow = (await screen.findByText('Reply 2')).closest('article');+ const root = screen.getByText('Root message').closest('article')!;+ fireEvent.click(within(root).getByRole('button', { name: k('reactionCount') }));+ await screen.findByText('Reply 101');+ expect(screen.getByText('Reply 2').closest('article')).toBe(oldRow);+ expect(screen.getByText('Reply 51')).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'bots.groupChat.timeline.loadEarlier' })).toBeNull();+ });+it('starts the Thread over from a latest page that no longer reaches the replies on screen', async () => {const early = { ...message, id: 'early', sequence: 5, content: 'Early reply' };const far = { ...message, id: 'far', sequence: 200, content: 'Far reply' };