mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
migrate compress command (#4271)
This commit is contained in:
@@ -1204,38 +1204,4 @@ describe('useSlashCommandProcessor', () => {
|
||||
expect(commandResult).toEqual({ type: 'handled' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('/compress command', () => {
|
||||
it('should call tryCompressChat(true)', async () => {
|
||||
const hook = getProcessorHook();
|
||||
mockTryCompressChat.mockResolvedValue({
|
||||
originalTokenCount: 100,
|
||||
newTokenCount: 50,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
hook.result.current.handleSlashCommand('/compress');
|
||||
});
|
||||
await act(async () => {
|
||||
hook.rerender();
|
||||
});
|
||||
expect(hook.result.current.pendingHistoryItems).toEqual([]);
|
||||
expect(mockGeminiClient.tryCompressChat).toHaveBeenCalledWith(
|
||||
'Prompt Id not set',
|
||||
true,
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
type: MessageType.COMPRESSION,
|
||||
compression: {
|
||||
isPending: false,
|
||||
originalTokenCount: 100,
|
||||
newTokenCount: 50,
|
||||
},
|
||||
}),
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -169,6 +169,8 @@ export const useSlashCommandProcessor = (
|
||||
refreshStatic();
|
||||
},
|
||||
setDebugMessage: onDebugMessage,
|
||||
pendingItem: pendingCompressionItemRef.current,
|
||||
setPendingItem: setPendingCompressionItem,
|
||||
},
|
||||
session: {
|
||||
stats: session.stats,
|
||||
@@ -184,6 +186,8 @@ export const useSlashCommandProcessor = (
|
||||
refreshStatic,
|
||||
session.stats,
|
||||
onDebugMessage,
|
||||
pendingCompressionItemRef,
|
||||
setPendingCompressionItem,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -599,60 +603,6 @@ export const useSlashCommandProcessor = (
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'compress',
|
||||
altName: 'summarize',
|
||||
description: 'Compresses the context by replacing it with a summary.',
|
||||
action: async (_mainCommand, _subCommand, _args) => {
|
||||
if (pendingCompressionItemRef.current !== null) {
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content:
|
||||
'Already compressing, wait for previous request to complete',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
setPendingCompressionItem({
|
||||
type: MessageType.COMPRESSION,
|
||||
compression: {
|
||||
isPending: true,
|
||||
originalTokenCount: null,
|
||||
newTokenCount: null,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const compressed = await config!
|
||||
.getGeminiClient()!
|
||||
// TODO: Set Prompt id for CompressChat from SlashCommandProcessor.
|
||||
.tryCompressChat('Prompt Id not set', true);
|
||||
if (compressed) {
|
||||
addMessage({
|
||||
type: MessageType.COMPRESSION,
|
||||
compression: {
|
||||
isPending: false,
|
||||
originalTokenCount: compressed.originalTokenCount,
|
||||
newTokenCount: compressed.newTokenCount,
|
||||
},
|
||||
timestamp: new Date(),
|
||||
});
|
||||
} else {
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content: 'Failed to compress chat history.',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content: `Failed to compress chat history: ${e instanceof Error ? e.message : String(e)}`,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
setPendingCompressionItem(null);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (config?.getCheckpointingEnabled()) {
|
||||
@@ -786,8 +736,6 @@ export const useSlashCommandProcessor = (
|
||||
gitService,
|
||||
loadHistory,
|
||||
setQuittingMessages,
|
||||
pendingCompressionItemRef,
|
||||
setPendingCompressionItem,
|
||||
]);
|
||||
|
||||
const handleSlashCommand = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user