feat(ui): add context window percentage to task header

Display the percentage of total context window used alongside token count in the task header. This helps users better understand their context usage relative to the model's capacity.

Implementation details:
- Retrieve model's context window size from normalized API configuration
- Calculate percentage of context window used based on current context tokens
- Display percentage in parentheses next to token count (e.g. "40,000 (20%)")
- Default to context window size of 1 if model info is unavailable
- Format numbers with commas for better readability
This commit is contained in:
MFPires
2025-01-28 16:33:06 -03:00
parent f7cf08c607
commit ea6dc7c16e
2 changed files with 12 additions and 2 deletions

View File

@@ -3043,7 +3043,11 @@ export class Cline {
// Add context tokens information
const { contextTokens } = getApiMetrics(this.clineMessages)
details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? contextTokens.toLocaleString() : "(Not available)"}`
const modelInfo = this.api.getModel().info
const contextWindow = modelInfo.contextWindow
const contextPercentage =
contextTokens && contextWindow ? Math.round((contextTokens / contextWindow) * 100) : undefined
details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? `${contextTokens.toLocaleString()} (${contextPercentage}%)` : "(Not available)"}`
// Add current mode and any mode-specific warnings
const { mode, customModes } = (await this.providerRef.deref()?.getState()) ?? {}