2025-08-07 11:16:47 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { Text } from 'ink';
|
2025-09-10 10:57:07 -07:00
|
|
|
import { theme } from '../semantic-colors.js';
|
2026-02-17 07:16:37 -08:00
|
|
|
import { getContextUsagePercentage } from '../utils/contextUsage.js';
|
2026-03-03 01:22:29 -08:00
|
|
|
import { useSettings } from '../contexts/SettingsContext.js';
|
|
|
|
|
import {
|
|
|
|
|
MIN_TERMINAL_WIDTH_FOR_FULL_LABEL,
|
|
|
|
|
DEFAULT_COMPRESSION_THRESHOLD,
|
|
|
|
|
} from '../constants.js';
|
2025-08-07 11:16:47 -07:00
|
|
|
|
|
|
|
|
export const ContextUsageDisplay = ({
|
|
|
|
|
promptTokenCount,
|
|
|
|
|
model,
|
2025-10-09 19:27:20 -07:00
|
|
|
terminalWidth,
|
2025-08-07 11:16:47 -07:00
|
|
|
}: {
|
|
|
|
|
promptTokenCount: number;
|
2026-03-03 01:22:29 -08:00
|
|
|
model: string | undefined;
|
2025-10-09 19:27:20 -07:00
|
|
|
terminalWidth: number;
|
2025-08-07 11:16:47 -07:00
|
|
|
}) => {
|
2026-03-03 01:22:29 -08:00
|
|
|
const settings = useSettings();
|
2026-02-17 07:16:37 -08:00
|
|
|
const percentage = getContextUsagePercentage(promptTokenCount, model);
|
2026-03-03 01:22:29 -08:00
|
|
|
const percentageUsed = (percentage * 100).toFixed(0);
|
2025-10-09 19:27:20 -07:00
|
|
|
|
2026-03-03 01:22:29 -08:00
|
|
|
const threshold =
|
|
|
|
|
settings.merged.model?.compressionThreshold ??
|
|
|
|
|
DEFAULT_COMPRESSION_THRESHOLD;
|
|
|
|
|
|
|
|
|
|
let textColor = theme.text.secondary;
|
|
|
|
|
if (percentage >= 1.0) {
|
|
|
|
|
textColor = theme.status.error;
|
|
|
|
|
} else if (percentage >= threshold) {
|
|
|
|
|
textColor = theme.status.warning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const label =
|
2026-03-04 21:21:48 -05:00
|
|
|
terminalWidth < MIN_TERMINAL_WIDTH_FOR_FULL_LABEL ? '%' : '% used';
|
2025-08-07 11:16:47 -07:00
|
|
|
|
|
|
|
|
return (
|
2026-03-03 01:22:29 -08:00
|
|
|
<Text color={textColor}>
|
|
|
|
|
{percentageUsed}
|
2026-02-10 09:36:20 -08:00
|
|
|
{label}
|
2025-08-07 11:16:47 -07:00
|
|
|
</Text>
|
|
|
|
|
);
|
|
|
|
|
};
|