mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 13:53:02 -07:00
@@ -42,6 +42,7 @@ describe('compressCommand', () => {
|
||||
},
|
||||
};
|
||||
await compressCommand.action!(context, '');
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(context.ui.addItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: MessageType.ERROR,
|
||||
@@ -62,6 +63,7 @@ describe('compressCommand', () => {
|
||||
mockTryCompressChat.mockResolvedValue(compressedResult);
|
||||
|
||||
await compressCommand.action!(context, '');
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
|
||||
expect(context.ui.setPendingItem).toHaveBeenNthCalledWith(1, {
|
||||
type: MessageType.COMPRESSION,
|
||||
@@ -98,6 +100,7 @@ describe('compressCommand', () => {
|
||||
mockTryCompressChat.mockResolvedValue(null);
|
||||
|
||||
await compressCommand.action!(context, '');
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
|
||||
expect(context.ui.addItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -114,6 +117,7 @@ describe('compressCommand', () => {
|
||||
mockTryCompressChat.mockRejectedValue(error);
|
||||
|
||||
await compressCommand.action!(context, '');
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
|
||||
expect(context.ui.addItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -128,6 +132,7 @@ describe('compressCommand', () => {
|
||||
it('should clear the pending item in a finally block', async () => {
|
||||
mockTryCompressChat.mockRejectedValue(new Error('some error'));
|
||||
await compressCommand.action!(context, '');
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(context.ui.setPendingItem).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
|
||||
@@ -36,48 +36,51 @@ export const compressCommand: SlashCommand = {
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
ui.setPendingItem(pendingMessage);
|
||||
const promptId = `compress-${Date.now()}`;
|
||||
const compressed =
|
||||
await context.services.agentContext?.geminiClient?.tryCompressChat(
|
||||
promptId,
|
||||
true,
|
||||
);
|
||||
if (compressed) {
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.COMPRESSION,
|
||||
compression: {
|
||||
isPending: false,
|
||||
originalTokenCount: compressed.originalTokenCount,
|
||||
newTokenCount: compressed.newTokenCount,
|
||||
compressionStatus: compressed.compressionStatus,
|
||||
ui.setPendingItem(pendingMessage);
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
const promptId = `compress-${Date.now()}`;
|
||||
const compressed =
|
||||
await context.services.agentContext?.geminiClient?.tryCompressChat(
|
||||
promptId,
|
||||
true,
|
||||
);
|
||||
if (compressed) {
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.COMPRESSION,
|
||||
compression: {
|
||||
isPending: false,
|
||||
originalTokenCount: compressed.originalTokenCount,
|
||||
newTokenCount: compressed.newTokenCount,
|
||||
compressionStatus: compressed.compressionStatus,
|
||||
},
|
||||
} as HistoryItemCompression,
|
||||
Date.now(),
|
||||
);
|
||||
} else {
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
text: 'Failed to compress chat history.',
|
||||
},
|
||||
} as HistoryItemCompression,
|
||||
Date.now(),
|
||||
);
|
||||
} else {
|
||||
Date.now(),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
text: 'Failed to compress chat history.',
|
||||
text: `Failed to compress chat history: ${
|
||||
e instanceof Error ? e.message : String(e)
|
||||
}`,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
} finally {
|
||||
ui.setPendingItem(null);
|
||||
}
|
||||
} catch (e) {
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
text: `Failed to compress chat history: ${
|
||||
e instanceof Error ? e.message : String(e)
|
||||
}`,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
} finally {
|
||||
ui.setPendingItem(null);
|
||||
}
|
||||
})();
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user