Files
gemini-cli/packages/cli/src/ui/utils/contextUsage.ts
T

30 lines
652 B
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { tokenLimit } from '@google/gemini-cli-core';
export function getContextUsagePercentage(
promptTokenCount: number,
model: string | undefined,
): number {
if (!model || typeof model !== 'string' || model.length === 0) {
return 0;
}
const limit = tokenLimit(model);
if (limit <= 0) {
return 0;
}
return promptTokenCount / limit;
}
export function isContextUsageHigh(
promptTokenCount: number,
model: string | undefined,
threshold = 0.6,
): boolean {
return getContextUsagePercentage(promptTokenCount, model) > threshold;
}