Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 一次到达超过一页的新消息时,主时间线与 Thread 从新页重新开始,不留看不见的空档
Chrise4ddaf44d1e0
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.tsindex 011ebb681f..5aec6f12bf 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts+++ b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts@@ -84,6 +84,20 @@ export function mergeBotGroupLatestPage(): BotGroupLoadedTimeline {const page = next.messages;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+ // 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) {+ return {+ group: { ...next, messages: stabilizeById(previous.group.messages, page, previous.older),+ plans: stabilizeById(previous.group.plans, next.plans, previous.olderPlans) },+ older: [],+ olderPlans: [],+ olderHasMore: next.hasMoreBefore,+ };+ }// A page that says nothing comes before it is the whole recent history: whatever the last// latest page showed below it is gone. Pages opened through 「查看更早」 stay as they were;// their quoted originals are re-checked separately.diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsxindex 1a17d91cf8..14fc14c75e 100644--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx@@ -99,9 +99,14 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,setRoot(previous => (previous && JSON.stringify(previous) === JSON.stringify(result.root) ? previous : result.root));setError('');setExecutionFailures(result.executionFailures ?? []);- setReplies(previous => stabilizeById(previous, mergeBotGroupMessages(previous, result.replies)));- if (!before) latestFloorRef.current = result.replies.reduce((min, reply) => Math.min(min, reply.sequence), Number.POSITIVE_INFINITY);- if (!rereadOnly && (before || shown.length === 0)) setHasMore(result.hasMore);+ 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:+ // 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);+ setReplies(previous => stabilizeById(previous, gap ? result.replies : mergeBotGroupMessages(previous, result.replies)));+ if (!before) latestFloorRef.current = floor;+ if (!rereadOnly && (before || shown.length === 0 || gap)) setHasMore(result.hasMore);} catch { if (current()) setError(t(key('requestFailed'))); }}, [group.id, rootId, t]);const readRef = useRef(read);diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.tsindex 5d9ec576eb..cf27213644 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts@@ -70,6 +70,19 @@ describe('push refresh merge', () => {expect(merged.older).toBe(first.older);});+ 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 };+ const merged = mergeBotGroupLatestPage(first, detail(page(16, 18), true));+ expect(merged.group.messages.map((message) => message.id)).toEqual(['m16', 'm17', 'm18']);+ // As on first load: 「查看更早」 reads on from right below the new page (13-15 included).+ expect(merged.older).toEqual([]);+ expect(merged.olderHasMore).toBe(true);+ // A page that still reaches the one on screen keeps the rows below it.+ expect(mergeBotGroupLatestPage(first, detail(page(12, 14), true)).older.map((message) => message.id))+ .toEqual(['m1', 'm2', 'm3', 'm10', 'm11']);+ });+it('reuses an unchanged array as is', () => {const items = page(1, 2);expect(stabilizeById(items, items.map((item) => ({ ...item })))).toBe(items);diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsxindex 8ec89fe7b3..1c48a6e640 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx@@ -149,6 +149,23 @@ describe('chat interaction controls', () => {expect(screen.getByText('Root message')).toBeTruthy();});+ 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' };+ mocks.thread.mockResolvedValueOnce({ ok: true, root: message, replies: [early], hasMore: false })+ .mockResolvedValue({ ok: true, root: message, replies: [far], hasMore: true });+ render(<ChatThreadPanel group={group} rootId="root" onClose={vi.fn()} />);+ await screen.findByText('Early reply');+ expect(screen.queryByRole('button', { name: 'bots.groupChat.timeline.loadEarlier' })).toBeNull();+ // More than a page arrived at once: replies may sit between 5 and 200.+ const root = screen.getByText('Root message').closest('article')!;+ fireEvent.click(within(root).getByRole('button', { name: k('reactionCount') }));+ await screen.findByText('Far reply');+ expect(screen.queryByText('Early reply')).toBeNull();+ fireEvent.click(await screen.findByRole('button', { name: 'bots.groupChat.timeline.loadEarlier' }));+ await waitFor(() => expect(mocks.thread.mock.calls.at(-1)?.[0]).toMatchObject({ before: 200 }));+ });+it('clears a retried failure on an older loaded Thread page without dropping its reply', async () => {const latest = { ...message, id: 'latest', sequence: 100, content: 'Latest reply' };const older = { ...message, id: 'older', sequence: 4, content: 'Earlier reply' };