perf(subagent): read saved task history by loaded turns (#6634)
This commit is contained in:
1 parent
1196698ecb
commit
eb8546c321
20 files changed
+893
-97
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Profiler, useState } from "react";
|
||||
import { Profiler, useCallback, useState } from "react";
|
||||
import { ThreadViewport } from "@/components/thread/ThreadViewport";
|
||||
import { SubagentTasksProvider } from "@/components/thread/SubagentTasks";
|
||||
import { useClient } from "@/providers/ClientProvider";
|
||||
@@ -17,6 +17,12 @@ export function HistoryBoundaryFixture({ local = false, navigate = false, tasks
|
||||
const history = useSessionHistory(local ? null : key);
|
||||
const messages = local ? localMessages : history.messages;
|
||||
const navigation = usePromptHistory(local ? null : key, history.version, messages);
|
||||
const [taskWindow, setTaskWindow] = useState<{ key: string; turnIds: string[] } | null>(null);
|
||||
const reportVisibleMessages = useCallback((visible: UIMessage[]) => {
|
||||
const turnIds = [...new Set(visible.flatMap(message => message.role === "user" && message.turnId ? [message.turnId] : []))];
|
||||
setTaskWindow(current => current?.key === key && current.turnIds.length === turnIds.length
|
||||
&& current.turnIds.every((turnId, index) => turnId === turnIds[index]) ? current : { key, turnIds });
|
||||
}, [key]);
|
||||
return <main className="bg-background text-foreground" style={{ height: "100vh", display: "flex", flexDirection: "column" }}>
|
||||
<div className="flex h-10 shrink-0 items-center gap-4 px-4 text-sm">
|
||||
<button onClick={() => setKey((current) => current.endsWith("-a") ? "websocket:boundary-b" : "websocket:boundary-a")}>Switch conversation</button>
|
||||
@@ -24,10 +30,13 @@ export function HistoryBoundaryFixture({ local = false, navigate = false, tasks
|
||||
<Profiler id="history-boundary" onRender={(_, phase, actualDuration) => {
|
||||
window.dispatchEvent(new CustomEvent("history-boundary-render", { detail: { phase, actualDuration } }));
|
||||
}}>
|
||||
<SubagentTasksProvider client={client} token={token} sessionKey={key} enabled={tasks} liveEvents={false}>
|
||||
<SubagentTasksProvider client={client} token={token} sessionKey={key} enabled={tasks} liveEvents={false}
|
||||
turnIds={taskWindow?.key === key ? taskWindow.turnIds : []}
|
||||
windowReady={taskWindow?.key === key && (!history.loading || messages.length > 0)}>
|
||||
<ThreadViewport messages={messages} isStreaming={false} conversationKey={key}
|
||||
messagesKey={local ? key : history.messagesKey}
|
||||
conversationReady={local || history.messagesReady} hasMoreBefore={history.hasMoreBefore}
|
||||
onVisibleMessagesChange={tasks ? reportVisibleMessages : undefined}
|
||||
initialLoading={history.loading} initialError={history.error} onRetryInitial={history.refresh}
|
||||
loadingOlder={history.loadingOlder} olderError={history.olderError} onLoadOlder={history.loadOlder}
|
||||
navigation={navigate ? navigation : undefined} userMessageOffset={history.userMessageOffset}
|
||||
|
||||
Reference in new issue
Block a user