@@ -9,8 +9,10 @@ import { IHistoryNavigationWidget } from '../../../../base/browser/history.js';
9
9
import { StandardKeyboardEvent } from '../../../../base/browser/keyboardEvent.js' ;
10
10
import * as aria from '../../../../base/browser/ui/aria/aria.js' ;
11
11
import { Button } from '../../../../base/browser/ui/button/button.js' ;
12
+ import { renderLabelWithIcons } from '../../../../base/browser/ui/iconLabel/iconLabels.js' ;
13
+ import { IAction } from '../../../../base/common/actions.js' ;
12
14
import { Codicon } from '../../../../base/common/codicons.js' ;
13
- import { Emitter } from '../../../../base/common/event.js' ;
15
+ import { Emitter , Event } from '../../../../base/common/event.js' ;
14
16
import { HistoryNavigator2 } from '../../../../base/common/history.js' ;
15
17
import { KeyCode } from '../../../../base/common/keyCodes.js' ;
16
18
import { Disposable , DisposableStore } from '../../../../base/common/lifecycle.js' ;
@@ -35,24 +37,27 @@ import { HiddenItemStrategy, MenuWorkbenchToolBar } from '../../../../platform/a
35
37
import { MenuId , MenuItemAction } from '../../../../platform/actions/common/actions.js' ;
36
38
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js' ;
37
39
import { IContextKey , IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js' ;
40
+ import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js' ;
38
41
import { FileKind } from '../../../../platform/files/common/files.js' ;
39
42
import { registerAndCreateHistoryNavigationContext } from '../../../../platform/history/browser/contextScopedHistoryWidget.js' ;
40
43
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js' ;
41
44
import { ServiceCollection } from '../../../../platform/instantiation/common/serviceCollection.js' ;
42
45
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js' ;
43
46
import { ILogService } from '../../../../platform/log/common/log.js' ;
47
+ import { INotificationService } from '../../../../platform/notification/common/notification.js' ;
48
+ import { IThemeService } from '../../../../platform/theme/common/themeService.js' ;
44
49
import { ResourceLabels } from '../../../browser/labels.js' ;
45
50
import { AccessibilityVerbositySettingId } from '../../accessibility/browser/accessibilityConfiguration.js' ;
46
51
import { AccessibilityCommandId } from '../../accessibility/common/accessibilityCommands.js' ;
47
52
import { getSimpleCodeEditorWidgetOptions , getSimpleEditorOptions , setupSimpleEditorSelectionStyling } from '../../codeEditor/browser/simpleEditorOptions.js' ;
48
53
import { ChatAgentLocation } from '../common/aideAgentAgents.js' ;
49
54
import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP , CONTEXT_CHAT_INPUT_HAS_FOCUS , CONTEXT_CHAT_INPUT_HAS_TEXT , CONTEXT_IN_CHAT_INPUT } from '../common/aideAgentContextKeys.js' ;
50
- import { IChatRequestVariableEntry } from '../common/aideAgentModel.js' ;
55
+ import { AgentMode , IChatRequestVariableEntry } from '../common/aideAgentModel.js' ;
51
56
import { IChatFollowup } from '../common/aideAgentService.js' ;
52
57
import { IChatResponseViewModel } from '../common/aideAgentViewModel.js' ;
53
58
import { IAideAgentWidgetHistoryService , IChatHistoryEntry } from '../common/aideAgentWidgetHistoryService.js' ;
54
59
import { IAideAgentLMService } from '../common/languageModels.js' ;
55
- import { CancelAction , IChatExecuteActionContext , SubmitAction } from './actions/aideAgentExecuteActions.js' ;
60
+ import { AgentModePickerActionId , CancelAction , IChatExecuteActionContext , SubmitAction } from './actions/aideAgentExecuteActions.js' ;
56
61
import { IChatWidget } from './aideAgent.js' ;
57
62
import { ChatFollowups } from './aideAgentFollowups.js' ;
58
63
@@ -146,6 +151,12 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
146
151
return metadataId ;
147
152
}
148
153
154
+ private _onDidChangeCurrentAgentMode = new Emitter < string > ( ) ;
155
+ private _currentAgentMode : AgentMode = AgentMode . Edit ;
156
+ get currentAgentMode ( ) {
157
+ return this . _currentAgentMode ;
158
+ }
159
+
149
160
private cachedDimensions : dom . Dimension | undefined ;
150
161
private cachedExecuteToolbarWidth : number | undefined ;
151
162
private cachedInputToolbarWidth : number | undefined ;
@@ -484,6 +495,16 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
484
495
menuOptions : { shouldForwardArgs : true } ,
485
496
hiddenItemStrategy : HiddenItemStrategy . Ignore ,
486
497
actionViewItemProvider : ( action , options ) => {
498
+ if ( action . id === AgentModePickerActionId && action instanceof MenuItemAction ) {
499
+ const itemDelegate : AgentModeSetterDelegate = {
500
+ onDidChangeMode : this . _onDidChangeCurrentAgentMode . event ,
501
+ setMode : ( modeId : string ) => {
502
+ this . _currentAgentMode = modeId as AgentMode ;
503
+ }
504
+ } ;
505
+ return this . instantiationService . createInstance ( AgentModeActionViewItem , action , this . _currentAgentMode , itemDelegate ) ;
506
+ }
507
+
487
508
if ( action instanceof MenuItemAction ) {
488
509
return this . instantiationService . createInstance ( MenuEntryActionViewItem , action , undefined ) ;
489
510
}
@@ -717,5 +738,73 @@ function getLastPosition(model: ITextModel): IPosition {
717
738
return { lineNumber : model . getLineCount ( ) , column : model . getLineLength ( model . getLineCount ( ) ) + 1 } ;
718
739
}
719
740
741
+ interface AgentModeSetterDelegate {
742
+ onDidChangeMode : Event < string > ;
743
+ setMode ( selectedModeId : string ) : void ;
744
+ }
745
+
746
+ class AgentModeActionViewItem extends MenuEntryActionViewItem {
747
+ constructor (
748
+ action : MenuItemAction ,
749
+ private currentAgentMode : AgentMode ,
750
+ private delegate : AgentModeSetterDelegate ,
751
+ @IKeybindingService keybindingService : IKeybindingService ,
752
+ @INotificationService notificationService : INotificationService ,
753
+ @IContextKeyService contextKeyService : IContextKeyService ,
754
+ @IThemeService themeService : IThemeService ,
755
+ @IContextMenuService contextMenuService : IContextMenuService ,
756
+ @IAccessibilityService _accessibilityService : IAccessibilityService
757
+ ) {
758
+ super ( action , undefined , keybindingService , notificationService , contextKeyService , themeService , contextMenuService , _accessibilityService ) ;
759
+
760
+ this . _register ( delegate . onDidChangeMode ( modeId => {
761
+ this . currentAgentMode = modeId as AgentMode ;
762
+ this . updateLabel ( ) ;
763
+ } ) ) ;
764
+ }
765
+
766
+ override async onClick ( ) : Promise < void > {
767
+ this . _openContextMenu ( ) ;
768
+ }
769
+
770
+ override render ( container : HTMLElement ) : void {
771
+ super . render ( container ) ;
772
+ container . classList . add ( 'agentmode-picker-item' ) ;
773
+ }
774
+
775
+ protected override updateLabel ( ) : void {
776
+ if ( this . label ) {
777
+ this . label . textContent = this . currentAgentMode ;
778
+ dom . reset ( this . label , ...renderLabelWithIcons ( `${ this . currentAgentMode } $(chevron-down)` ) ) ;
779
+ }
780
+ }
781
+
782
+ private _openContextMenu ( ) {
783
+ const setAgentModeAction = ( mode : string ) : IAction => {
784
+ return {
785
+ id : mode ,
786
+ label : mode ,
787
+ tooltip : '' ,
788
+ class : undefined ,
789
+ enabled : true ,
790
+ checked : mode === this . currentAgentMode ,
791
+ run : ( ) => {
792
+ this . currentAgentMode = mode as AgentMode ;
793
+ this . delegate . setMode ( mode ) ;
794
+ this . updateLabel ( ) ;
795
+ }
796
+ } ;
797
+ } ;
798
+
799
+ this . _contextMenuService . showContextMenu ( {
800
+ getAnchor : ( ) => this . element ! ,
801
+ getActions : ( ) => [
802
+ setAgentModeAction ( 'Edit' ) ,
803
+ setAgentModeAction ( 'Chat' ) ,
804
+ ]
805
+ } ) ;
806
+ }
807
+ }
808
+
720
809
const chatInputEditorContainerSelector = '.interactive-input-editor' ;
721
810
setupSimpleEditorSelectionStyling ( chatInputEditorContainerSelector ) ;
0 commit comments