Path: blob/main/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsOpener.ts
4780 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 { IAgentSession, isLocalAgentSessionItem } from './agentSessionsModel.js';6import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';7import { IChatEditorOptions } from '../widgetHosts/editor/chatEditor.js';8import { ChatViewPaneTarget, IChatWidgetService } from '../chat.js';9import { ACTIVE_GROUP, SIDE_GROUP } from '../../../../services/editor/common/editorService.js';10import { IEditorOptions } from '../../../../../platform/editor/common/editor.js';11import { IChatSessionsService } from '../../common/chatSessionsService.js';12import { Schemas } from '../../../../../base/common/network.js';1314export async function openSession(accessor: ServicesAccessor, session: IAgentSession, openOptions?: { sideBySide?: boolean; editorOptions?: IEditorOptions }): Promise<void> {15const chatSessionsService = accessor.get(IChatSessionsService);16const chatWidgetService = accessor.get(IChatWidgetService);1718session.setRead(true); // mark as read when opened1920let sessionOptions: IChatEditorOptions;21if (isLocalAgentSessionItem(session)) {22sessionOptions = {};23} else {24sessionOptions = { title: { preferred: session.label } };25}2627let options: IChatEditorOptions = {28...sessionOptions,29...openOptions?.editorOptions,30revealIfOpened: true // always try to reveal if already opened31};3233await chatSessionsService.activateChatSessionItemProvider(session.providerType); // ensure provider is activated before trying to open3435let target: typeof SIDE_GROUP | typeof ACTIVE_GROUP | typeof ChatViewPaneTarget | undefined;36if (openOptions?.sideBySide) {37target = ACTIVE_GROUP;38} else {39target = ChatViewPaneTarget;40}4142const isLocalChatSession = session.resource.scheme === Schemas.vscodeChatEditor || session.resource.scheme === Schemas.vscodeLocalChatSession;43if (!isLocalChatSession && !(await chatSessionsService.canResolveChatSession(session.resource))) {44target = openOptions?.sideBySide ? SIDE_GROUP : ACTIVE_GROUP; // force to open in editor if session cannot be resolved in panel45options = { ...options, revealIfOpened: true };46}4748await chatWidgetService.openSession(session.resource, target, options);49}505152