perf(webui): restore cached threads and load mention catalogs on demand
This commit is contained in:
1 parent
c370e2a5a5
commit
1a78ae2b99
13 files changed
+316
-65
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
/** Quiet layout placeholders while the authenticated application starts. */
|
||||
export function StartupShell({ embedded = false }: { embedded?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const Root = embedded ? "section" : "main";
|
||||
return (
|
||||
<Root className="startup-shell" aria-busy="true">
|
||||
<div className="startup-header" aria-hidden="true">
|
||||
<span className="startup-control-shadow" />
|
||||
<span className="startup-control-shadow" />
|
||||
</div>
|
||||
<div className="startup-composer" aria-hidden="true" />
|
||||
<span className="startup-status" role="status">{t("app.loading.connecting")}</span>
|
||||
</Root>
|
||||
);
|
||||
}
|
||||
@@ -211,6 +211,7 @@ interface ThreadComposerProps {
|
||||
recentRoundUsage?: readonly ComposerRoundUsage[];
|
||||
variant?: "thread" | "hero";
|
||||
slashCommands?: SlashCommand[];
|
||||
onMentionSearch?: () => void;
|
||||
cliApps?: CliAppInfo[];
|
||||
mcpPresets?: McpPresetInfo[];
|
||||
sessions?: ChatSummary[];
|
||||
@@ -912,6 +913,7 @@ export function ThreadComposer({
|
||||
recentRoundUsage = [],
|
||||
variant = "thread",
|
||||
slashCommands = [],
|
||||
onMentionSearch,
|
||||
cliApps = [],
|
||||
mcpPresets = [],
|
||||
sessions = [],
|
||||
@@ -1301,6 +1303,11 @@ export function ThreadComposer({
|
||||
};
|
||||
}, [cliAppMenuDismissed, cursorPosition, interactionDisabled, value]);
|
||||
|
||||
const mentionSearchActive = cliAppMention !== null;
|
||||
useEffect(() => {
|
||||
if (mentionSearchActive) onMentionSearch?.();
|
||||
}, [mentionSearchActive, onMentionSearch]);
|
||||
|
||||
const availableSessionMentions = useMemo(
|
||||
() => sessionMentionOptions(sessions),
|
||||
[sessions],
|
||||
|
||||
@@ -541,6 +541,7 @@ interface PendingFirstMessage {
|
||||
}
|
||||
|
||||
interface InstalledSettingItemsOptions<Payload, Item> {
|
||||
enabled: boolean;
|
||||
getToken: () => string;
|
||||
eventName: string;
|
||||
fetchPayload: (token: string) => Promise<Payload>;
|
||||
@@ -549,6 +550,7 @@ interface InstalledSettingItemsOptions<Payload, Item> {
|
||||
}
|
||||
|
||||
function useInstalledSettingItems<Payload, Item>({
|
||||
enabled,
|
||||
getToken,
|
||||
eventName,
|
||||
fetchPayload,
|
||||
@@ -583,14 +585,14 @@ function useInstalledSettingItems<Payload, Item>({
|
||||
}
|
||||
};
|
||||
const queueRefresh = () => {
|
||||
if (document.visibilityState === "hidden" || refreshQueued) return;
|
||||
if (!enabled || document.visibilityState === "hidden" || refreshQueued) return;
|
||||
refreshQueued = true;
|
||||
queueMicrotask(() => {
|
||||
refreshQueued = false;
|
||||
if (!cancelled) void refresh();
|
||||
});
|
||||
};
|
||||
void refresh();
|
||||
if (enabled) void refresh();
|
||||
|
||||
const refreshOnChanged = (event: Event) => {
|
||||
const payload = (event as CustomEvent<unknown>).detail;
|
||||
@@ -606,16 +608,12 @@ function useInstalledSettingItems<Payload, Item>({
|
||||
queueRefresh();
|
||||
};
|
||||
|
||||
window.addEventListener("focus", queueRefresh);
|
||||
document.addEventListener("visibilitychange", queueRefresh);
|
||||
window.addEventListener(eventName, refreshOnChanged);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
window.removeEventListener("focus", queueRefresh);
|
||||
document.removeEventListener("visibilitychange", queueRefresh);
|
||||
window.removeEventListener(eventName, refreshOnChanged);
|
||||
};
|
||||
}, [eventName, fetchPayload, getToken, isPayload, selectItems]);
|
||||
}, [enabled, eventName, fetchPayload, getToken, isPayload, selectItems]);
|
||||
|
||||
return items;
|
||||
}
|
||||
@@ -698,7 +696,10 @@ export function ThreadShell({
|
||||
}, [client]);
|
||||
const [booting, setBooting] = useState(false);
|
||||
const [slashCommands, setSlashCommands] = useState<SlashCommand[]>([]);
|
||||
const [mentionCatalogsRequested, setMentionCatalogsRequested] = useState(false);
|
||||
const requestMentionCatalogs = useCallback(() => setMentionCatalogsRequested(true), []);
|
||||
const cliApps = useInstalledSettingItems({
|
||||
enabled: mentionCatalogsRequested,
|
||||
getToken,
|
||||
eventName: CLI_APPS_CHANGED_EVENT,
|
||||
fetchPayload: fetchInstalledCliApps,
|
||||
@@ -706,6 +707,7 @@ export function ThreadShell({
|
||||
selectItems: installedCliAppsFromPayload,
|
||||
});
|
||||
const mcpPresets = useInstalledSettingItems({
|
||||
enabled: mentionCatalogsRequested,
|
||||
getToken,
|
||||
eventName: MCP_PRESETS_CHANGED_EVENT,
|
||||
fetchPayload: fetchMcpPresets,
|
||||
@@ -899,6 +901,11 @@ export function ThreadShell({
|
||||
}, []);
|
||||
|
||||
const displayMessages = useMemo(() => projectWebuiThreadMessages(messages), [messages]);
|
||||
useEffect(() => {
|
||||
if (displayMessages.some((message) => message.cliApps?.length || message.mcpPresets?.length)) {
|
||||
requestMentionCatalogs();
|
||||
}
|
||||
}, [displayMessages, requestMentionCatalogs]);
|
||||
const composerContextUsage = useMemo(
|
||||
() => latestComposerContextUsage(displayMessages),
|
||||
[displayMessages],
|
||||
@@ -1725,6 +1732,7 @@ export function ThreadShell({
|
||||
recentRoundUsage={composerRoundUsage}
|
||||
variant={composerVariant}
|
||||
slashCommands={availableSlashCommands}
|
||||
onMentionSearch={requestMentionCatalogs}
|
||||
cliApps={cliApps}
|
||||
mcpPresets={mcpPresets}
|
||||
sessions={mentionSessions}
|
||||
@@ -1774,6 +1782,7 @@ export function ThreadShell({
|
||||
recentRoundUsage={composerRoundUsage}
|
||||
variant="hero"
|
||||
slashCommands={availableSlashCommands}
|
||||
onMentionSearch={requestMentionCatalogs}
|
||||
cliApps={cliApps}
|
||||
mcpPresets={mcpPresets}
|
||||
sessions={mentionSessions}
|
||||
|
||||
Reference in new issue
Block a user