Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/agentFeedback/browser/agentFeedback.contribution.ts
13401 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 './agentFeedbackEditorInputContribution.js';
7
import './agentFeedbackEditorWidgetContribution.js';
8
import './agentFeedbackOverviewRulerContribution.js';
9
import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
10
import { autorun, observableFromEvent } from '../../../../base/common/observable.js';
11
import { localize } from '../../../../nls.js';
12
import { MenuId, MenuRegistry } from '../../../../platform/actions/common/actions.js';
13
import { IContextKeyService, ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
14
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
15
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
16
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
17
import { IsSessionsWindowContext } from '../../../../workbench/common/contextkeys.js';
18
import { AgentFeedbackService, IAgentFeedbackService } from './agentFeedbackService.js';
19
import { AgentFeedbackAttachmentContribution } from './agentFeedbackAttachment.js';
20
import { AgentFeedbackAttachmentWidget } from './agentFeedbackAttachmentWidget.js';
21
import { AgentFeedbackEditorOverlay } from './agentFeedbackEditorOverlay.js';
22
import { hasActiveSessionAgentFeedback, registerAgentFeedbackEditorActions, submitActiveSessionFeedbackActionId } from './agentFeedbackEditorActions.js';
23
import { IChatAttachmentWidgetRegistry } from '../../../../workbench/contrib/chat/browser/attachments/chatAttachmentWidgetRegistry.js';
24
import { IAgentFeedbackVariableEntry } from '../../../../workbench/contrib/chat/common/attachments/chatVariableEntries.js';
25
import { Codicon } from '../../../../base/common/codicons.js';
26
import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';
27
28
/**
29
* Sets the `hasActiveSessionAgentFeedback` context key to true when the
30
* currently active session has pending agent feedback items.
31
*/
32
class ActiveSessionFeedbackContextContribution extends Disposable implements IWorkbenchContribution {
33
34
static readonly ID = 'workbench.contrib.activeSessionFeedbackContext';
35
36
constructor(
37
@IContextKeyService contextKeyService: IContextKeyService,
38
@IAgentFeedbackService agentFeedbackService: IAgentFeedbackService,
39
@ISessionsManagementService sessionManagementService: ISessionsManagementService,
40
) {
41
super();
42
43
const contextKey = hasActiveSessionAgentFeedback.bindTo(contextKeyService);
44
const menuRegistration = this._register(new MutableDisposable());
45
46
const feedbackChanged = observableFromEvent(
47
this,
48
agentFeedbackService.onDidChangeFeedback,
49
e => e,
50
);
51
52
this._register(autorun(reader => {
53
feedbackChanged.read(reader);
54
const activeSession = sessionManagementService.activeSession.read(reader);
55
menuRegistration.clear();
56
if (!activeSession) {
57
contextKey.set(false);
58
return;
59
}
60
const feedback = agentFeedbackService.getFeedback(activeSession.resource);
61
const count = feedback.length;
62
contextKey.set(count > 0);
63
64
if (count > 0) {
65
menuRegistration.value = MenuRegistry.appendMenuItem(MenuId.ChatEditingSessionApplySubmenu, {
66
command: {
67
id: submitActiveSessionFeedbackActionId,
68
icon: Codicon.comment,
69
title: localize('agentFeedback.submitFeedbackCount', "Submit Feedback ({0})", count),
70
},
71
group: 'navigation',
72
order: 3,
73
when: ContextKeyExpr.and(IsSessionsWindowContext, hasActiveSessionAgentFeedback),
74
});
75
}
76
}));
77
}
78
}
79
80
registerWorkbenchContribution2(ActiveSessionFeedbackContextContribution.ID, ActiveSessionFeedbackContextContribution, WorkbenchPhase.AfterRestored);
81
registerWorkbenchContribution2(AgentFeedbackEditorOverlay.ID, AgentFeedbackEditorOverlay, WorkbenchPhase.AfterRestored);
82
registerWorkbenchContribution2(AgentFeedbackAttachmentContribution.ID, AgentFeedbackAttachmentContribution, WorkbenchPhase.AfterRestored);
83
84
registerAgentFeedbackEditorActions();
85
86
registerSingleton(IAgentFeedbackService, AgentFeedbackService, InstantiationType.Delayed);
87
88
// Register the custom attachment widget for agentFeedback attachments
89
class AgentFeedbackAttachmentWidgetContribution {
90
static readonly ID = 'workbench.contrib.agentFeedbackAttachmentWidgetFactory';
91
constructor(
92
@IChatAttachmentWidgetRegistry registry: IChatAttachmentWidgetRegistry,
93
@IInstantiationService instantiationService: IInstantiationService,
94
) {
95
registry.registerFactory('agentFeedback', (attachment, options, container) => {
96
return instantiationService.createInstance(AgentFeedbackAttachmentWidget, attachment as IAgentFeedbackVariableEntry, options, container);
97
});
98
}
99
}
100
registerWorkbenchContribution2(AgentFeedbackAttachmentWidgetContribution.ID, AgentFeedbackAttachmentWidgetContribution, WorkbenchPhase.AfterRestored);
101
102