refactor: migrate chatCompressionService to use HookSystem (#16259)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Vedant Mahajan
2026-01-10 01:48:06 +05:30
committed by GitHub
parent 14f0cb4538
commit 9d187e041c
2 changed files with 4 additions and 10 deletions

View File

@@ -159,6 +159,7 @@ describe('ChatCompressionService', () => {
}),
getEnableHooks: vi.fn().mockReturnValue(false),
getMessageBus: vi.fn().mockReturnValue(undefined),
getHookSystem: () => undefined,
} as unknown as Config;
vi.mocked(tokenLimit).mockReturnValue(1000);

View File

@@ -22,7 +22,6 @@ import {
PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_FLASH_MODEL,
} from '../config/models.js';
import { firePreCompressHook } from '../core/sessionHookTriggers.js';
import { PreCompressTrigger } from '../hooks/types.js';
/**
@@ -128,16 +127,10 @@ export class ChatCompressionService {
};
}
// Fire PreCompress hook before compression (only if hooks are enabled)
// Fire PreCompress hook before compression
// This fires for both manual and auto compression attempts
const hooksEnabled = config.getEnableHooks();
const messageBus = config.getMessageBus();
if (hooksEnabled && messageBus) {
const trigger = force
? PreCompressTrigger.Manual
: PreCompressTrigger.Auto;
await firePreCompressHook(messageBus, trigger);
}
const trigger = force ? PreCompressTrigger.Manual : PreCompressTrigger.Auto;
await config.getHookSystem()?.firePreCompressEvent(trigger);
const originalTokenCount = chat.getLastPromptTokenCount();