feat(ui): restore threshold hint and thin arrow to compression message

This commit is contained in:
Keith Guerin
2026-03-20 12:37:28 -07:00
parent fd8d218911
commit 375afc7199
9 changed files with 128 additions and 20 deletions
+8 -1
View File
@@ -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),
}),
}),
);
+25 -11
View File
@@ -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;
}
/**
+1
View File
@@ -188,6 +188,7 @@ export interface ChatCompressionInfo {
originalTokenCount: number;
newTokenCount: number;
compressionStatus: CompressionStatus;
requestTokenCount?: number;
}
export type ServerGeminiChatCompressedEvent = {