mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
fix(cli): address review issues in /btw command
- Add pendingItem conflict guard to prevent overwriting other operations - Use finally block to ensure setPendingItem(null) is always called - Wrap "Thinking..." with t() for i18n support - Remove unnecessary type assertion, use typed variable instead Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3818f8acd4
commit
8dc34c385d
2 changed files with 45 additions and 37 deletions
|
|
@ -57,6 +57,17 @@ export const btwCommand: SlashCommand = {
|
|||
};
|
||||
}
|
||||
|
||||
// Guard against concurrent pending operations
|
||||
if (ui.pendingItem) {
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'error',
|
||||
content: t(
|
||||
'Another operation is in progress. Please wait for it to complete.',
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
// Show pending state
|
||||
const pendingItem: HistoryItemBtw = {
|
||||
type: MessageType.BTW,
|
||||
|
|
@ -92,7 +103,6 @@ export const btwCommand: SlashCommand = {
|
|||
);
|
||||
|
||||
if (abortSignal?.aborted) {
|
||||
ui.setPendingItem(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -105,25 +115,20 @@ export const btwCommand: SlashCommand = {
|
|||
.join('') || t('No response received.');
|
||||
|
||||
// Clear pending and show the completed btw item
|
||||
ui.setPendingItem(null);
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.BTW,
|
||||
btw: {
|
||||
question,
|
||||
answer,
|
||||
isPending: false,
|
||||
},
|
||||
} as HistoryItemBtw,
|
||||
Date.now(),
|
||||
);
|
||||
const completedItem: HistoryItemBtw = {
|
||||
type: MessageType.BTW,
|
||||
btw: {
|
||||
question,
|
||||
answer,
|
||||
isPending: false,
|
||||
},
|
||||
};
|
||||
ui.addItem(completedItem, Date.now());
|
||||
} catch (error) {
|
||||
if (abortSignal?.aborted) {
|
||||
ui.setPendingItem(null);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.setPendingItem(null);
|
||||
ui.addItem(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
|
|
@ -133,6 +138,8 @@ export const btwCommand: SlashCommand = {
|
|||
},
|
||||
Date.now(),
|
||||
);
|
||||
} finally {
|
||||
ui.setPendingItem(null);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue