mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-01 05:00:46 +00:00
feat(cli): support single Ctrl+C to cancel streaming, preserving double Ctrl+C to exit (#5838)
This commit is contained in:
parent
f9efb2e24f
commit
2d1a6af890
3 changed files with 40 additions and 21 deletions
|
|
@ -183,26 +183,39 @@ export const useGeminiStream = (
|
|||
return StreamingState.Idle;
|
||||
}, [isResponding, toolCalls]);
|
||||
|
||||
const cancelOngoingRequest = useCallback(() => {
|
||||
if (streamingState !== StreamingState.Responding) {
|
||||
return;
|
||||
}
|
||||
if (turnCancelledRef.current) {
|
||||
return;
|
||||
}
|
||||
turnCancelledRef.current = true;
|
||||
abortControllerRef.current?.abort();
|
||||
if (pendingHistoryItemRef.current) {
|
||||
addItem(pendingHistoryItemRef.current, Date.now());
|
||||
}
|
||||
addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: 'Request cancelled.',
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
setPendingHistoryItem(null);
|
||||
onCancelSubmit();
|
||||
setIsResponding(false);
|
||||
}, [
|
||||
streamingState,
|
||||
addItem,
|
||||
setPendingHistoryItem,
|
||||
onCancelSubmit,
|
||||
pendingHistoryItemRef,
|
||||
]);
|
||||
|
||||
useInput((_input, key) => {
|
||||
if (streamingState === StreamingState.Responding && key.escape) {
|
||||
if (turnCancelledRef.current) {
|
||||
return;
|
||||
}
|
||||
turnCancelledRef.current = true;
|
||||
abortControllerRef.current?.abort();
|
||||
if (pendingHistoryItemRef.current) {
|
||||
addItem(pendingHistoryItemRef.current, Date.now());
|
||||
}
|
||||
addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: 'Request cancelled.',
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
setPendingHistoryItem(null);
|
||||
onCancelSubmit();
|
||||
setIsResponding(false);
|
||||
if (key.escape) {
|
||||
cancelOngoingRequest();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -954,5 +967,6 @@ export const useGeminiStream = (
|
|||
initError,
|
||||
pendingHistoryItems,
|
||||
thought,
|
||||
cancelOngoingRequest,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue