feat: do not show context fill display when model changes

This commit is contained in:
uinstinct 2025-09-11 12:50:05 +05:30
parent cf6b7d1878
commit fc3e72dfe1

View file

@ -1,3 +1,4 @@
import { useMemo, useRef } from "react";
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { saveCurrentSession } from "../../redux/thunks/session";
import { useCompactConversation } from "../../util/compactConversation";
@ -8,15 +9,36 @@ const ContextStatus = () => {
const contextPercentage = useAppSelector(
(state) => state.session.contextPercentage,
);
const selectedChatModel = useAppSelector(
(state) => state.config.config.selectedModelByRole.chat?.model,
);
const previousHistoryLength = useRef<number | null>(null);
const previousSelectedChatModel = useRef<string | null>(null);
const history = useAppSelector((state) => state.session.history);
const percent = Math.round((contextPercentage ?? 0) * 100);
const isPruned = useAppSelector((state) => state.session.isPruned);
const isDifferentModelAndSameHistory = useMemo(() => {
if (!selectedChatModel) return false;
// only reset if history changes
if (previousHistoryLength.current !== history.length) {
previousHistoryLength.current = history.length;
previousSelectedChatModel.current = selectedChatModel;
return false;
}
return previousSelectedChatModel.current !== selectedChatModel;
}, [history.length, selectedChatModel]);
const compactConversation = useCompactConversation();
if (!isPruned && percent < 60) {
return null;
}
// if user changed to a different model, we shouldn't show the context status until the user sends a new message
if (isDifferentModelAndSameHistory) {
return null;
}
const barColorClass = isPruned ? "bg-error" : "bg-description";
return (