@@ -50,12 +50,12 @@ import { IChatAgentService } from '../../common/chatAgents.js';
50
50
import { ChatContextKeys } from '../../common/chatContextKeys.js' ;
51
51
import { IChatEditingSession , ModifiedFileEntryState } from '../../common/chatEditingService.js' ;
52
52
import { ChatEntitlement , IChatEntitlementService } from '../../common/chatEntitlementService.js' ;
53
- import { ChatMode , IChatMode } from '../../common/chatModes.js' ;
53
+ import { ChatMode , IChatMode , IChatModeService } from '../../common/chatModes.js' ;
54
54
import { extractAgentAndCommand } from '../../common/chatParserTypes.js' ;
55
55
import { IChatDetail , IChatService } from '../../common/chatService.js' ;
56
56
import { IChatRequestViewModel , IChatResponseViewModel , isRequestVM } from '../../common/chatViewModel.js' ;
57
57
import { IChatWidgetHistoryService } from '../../common/chatWidgetHistoryService.js' ;
58
- import { ChatAgentLocation , ChatConfiguration , ChatModeKind , validateChatMode } from '../../common/constants.js' ;
58
+ import { ChatAgentLocation , ChatConfiguration , ChatModeKind } from '../../common/constants.js' ;
59
59
import { CopilotUsageExtensionFeatureId } from '../../common/languageModelStats.js' ;
60
60
import { ILanguageModelToolsService } from '../../common/languageModelToolsService.js' ;
61
61
import { ChatViewId , IChatWidget , IChatWidgetService , showChatView , showCopilotView } from '../chat.js' ;
@@ -100,9 +100,9 @@ export interface IChatViewOpenOptions {
100
100
*/
101
101
attachFiles ?: URI [ ] ;
102
102
/**
103
- * The mode to open the chat in.
103
+ * The mode ID or name to open the chat in.
104
104
*/
105
- mode ?: ChatModeKind ;
105
+ mode ?: ChatModeKind | string ;
106
106
}
107
107
108
108
export interface IChatViewOpenRequestEntry {
@@ -139,6 +139,7 @@ abstract class OpenChatGlobalAction extends Action2 {
139
139
const chatAgentService = accessor . get ( IChatAgentService ) ;
140
140
const instaService = accessor . get ( IInstantiationService ) ;
141
141
const commandService = accessor . get ( ICommandService ) ;
142
+ const chatModeService = accessor . get ( IChatModeService ) ;
142
143
143
144
let chatWidget = widgetService . lastFocusedWidget ;
144
145
// When this was invoked to switch to a mode via keybinding, and some chat widget is focused, use that one.
@@ -151,11 +152,12 @@ abstract class OpenChatGlobalAction extends Action2 {
151
152
return ;
152
153
}
153
154
154
- let switchToMode = opts ?. mode ?? this . mode ;
155
+ const switchToModeInput = opts ?. mode ?? this . mode ;
156
+ let switchToMode = switchToModeInput && ( chatModeService . findModeById ( switchToModeInput ) ?? chatModeService . findModeByName ( switchToModeInput ) ) ;
155
157
if ( ! switchToMode ) {
156
- switchToMode = opts ?. query ?. startsWith ( '@' ) ? ChatModeKind . Ask : undefined ;
158
+ switchToMode = opts ?. query ?. startsWith ( '@' ) ? ChatMode . Ask : undefined ;
157
159
}
158
- if ( switchToMode && validateChatMode ( switchToMode ) ) {
160
+ if ( switchToMode ) {
159
161
await this . handleSwitchToMode ( switchToMode , chatWidget , instaService , commandService ) ;
160
162
}
161
163
@@ -203,17 +205,17 @@ abstract class OpenChatGlobalAction extends Action2 {
203
205
chatWidget . focusInput ( ) ;
204
206
}
205
207
206
- private async handleSwitchToMode ( switchToMode : ChatModeKind , chatWidget : IChatWidget , instaService : IInstantiationService , commandService : ICommandService ) : Promise < void > {
208
+ private async handleSwitchToMode ( switchToMode : IChatMode , chatWidget : IChatWidget , instaService : IInstantiationService , commandService : ICommandService ) : Promise < void > {
207
209
const currentMode = chatWidget . input . currentModeKind ;
208
210
209
211
if ( switchToMode ) {
210
212
const editingSession = chatWidget . viewModel ?. model . editingSession ;
211
213
const requestCount = chatWidget . viewModel ?. model . getRequests ( ) . length ?? 0 ;
212
- const chatModeCheck = await instaService . invokeFunction ( handleModeSwitch , currentMode , switchToMode , requestCount , editingSession ) ;
214
+ const chatModeCheck = await instaService . invokeFunction ( handleModeSwitch , currentMode , switchToMode . kind , requestCount , editingSession ) ;
213
215
if ( ! chatModeCheck ) {
214
216
return ;
215
217
}
216
- chatWidget . input . setChatMode ( switchToMode ) ;
218
+ chatWidget . input . setChatMode ( switchToMode . id ) ;
217
219
218
220
if ( chatModeCheck . needToClearSession ) {
219
221
await commandService . executeCommand ( ACTION_ID_NEW_CHAT ) ;
0 commit comments