Changesets · Branches · Tags · Compare
| Changeset | b83510677c3942a2b49fc3513baf94c7e2f0e8a0e567b3e3b081c3beea644684 |
|---|---|
| Author | Ting-Wai <40179554+tingwai@users.noreply.github.com> · 2025-09-11 09:53 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-11 09:53 -07:00 |
| Parents | b804d5856fb5, 20b9c3efac21 |
1 file changed
modified gui/src/components/mainInput/ContextStatus.tsx +22 −0
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { useMemo, useRef } from "react"; | |
| 1 | 2 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 2 | 3 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 3 | 4 | import { useCompactConversation } from "../../util/compactConversation"; |
| @@ -8,15 +9,36 @@ | ||
| 8 | 9 | const contextPercentage = useAppSelector( |
| 9 | 10 | (state) => state.session.contextPercentage, |
| 10 | 11 | ); |
| 12 | + const selectedChatModel = useAppSelector( | |
| 13 | + (state) => state.config.config.selectedModelByRole.chat?.model, | |
| 14 | + ); | |
| 15 | + const previousHistoryLength = useRef<number | null>(null); | |
| 16 | + const previousSelectedChatModel = useRef<string | null>(null); | |
| 11 | 17 | const history = useAppSelector((state) => state.session.history); |
| 12 | 18 | const percent = Math.round((contextPercentage ?? 0) * 100); |
| 13 | 19 | const isPruned = useAppSelector((state) => state.session.isPruned); |
| 14 | 20 | |
| 21 | + const isDifferentModelAndSameHistory = useMemo(() => { | |
| 22 | + if (!selectedChatModel) return false; | |
| 23 | + // only reset if history changes | |
| 24 | + if (previousHistoryLength.current !== history.length) { | |
| 25 | + previousHistoryLength.current = history.length; | |
| 26 | + previousSelectedChatModel.current = selectedChatModel; | |
| 27 | + return false; | |
| 28 | + } | |
| 29 | + return previousSelectedChatModel.current !== selectedChatModel; | |
| 30 | + }, [history.length, selectedChatModel]); | |
| 31 | + | |
| 15 | 32 | const compactConversation = useCompactConversation(); |
| 16 | 33 | if (!isPruned && percent < 60) { |
| 17 | 34 | return null; |
| 18 | 35 | } |
| 19 | 36 | |
| 37 | + // if user changed to a different model, we shouldn't show the context status until the user sends a new message | |
| 38 | + if (isDifferentModelAndSameHistory) { | |
| 39 | + return null; | |
| 40 | + } | |
| 41 | + | |
| 20 | 42 | const barColorClass = isPruned ? "bg-error" : "bg-description"; |
| 21 | 43 | |
| 22 | 44 | return ( |