🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(conversation): stop re-paging the topic start after a run step (#21625)
AmAzing-e995b2d38bb3
diff --git a/src/store/chat/slices/message/actions/transcript.paging.test.ts b/src/store/chat/slices/message/actions/transcript.paging.test.tsindex e660a4185a1..55fb7d531ae 100644--- a/src/store/chat/slices/message/actions/transcript.paging.test.ts+++ b/src/store/chat/slices/message/actions/transcript.paging.test.ts@@ -108,6 +108,30 @@ describe('message transcript paging and persistence', () => {});});+ it('keeps the reached topic start when a run appends rows to a synced head', async () => {+ const context = { agentId: 'step-agent', topicId: 'step-topic', threadId: null };+ const key = conversationMessagesKey(context);+ const user = { id: 'user', role: 'user', content: 'go', createdAt: 1 } as UIChatMessage;+ const step = { id: 'step', role: 'assistant', content: '', createdAt: 2 } as UIChatMessage;+ vi.mocked(messageService.getMessageListPage).mockResolvedValue({+ messages: [user],+ olderCursor: null,+ });+ syncMessages(context);+ await waitFor(() =>+ expect(useChatStore.getState().messageReplica.entries[key]?.source).toBe('server'),+ );++ // A step boundary of the run brings the new assistant row in through a replacement.+ useChatStore.getState().replaceMessages([user, step], { context });++ expect(useChatStore.getState().messagePagingMap[key]?.hasMore).toBe(false);+ await expect(useChatStore.getState().loadEarlierMessages(context)).resolves.toEqual({+ started: false,+ });+ expect(messageService.getEarlierMessages).not.toHaveBeenCalled();+ });+it('keeps streamed writes in memory and persists once the run settles', async () => {let running = true;vi.spyOn(operationSelectors, 'isAgentRuntimeRunningByContext').mockImplementation(diff --git a/src/store/chat/slices/message/transcript/index.ts b/src/store/chat/slices/message/transcript/index.tsindex 12051ee1e7e..74243fdbe65 100644--- a/src/store/chat/slices/message/transcript/index.ts+++ b/src/store/chat/slices/message/transcript/index.ts@@ -476,7 +476,11 @@ const createMessageTranscript = (set: StoreSetter<ChatStore>, get: () => ChatSto/*** Write a conversation's rows (memory only). An unchanged id sequence keeps* the entry's paging; so does `preservePaging` (a reducer edit of the same- * window). Anything else is a fresh, unpaged transcript.+ * window). Rows that changed only after an unchanged oldest row (a run step+ * adding its assistant and tool rows) keep what is known about the history+ * before it: re-assuming more there would page a reached topic start again+ * on every scroll to the top while the run goes on. Anything else is a+ * fresh, unpaged transcript.*/const commit = (context: TranscriptContext,@@ -491,13 +495,22 @@ const createMessageTranscript = (set: StoreSetter<ChatStore>, get: () => ChatStoif (clientCreatedId) noteClientWrite(clientCreatedId);return slice.update(key,- (current) =>- current &&- (preservePaging ||+ (current) => {+ if (!current) return transcriptOf(messages);+ if (+ preservePaging ||(current.items.length === messages.length &&- current.items.every((item, index) => item.id === messages[index].id)))- ? { ...current, items: messages }- : transcriptOf(messages),+ current.items.every((item, index) => item.id === messages[index].id))+ )+ return { ...current, items: messages };+ const keepsOlderEdge =+ context.messageReadMode !== 'forward' &&+ current.items.length > 0 &&+ current.items[0].id === messages[0]?.id;+ return keepsOlderEdge+ ? { ...transcriptOf(messages), hasMore: current.hasMore, nextCursor: current.nextCursor }+ : transcriptOf(messages);+ },{ persist: false },);};