Path: blob/main/src/vs/sessions/contrib/chat/browser/sessionsOpenerParticipant.ts
13401 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 { Disposable } from '../../../../base/common/lifecycle.js';6import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';7import { IWorkbenchContribution } from '../../../../workbench/common/contributions.js';8import { IAgentSession } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js';9import { ISessionOpenerParticipant, ISessionOpenOptions, sessionOpenerRegistry } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsOpener.js';10import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';1112/**13* Routes session open requests in the Agents window through the14* {@link ISessionsManagementService} so that the active session/chat state is15* properly updated. Without this, the default opener tries to load the chat16* directly into the `ChatViewId` view, which is hidden behind a `when` clause17* tied to the new-chat context keys and may simply do nothing.18*/19class SessionsOpenerParticipant implements ISessionOpenerParticipant {2021async handleOpenSession(accessor: ServicesAccessor, session: IAgentSession, openOptions?: ISessionOpenOptions): Promise<boolean> {22const sessionsManagementService = accessor.get(ISessionsManagementService);23const target = sessionsManagementService.getSession(session.resource);24if (!target) {25return false;26}2728await sessionsManagementService.openSession(session.resource, { preserveFocus: openOptions?.editorOptions?.preserveFocus });29return true;30}31}3233export class SessionsOpenerParticipantContribution extends Disposable implements IWorkbenchContribution {3435static readonly ID = 'sessions.sessionOpenerParticipant';3637constructor() {38super();39this._register(sessionOpenerRegistry.registerParticipant(new SessionsOpenerParticipant()));40}41}424344