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