Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/browser/openPanelChatAndGetWidget.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { raceTimeout } from '../../../../base/common/async.js';
7
import { Event } from '../../../../base/common/event.js';
8
import { IViewsService } from '../../../services/views/common/viewsService.js';
9
import { IChatWidgetService, IChatWidget, ChatViewId } from '../../chat/browser/chat.js';
10
import { ChatAgentLocation } from '../../chat/common/constants.js';
11
12
13
export async function openPanelChatAndGetWidget(viewsService: IViewsService, chatService: IChatWidgetService): Promise<IChatWidget | undefined> {
14
await viewsService.openView(ChatViewId, true);
15
const widgets = chatService.getWidgetsByLocations(ChatAgentLocation.Panel);
16
if (widgets.length) {
17
return widgets[0];
18
}
19
20
const eventPromise = Event.toPromise(Event.filter(chatService.onDidAddWidget, e => e.location === ChatAgentLocation.Panel));
21
22
return await raceTimeout(
23
eventPromise,
24
10000, // should be enough time for chat to initialize...
25
() => eventPromise.cancel()
26
);
27
}
28
29