refactor(chat): remove pagination-related state and logic from chat components

This commit is contained in:
2026-07-13 17:06:12 +08:00
parent b126b83c4c
commit cd0351b923
11 changed files with 18 additions and 169 deletions
+5 -12
View File
@@ -3,15 +3,16 @@ import { resolveChatCacheOwnerKey } from "@/data/repositories/chat_cache_identit
import { getChatRepository } from "@/data/repositories/chat_repository";
import { Logger, Result, todayString } from "@/utils";
import { localMessagesToUi, PAGE_SIZE } from "./chat-machine.helpers";
import {
CHAT_HISTORY_LIMIT,
localMessagesToUi,
} from "./chat-machine.helpers";
const log = new Logger("StoresChatChatHistorySync");
export type ReadAndSyncHistoryOutput = {
/** Network-authoritative messages. Empty network history includes a UI greeting. */
messages: UiMessage[];
hasMore: boolean;
newOffset: number;
/** True when network history was written back to local storage. */
localOverwritten: boolean;
localCount: number;
@@ -21,8 +22,6 @@ export type ReadAndSyncHistoryOutput = {
export type LocalHistorySnapshotOutput = {
/** Local cached messages. Empty local history includes a UI greeting. */
messages: UiMessage[];
hasMore: boolean;
newOffset: number;
localCount: number;
};
@@ -69,8 +68,6 @@ export async function readLocalHistorySnapshot(
return {
messages: snapshotMessages,
hasMore: localMessages.length >= PAGE_SIZE,
newOffset: snapshotMessages.length,
localCount: localMessages.length,
};
}
@@ -82,7 +79,7 @@ export async function syncNetworkHistory(
const chatRepo = getChatRepository();
const greetingMessage = createGreetingMessage();
const networkResult = await chatRepo.getHistory(PAGE_SIZE, 0);
const networkResult = await chatRepo.getHistory(CHAT_HISTORY_LIMIT, 0);
if (Result.isErr(networkResult)) {
log.error("[chat-machine] loadHistory NETWORK FAILED", {
error: networkResult.error,
@@ -120,8 +117,6 @@ export async function syncNetworkHistory(
return {
messages: finalMessages,
hasMore: finalMessages.length >= PAGE_SIZE,
newOffset: finalMessages.length,
localOverwritten,
localCount,
networkCount: networkUi.length,
@@ -145,8 +140,6 @@ export async function readAndSyncHistory(): Promise<ReadAndSyncHistoryOutput> {
return {
messages: localSnapshot.messages,
hasMore: localSnapshot.hasMore,
newOffset: localSnapshot.newOffset,
localOverwritten: false,
localCount: localSnapshot.localCount,
networkCount: 0,