fix(webui): preserve oversized turn history with record pagination (#6586)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-11 17:32:47 +08:00
1 parent 5c1083df7f
commit 3c61bcfdf0
34 files changed
+3466 -380

No files matched your search

+10 -10
View File
@@ -28,16 +28,16 @@ export function persistedCanonicalRunState(body: WebuiThreadPersistedPayload): {
completedTurnIds: string[];
snapshot: CanonicalRunSnapshot;
} {
const messages = projectThreadEvents(body.events);
const suppliedCompletionIds = Array.isArray(body.completed_turn_ids) ? body.completed_turn_ids : null;
// The older protocol-1 host may omit active_turn_id. Its explicit pending
// flag still confirms idle; a missing flag cannot establish completion.
const snapshot = canonicalRunSnapshot(
messages,
body.has_pending_tool_calls !== false,
typeof body.active_turn_id === "string" ? body.active_turn_id : null,
suppliedCompletionIds !== null,
);
// User identities and explicit completion are wire facts, not rendered messages.
const snapshot: CanonicalRunSnapshot = {
observedTurnIds: Array.from(new Set(body.events.flatMap((event) => (
event.event === "user_message" && event.turn_id ? [event.turn_id] : []
)))),
hasPendingToolCalls: body.has_pending_tool_calls !== false,
activeTurnId: typeof body.active_turn_id === "string" ? body.active_turn_id : null,
completionIdsProvided: suppliedCompletionIds !== null,
};
const completedTurnIds = suppliedCompletionIds?.filter(
(turnId) => typeof turnId === "string" && turnId.length > 0,
) ?? [];
@@ -47,7 +47,7 @@ export function persistedCanonicalRunState(body: WebuiThreadPersistedPayload): {
completedTurnIds.push(...body.events.flatMap((event) => (
event.event === "turn_end" && event.turn_id ? [event.turn_id] : []
)));
completedTurnIds.push(...completedAssistantTurnIds(messages));
completedTurnIds.push(...completedAssistantTurnIds(projectThreadEvents(body.events)));
}
return { completedTurnIds: Array.from(new Set(completedTurnIds)), snapshot };
}