feat(core): Improve request token calculation accuracy (#13824)

This commit is contained in:
Sandy Tao
2025-11-26 12:20:46 +08:00
committed by GitHub
parent 36a0a3d37b
commit e1d2653a7a
8 changed files with 307 additions and 56 deletions
@@ -154,6 +154,9 @@ describe('ChatCompressionService', () => {
generateContent: mockGenerateContent,
}),
isInteractive: vi.fn().mockReturnValue(false),
getContentGenerator: vi.fn().mockReturnValue({
countTokens: vi.fn().mockResolvedValue({ totalTokens: 100 }),
}),
} as unknown as Config;
vi.mocked(tokenLimit).mockReturnValue(1000);
@@ -286,6 +289,11 @@ describe('ChatCompressionService', () => {
],
} as unknown as GenerateContentResponse);
// Override mock to simulate high token count for this specific test
vi.mocked(mockConfig.getContentGenerator().countTokens).mockResolvedValue({
totalTokens: 10000,
});
const result = await service.compress(
mockChat,
mockPromptId,