mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-11 10:30:46 -07:00
feat(ui): restore threshold hint and thin arrow to compression message
This commit is contained in:
@@ -248,6 +248,9 @@ describe('Gemini Client (client.ts)', () => {
|
||||
getEnableHooks: vi.fn().mockReturnValue(false),
|
||||
getChatCompression: vi.fn().mockReturnValue(undefined),
|
||||
getCompressionThreshold: vi.fn().mockReturnValue(undefined),
|
||||
getShowContextWindowWarning: vi.fn().mockReturnValue(false),
|
||||
getShowContextCompression: vi.fn().mockReturnValue(false),
|
||||
getContextWindowCompressionThreshold: vi.fn().mockReturnValue(0.2),
|
||||
getSkipNextSpeakerCheck: vi.fn().mockReturnValue(false),
|
||||
getShowModelInfoInChat: vi.fn().mockReturnValue(false),
|
||||
getContinueOnFailedApiCall: vi.fn(),
|
||||
@@ -1617,6 +1620,7 @@ ${JSON.stringify(
|
||||
originalTokenCount: initialTokenCount,
|
||||
newTokenCount: 400,
|
||||
compressionStatus: CompressionStatus.COMPRESSED,
|
||||
requestTokenCount: 50, // Added to match updated interface
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1643,10 +1647,13 @@ ${JSON.stringify(
|
||||
}),
|
||||
);
|
||||
|
||||
// 2. Should contain compression event
|
||||
// 2. Should contain compression event with requestTokenCount
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: GeminiEventType.ChatCompressed,
|
||||
value: expect.objectContaining({
|
||||
requestTokenCount: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -608,7 +608,19 @@ export class GeminiClient {
|
||||
// Check for context window overflow
|
||||
const modelForLimitCheck = this._getActiveModelForCurrentTurn();
|
||||
|
||||
const compressed = await this.tryCompressChat(prompt_id, false);
|
||||
// Estimate tokens. For text-only requests, we estimate based on character length.
|
||||
// For requests with non-text parts (like images, tools), we use the countTokens API.
|
||||
const estimatedRequestTokenCount = await calculateRequestTokenCount(
|
||||
request,
|
||||
this.getContentGeneratorOrFail(),
|
||||
modelForLimitCheck,
|
||||
);
|
||||
|
||||
const compressed = await this.tryCompressChat(
|
||||
prompt_id,
|
||||
false,
|
||||
estimatedRequestTokenCount,
|
||||
);
|
||||
|
||||
if (compressed.compressionStatus === CompressionStatus.COMPRESSED) {
|
||||
yield { type: GeminiEventType.ChatCompressed, value: compressed };
|
||||
@@ -619,17 +631,13 @@ export class GeminiClient {
|
||||
|
||||
await this.tryMaskToolOutputs(this.getHistory());
|
||||
|
||||
// Estimate tokens. For text-only requests, we estimate based on character length.
|
||||
// For requests with non-text parts (like images, tools), we use the countTokens API.
|
||||
const estimatedRequestTokenCount = await calculateRequestTokenCount(
|
||||
request,
|
||||
this.getContentGeneratorOrFail(),
|
||||
modelForLimitCheck,
|
||||
);
|
||||
|
||||
if (estimatedRequestTokenCount > remainingTokenCount) {
|
||||
if (!this.config.getShowContextWindowWarning()) {
|
||||
const forcedCompressed = await this.tryCompressChat(prompt_id, true);
|
||||
const forcedCompressed = await this.tryCompressChat(
|
||||
prompt_id,
|
||||
true,
|
||||
estimatedRequestTokenCount,
|
||||
);
|
||||
if (
|
||||
forcedCompressed.compressionStatus === CompressionStatus.COMPRESSED
|
||||
) {
|
||||
@@ -1175,6 +1183,7 @@ export class GeminiClient {
|
||||
async tryCompressChat(
|
||||
prompt_id: string,
|
||||
force: boolean = false,
|
||||
requestTokenCount?: number,
|
||||
): Promise<ChatCompressionInfo> {
|
||||
// If the model is 'auto', we will use a placeholder model to check.
|
||||
// Compression occurs before we choose a model, so calling `count_tokens`
|
||||
@@ -1190,6 +1199,11 @@ export class GeminiClient {
|
||||
this.hasFailedCompressionAttempt,
|
||||
);
|
||||
|
||||
const resultInfo = {
|
||||
...info,
|
||||
requestTokenCount,
|
||||
};
|
||||
|
||||
if (
|
||||
info.compressionStatus ===
|
||||
CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT
|
||||
@@ -1225,7 +1239,7 @@ export class GeminiClient {
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
return resultInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -188,6 +188,7 @@ export interface ChatCompressionInfo {
|
||||
originalTokenCount: number;
|
||||
newTokenCount: number;
|
||||
compressionStatus: CompressionStatus;
|
||||
requestTokenCount?: number;
|
||||
}
|
||||
|
||||
export type ServerGeminiChatCompressedEvent = {
|
||||
|
||||
Reference in New Issue
Block a user