mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Generically exit sidebar chat after delegating (#280384)
* Initial plan * Add delegation event to exit panel chat when chatSessions API delegates to new session Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com> * Fix: Store viewModel reference to avoid potential null reference during delegation exit Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com> * fix * tidy --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com>
This commit is contained in:
@@ -40,7 +40,6 @@ import { IChatWidgetService } from '../chat.js';
|
||||
import { CHAT_SETUP_ACTION_ID } from './chatActions.js';
|
||||
import { PromptFileVariableKind, toPromptFileVariableEntry } from '../../common/chatVariableEntries.js';
|
||||
import { NEW_CHAT_SESSION_ACTION_ID } from '../chatSessions/common.js';
|
||||
import { isResponseVM } from '../../common/chatViewModel.js';
|
||||
|
||||
export const enum ActionLocation {
|
||||
ChatWidget = 'chatWidget',
|
||||
@@ -285,57 +284,7 @@ class CreateRemoteAgentJobAction {
|
||||
});
|
||||
|
||||
if (requestData) {
|
||||
await requestData.responseCompletePromise;
|
||||
|
||||
const checkAndClose = () => {
|
||||
const items = widget.viewModel?.getItems() ?? [];
|
||||
const lastItem = items[items.length - 1];
|
||||
|
||||
if (lastItem && isResponseVM(lastItem) && lastItem.isComplete && !lastItem.model.isPendingConfirmation.get()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (checkAndClose()) {
|
||||
await widget.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// Monitor subsequent responses when pending confirmations block us from closing
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
let disposed = false;
|
||||
let disposable: IDisposable | undefined;
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
const cleanup = () => {
|
||||
if (!disposed) {
|
||||
disposed = true;
|
||||
if (timeout !== undefined) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
if (disposable) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
disposable = widget.viewModel!.onDidChange(() => {
|
||||
if (checkAndClose()) {
|
||||
cleanup();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
timeout = setTimeout(() => {
|
||||
cleanup();
|
||||
resolve();
|
||||
}, 30_000); // 30 second timeout
|
||||
} catch (e) {
|
||||
cleanup();
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
await widget.clear();
|
||||
await widget.handleDelegationExitIfNeeded(requestData.agent);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error creating remote coding agent job', e);
|
||||
|
||||
Reference in New Issue
Block a user