@@ -15,7 +15,7 @@ import { KeybindingWeight } from '../../../../../platform/keybinding/common/keyb
15
15
import { ActiveEditorContext } from '../../../../common/contextkeys.js' ;
16
16
import { IViewsService } from '../../../../services/views/common/viewsService.js' ;
17
17
import { isChatViewTitleActionContext } from '../../common/chatActions.js' ;
18
- import { ChatAgentLocation } from '../../common/chatAgents.js' ;
18
+ import { ChatAgentLocation , IChatAgentService } from '../../common/chatAgents.js' ;
19
19
import { ChatContextKeys } from '../../common/chatContextKeys.js' ;
20
20
import { hasAppliedChatEditsContextKey , hasUndecidedChatEditingResourceContextKey , IChatEditingSession , WorkingSetEntryState } from '../../common/chatEditingService.js' ;
21
21
import { ChatViewId , EditsViewId , IChatWidget , IChatWidgetService } from '../chat.js' ;
@@ -30,6 +30,24 @@ export const ACTION_ID_NEW_CHAT = `workbench.action.chat.newChat`;
30
30
export const ACTION_ID_NEW_EDIT_SESSION = `workbench.action.chat.newEditSession` ;
31
31
export const ChatDoneActionId = 'workbench.action.chat.done' ;
32
32
33
+ export interface INewEditSessionActionContext {
34
+ /**
35
+ * An initial prompt to write to the chat.
36
+ */
37
+ inputValue ?: string ;
38
+
39
+ /**
40
+ * Selects opening in agent mode or not. If not set, the current mode is used.
41
+ * This is ignored when coming from a chat view title context.
42
+ */
43
+ agentMode ?: boolean ;
44
+
45
+ /**
46
+ * Whether the inputValue is partial and should wait for further user input. If false or not set, the prompt is sent immediately.
47
+ */
48
+ isPartialQuery ?: boolean ;
49
+ }
50
+
33
51
export function registerNewChatActions ( ) {
34
52
registerAction2 ( class NewChatEditorAction extends Action2 {
35
53
constructor ( ) {
@@ -175,34 +193,54 @@ export function registerNewChatActions() {
175
193
}
176
194
177
195
async runEditingSessionAction ( accessor : ServicesAccessor , editingSession : IChatEditingSession , chatWidget : IChatWidget , ...args : any [ ] ) {
178
- const context = args [ 0 ] ;
196
+ const context : INewEditSessionActionContext | undefined = args [ 0 ] ;
179
197
const accessibilitySignalService = accessor . get ( IAccessibilitySignalService ) ;
180
198
const widgetService = accessor . get ( IChatWidgetService ) ;
181
199
const dialogService = accessor . get ( IDialogService ) ;
182
200
const viewsService = accessor . get ( IViewsService ) ;
201
+ const agentService = accessor . get ( IChatAgentService ) ;
202
+
183
203
if ( ! ( await this . _handleCurrentEditingSession ( editingSession , dialogService ) ) ) {
184
204
return ;
185
205
}
186
- if ( isChatViewTitleActionContext ( context ) ) {
206
+
207
+ const isChatViewTitleAction = isChatViewTitleActionContext ( context ) ;
208
+
209
+ let widget : IChatWidget | undefined ;
210
+ if ( isChatViewTitleAction ) {
187
211
// Is running in the Chat view title
188
- announceChatCleared ( accessibilitySignalService ) ;
189
- const widget = widgetService . getWidgetBySessionId ( context . sessionId ) ;
190
- if ( widget ) {
191
- await editingSession . stop ( true ) ;
192
- widget . clear ( ) ;
193
- widget . attachmentModel . clear ( ) ;
194
- widget . focusInput ( ) ;
195
- }
212
+ widget = widgetService . getWidgetBySessionId ( context . sessionId ) ;
196
213
} else {
197
214
// Is running from f1 or keybinding
198
215
const chatView = await viewsService . openView ( EditsViewId ) as ChatViewPane ;
199
- const widget = chatView . widget ;
216
+ widget = chatView . widget ;
217
+ }
200
218
201
- announceChatCleared ( accessibilitySignalService ) ;
202
- await editingSession . stop ( true ) ;
203
- widget . clear ( ) ;
204
- widget . attachmentModel . clear ( ) ;
205
- widget . focusInput ( ) ;
219
+ announceChatCleared ( accessibilitySignalService ) ;
220
+
221
+ if ( ! widget ) {
222
+ return ;
223
+ }
224
+
225
+ await editingSession . stop ( true ) ;
226
+ widget . clear ( ) ;
227
+ widget . attachmentModel . clear ( ) ;
228
+ widget . focusInput ( ) ;
229
+
230
+ if ( ! context ) {
231
+ return ;
232
+ }
233
+
234
+ if ( ! isChatViewTitleAction && typeof context . agentMode === 'boolean' ) {
235
+ agentService . toggleToolsAgentMode ( context . agentMode ) ;
236
+ }
237
+
238
+ if ( context . inputValue ) {
239
+ if ( context . isPartialQuery ) {
240
+ widget . setInput ( context . inputValue ) ;
241
+ } else {
242
+ widget . acceptInput ( context . inputValue ) ;
243
+ }
206
244
}
207
245
}
208
246
} ) ;
0 commit comments