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
5263 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, groupAgentSessionsByDate } 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
import { AgentSessionsFilter } from './agentSessionsFilter.js';
20
21
export const AGENT_SESSIONS_QUICK_ACCESS_PREFIX = 'agent ';
22
23
export class AgentSessionsQuickAccessProvider extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
24
25
private readonly sorter = new AgentSessionsSorter();
26
private readonly filter: AgentSessionsFilter;
27
28
constructor(
29
@IAgentSessionsService private readonly agentSessionsService: IAgentSessionsService,
30
@IInstantiationService private readonly instantiationService: IInstantiationService,
31
@ICommandService private readonly commandService: ICommandService,
32
) {
33
super(AGENT_SESSIONS_QUICK_ACCESS_PREFIX, {
34
canAcceptInBackground: true,
35
noResultsPick: {
36
label: localize('noAgentSessionResults', "No matching agent sessions")
37
}
38
});
39
40
this.filter = this._register(this.instantiationService.createInstance(AgentSessionsFilter, {}));
41
}
42
43
protected async _getPicks(filter: string): Promise<(IQuickPickSeparator | IPickerQuickAccessItem)[]> {
44
const picks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];
45
46
const sessions = this.agentSessionsService.model.sessions
47
.filter(session => !this.filter.exclude(session))
48
.sort(this.sorter.compare.bind(this.sorter));
49
const groupedSessions = groupAgentSessionsByDate(sessions);
50
51
for (const group of groupedSessions.values()) {
52
if (group.sessions.length > 0) {
53
picks.push({ type: 'separator', label: group.label });
54
55
for (const session of group.sessions) {
56
const highlights = matchesFuzzy(filter, session.label, true);
57
if (highlights) {
58
picks.push(this.toPickItem(session, highlights));
59
}
60
}
61
}
62
}
63
64
return picks;
65
}
66
67
private toPickItem(session: IAgentSession, highlights: IMatch[]): IPickerQuickAccessItem {
68
const description = getSessionDescription(session);
69
const buttons = getSessionButtons(session);
70
71
return {
72
label: session.label,
73
description,
74
highlights: { label: highlights },
75
iconClass: ThemeIcon.asClassName(session.icon),
76
buttons,
77
trigger: async (buttonIndex) => {
78
const button = buttons[buttonIndex];
79
switch (button) {
80
case renameButton:
81
await this.commandService.executeCommand(AGENT_SESSION_RENAME_ACTION_ID, session);
82
return TriggerAction.REFRESH_PICKER;
83
case deleteButton:
84
await this.commandService.executeCommand(AGENT_SESSION_DELETE_ACTION_ID, session);
85
return TriggerAction.REFRESH_PICKER;
86
case archiveButton:
87
case unarchiveButton: {
88
const newArchivedState = !session.isArchived();
89
session.setArchived(newArchivedState);
90
return TriggerAction.REFRESH_PICKER;
91
}
92
default:
93
return TriggerAction.NO_ACTION;
94
}
95
},
96
accept: (keyMods: IKeyMods, event: IQuickPickDidAcceptEvent) => {
97
this.instantiationService.invokeFunction(openSession, session, {
98
sideBySide: event.inBackground,
99
editorOptions: {
100
preserveFocus: event.inBackground,
101
pinned: event.inBackground
102
}
103
});
104
}
105
};
106
}
107
}
108
109