Path: blob/main/src/vs/workbench/contrib/mcp/browser/openPanelChatAndGetWidget.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { raceTimeout } from '../../../../base/common/async.js';6import { Event } from '../../../../base/common/event.js';7import { IViewsService } from '../../../services/views/common/viewsService.js';8import { IChatWidgetService, IChatWidget, ChatViewId } from '../../chat/browser/chat.js';9import { ChatAgentLocation } from '../../chat/common/constants.js';101112export async function openPanelChatAndGetWidget(viewsService: IViewsService, chatService: IChatWidgetService): Promise<IChatWidget | undefined> {13await viewsService.openView(ChatViewId, true);14const widgets = chatService.getWidgetsByLocations(ChatAgentLocation.Panel);15if (widgets.length) {16return widgets[0];17}1819const eventPromise = Event.toPromise(Event.filter(chatService.onDidAddWidget, e => e.location === ChatAgentLocation.Panel));2021return await raceTimeout(22eventPromise,2310000, // should be enough time for chat to initialize...24() => eventPromise.cancel()25);26}272829