Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsOpener.ts
4780 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 { IAgentSession, isLocalAgentSessionItem } from './agentSessionsModel.js';
7
import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';
8
import { IChatEditorOptions } from '../widgetHosts/editor/chatEditor.js';
9
import { ChatViewPaneTarget, IChatWidgetService } from '../chat.js';
10
import { ACTIVE_GROUP, SIDE_GROUP } from '../../../../services/editor/common/editorService.js';
11
import { IEditorOptions } from '../../../../../platform/editor/common/editor.js';
12
import { IChatSessionsService } from '../../common/chatSessionsService.js';
13
import { Schemas } from '../../../../../base/common/network.js';
14
15
export async function openSession(accessor: ServicesAccessor, session: IAgentSession, openOptions?: { sideBySide?: boolean; editorOptions?: IEditorOptions }): Promise<void> {
16
const chatSessionsService = accessor.get(IChatSessionsService);
17
const chatWidgetService = accessor.get(IChatWidgetService);
18
19
session.setRead(true); // mark as read when opened
20
21
let sessionOptions: IChatEditorOptions;
22
if (isLocalAgentSessionItem(session)) {
23
sessionOptions = {};
24
} else {
25
sessionOptions = { title: { preferred: session.label } };
26
}
27
28
let options: IChatEditorOptions = {
29
...sessionOptions,
30
...openOptions?.editorOptions,
31
revealIfOpened: true // always try to reveal if already opened
32
};
33
34
await chatSessionsService.activateChatSessionItemProvider(session.providerType); // ensure provider is activated before trying to open
35
36
let target: typeof SIDE_GROUP | typeof ACTIVE_GROUP | typeof ChatViewPaneTarget | undefined;
37
if (openOptions?.sideBySide) {
38
target = ACTIVE_GROUP;
39
} else {
40
target = ChatViewPaneTarget;
41
}
42
43
const isLocalChatSession = session.resource.scheme === Schemas.vscodeChatEditor || session.resource.scheme === Schemas.vscodeLocalChatSession;
44
if (!isLocalChatSession && !(await chatSessionsService.canResolveChatSession(session.resource))) {
45
target = openOptions?.sideBySide ? SIDE_GROUP : ACTIVE_GROUP; // force to open in editor if session cannot be resolved in panel
46
options = { ...options, revealIfOpened: true };
47
}
48
49
await chatWidgetService.openSession(session.resource, target, options);
50
}
51
52