fix(webui): stabilize earlier-history loading and reclaim space (#6349)

* fix(webui): retain smoothly revealed history loading headers

* refactor(webui): simplify history loading feedback

* fix(webui): keep retained history headers clear of preceding text

* fix(webui): reclaim completed history loading space

* refactor(webui): group history projection handoff with navigation

* test(webui): synchronize history motion observations

* fix(webui): collapse history completion geometry handoff
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-21 13:10:05 +08:00
1 parent 73a55e0b2f
commit 743c51e81f
24 files changed
+1658 -356

No files matched your search

+12 -4
View File
@@ -13,6 +13,8 @@ interface HistoryPage {
body: WebuiThreadPersistedPayload;
}
const HISTORY_PAGE_LIMIT = 3;
export interface PromptHistoryNavigation {
prompts: PromptAnchor[];
window: {
@@ -23,6 +25,8 @@ export interface PromptHistoryNavigation {
forkBoundaryMessageCount: number | null;
} | null;
target: { id: string; sequence: number } | null;
/** Pending or failed page read; index errors have no page operation. */
operation: "jump" | "older" | "newer" | null;
loading: boolean;
error: string | null;
jump: (id: string) => void;
@@ -42,6 +46,7 @@ export function usePromptHistory(key: string | null, version: number, messages:
const indexSnapshot = useRef<PromptIndex>();
const [pages, setPages] = useState<HistoryPage[]>([]);
const [target, setTarget] = useState<PromptHistoryNavigation["target"]>(null);
const [operation, setOperation] = useState<PromptHistoryNavigation["operation"]>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [indexError, setIndexError] = useState<string | null>(null);
@@ -130,10 +135,12 @@ export function usePromptHistory(key: string | null, version: number, messages:
}, []);
const read = useCallback(async (cursor: string, direction: "before" | "after", id?: string) => {
if (!key) return;
// Boundary inputs can arrive before loading renders; only a new jump supersedes a read.
if (!key || (!id && request.current)) return;
request.current?.abort();
const controller = new AbortController();
request.current = controller;
setOperation(id ? "jump" : direction === "before" ? "older" : "newer");
setLoading(true);
setError(null);
retry.current = () => { void read(cursor, direction, id); };
@@ -150,7 +157,7 @@ export function usePromptHistory(key: string | null, version: number, messages:
}
// At most three bounded server pages, even after many navigations.
setPages((previous) => id ? [page] : direction === "before"
? [page, ...previous].slice(0, 3) : [...previous, page].slice(-3));
? [page, ...previous].slice(0, HISTORY_PAGE_LIMIT) : [...previous, page].slice(-HISTORY_PAGE_LIMIT));
if (id) setTarget({ id, sequence: ++sequence.current });
} catch (cause) {
if (!controller.signal.aborted) setError(cause instanceof Error ? cause.message : String(cause));
@@ -180,13 +187,14 @@ export function usePromptHistory(key: string | null, version: number, messages:
}, [currentScope, pages, first, last]);
return { prompts, window, target: currentScope ? target : null, loading: currentScope && loading,
operation: currentScope && (loading || error) ? operation : null,
error: currentScope ? error ?? indexError : null, cancel, latest, updateMessages,
retry: () => error ? retry.current() : setRefresh((value) => value + 1),
jump: (id) => {
const prompt = prompts.find((item) => item.id === id);
if (enabled && prompt?.cursor) void read(prompt.cursor, "after", id);
},
older: () => { if (!loading && first?.before_cursor) void read(first.before_cursor, "before"); },
newer: () => { if (!loading && last?.after_cursor) void read(last.after_cursor, "after"); },
older: () => { if (first?.before_cursor) void read(first.before_cursor, "before"); },
newer: () => { if (last?.after_cursor) void read(last.after_cursor, "after"); },
};
}