Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsQuickAccess.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 { IKeyMods, IQuickPickDidAcceptEvent, IQuickPickSeparator } from '../../../../../platform/quickinput/common/quickInput.js';
7
import { PickerQuickAccessProvider, IPickerQuickAccessItem, TriggerAction } from '../../../../../platform/quickinput/browser/pickerQuickAccess.js';
8
import { localize } from '../../../../../nls.js';
9
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
10
import { IMatch, matchesFuzzy } from '../../../../../base/common/filters.js';
11
import { ThemeIcon } from '../../../../../base/common/themables.js';
12
import { IAgentSessionsService } from './agentSessionsService.js';
13
import { AgentSessionsSorter, groupAgentSessions } from './agentSessionsViewer.js';
14
import { IAgentSession } from './agentSessionsModel.js';
15
import { openSession } from './agentSessionsOpener.js';
16
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
17
import { AGENT_SESSION_DELETE_ACTION_ID, AGENT_SESSION_RENAME_ACTION_ID } from './agentSessions.js';
18
import { archiveButton, deleteButton, getSessionButtons, getSessionDescription, renameButton, unarchiveButton } from './agentSessionsPicker.js';
19
20
export const AGENT_SESSIONS_QUICK_ACCESS_PREFIX = 'agent ';
21
22
export class AgentSessionsQuickAccessProvider extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
23
24
private readonly sorter = new AgentSessionsSorter();
25
26
constructor(
27
@IAgentSessionsService private readonly agentSessionsService: IAgentSessionsService,
28
@IInstantiationService private readonly instantiationService: IInstantiationService,
29
@ICommandService private readonly commandService: ICommandService,
30
) {
31
super(AGENT_SESSIONS_QUICK_ACCESS_PREFIX, {
32
canAcceptInBackground: true,
33
noResultsPick: {
34
label: localize('noAgentSessionResults', "No matching agent sessions")
35
}
36
});
37
}
38
39
protected async _getPicks(filter: string): Promise<(IQuickPickSeparator | IPickerQuickAccessItem)[]> {
40
const picks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];
41
42
const sessions = this.agentSessionsService.model.sessions.sort(this.sorter.compare.bind(this.sorter));
43
const groupedSessions = groupAgentSessions(sessions);
44
45
for (const group of groupedSessions.values()) {
46
if (group.sessions.length > 0) {
47
picks.push({ type: 'separator', label: group.label });
48
49
for (const session of group.sessions) {
50
const highlights = matchesFuzzy(filter, session.label, true);
51
if (highlights) {
52
picks.push(this.toPickItem(session, highlights));
53
}
54
}
55
}
56
}
57
58
return picks;
59
}
60
61
private toPickItem(session: IAgentSession, highlights: IMatch[]): IPickerQuickAccessItem {
62
const description = getSessionDescription(session);
63
const buttons = getSessionButtons(session);
64
65
return {
66
label: session.label,
67
description,
68
highlights: { label: highlights },
69
iconClass: ThemeIcon.asClassName(session.icon),
70
buttons,
71
trigger: async (buttonIndex) => {
72
const button = buttons[buttonIndex];
73
switch (button) {
74
case renameButton:
75
await this.commandService.executeCommand(AGENT_SESSION_RENAME_ACTION_ID, session);
76
return TriggerAction.REFRESH_PICKER;
77
case deleteButton:
78
await this.commandService.executeCommand(AGENT_SESSION_DELETE_ACTION_ID, session);
79
return TriggerAction.REFRESH_PICKER;
80
case archiveButton:
81
case unarchiveButton: {
82
const newArchivedState = !session.isArchived();
83
session.setArchived(newArchivedState);
84
return TriggerAction.REFRESH_PICKER;
85
}
86
default:
87
return TriggerAction.NO_ACTION;
88
}
89
},
90
accept: (keyMods: IKeyMods, event: IQuickPickDidAcceptEvent) => {
91
this.instantiationService.invokeFunction(openSession, session, {
92
sideBySide: event.inBackground,
93
editorOptions: {
94
preserveFocus: event.inBackground,
95
pinned: event.inBackground
96
}
97
});
98
}
99
};
100
}
101
}
102
103