diff --git a/webview-ui/src/components/chat/TaskHeader.tsx b/webview-ui/src/components/chat/TaskHeader.tsx index 3ced874026..8948302ce1 100644 --- a/webview-ui/src/components/chat/TaskHeader.tsx +++ b/webview-ui/src/components/chat/TaskHeader.tsx @@ -104,6 +104,20 @@ const TaskHeader = ({ const textRef = useRef(null) const contextWindow = model?.contextWindow || 1 + // Calculate maxTokens (reserved for output) once for reuse in percentage and tooltip + const maxTokens = useMemo( + () => + model + ? getModelMaxOutputTokens({ + modelId, + model, + settings: apiConfiguration, + }) + : 0, + [model, modelId, apiConfiguration], + ) + const reservedForOutput = maxTokens || 0 + // Detect if this task had any browser session activity so we can show a grey globe when inactive const browserSessionStartIndex = useMemo(() => { const msgs = clineMessages || [] @@ -226,14 +240,6 @@ const TaskHeader = ({
{ - const maxTokens = model - ? getModelMaxOutputTokens({ - modelId, - model, - settings: apiConfiguration, - }) - : 0 - const reservedForOutput = maxTokens || 0 const availableSpace = contextWindow - (contextTokens || 0) - reservedForOutput return ( @@ -276,7 +282,9 @@ const TaskHeader = ({ sideOffset={8}> {(() => { - const percentage = Math.round(((contextTokens || 0) / contextWindow) * 100) + const percentage = Math.round( + (((contextTokens || 0) + reservedForOutput) / contextWindow) * 100, + ) return ( <> @@ -397,15 +405,7 @@ const TaskHeader = ({ {condenseButton}