@@ -38,6 +38,7 @@ export const AIChatInputConfiguration = Symbol('AIChatInputConfiguration');
38
38
export interface AIChatInputConfiguration {
39
39
showContext ?: boolean ;
40
40
showPinnedAgent ?: boolean ;
41
+ showChangeSet ?: boolean ;
41
42
}
42
43
43
44
@injectable ( )
@@ -70,7 +71,7 @@ export class AIChatInputWidget extends ReactWidget {
70
71
protected readonly changeSetActionService : ChangeSetActionService ;
71
72
72
73
protected editorRef : MonacoEditor | undefined = undefined ;
73
- private editorReady = new Deferred < void > ( ) ;
74
+ protected readonly editorReady = new Deferred < void > ( ) ;
74
75
75
76
protected isEnabled = false ;
76
77
@@ -95,6 +96,11 @@ export class AIChatInputWidget extends ReactWidget {
95
96
this . _onDeleteChangeSetElement = deleteChangeSetElement ;
96
97
}
97
98
99
+ private _initialValue ?: string ;
100
+ set initialValue ( value : string | undefined ) {
101
+ this . _initialValue = value ;
102
+ }
103
+
98
104
protected onDisposeForChatModel = new DisposableCollection ( ) ;
99
105
private _chatModel : ChatModel ;
100
106
set chatModel ( chatModel : ChatModel ) {
@@ -130,6 +136,10 @@ export class AIChatInputWidget extends ReactWidget {
130
136
} ) ;
131
137
}
132
138
139
+ protected getResourceUri ( ) : URI {
140
+ return new URI ( `ai-chat:/input.${ CHAT_VIEW_LANGUAGE_EXTENSION } ` ) ;
141
+ }
142
+
133
143
protected render ( ) : React . ReactNode {
134
144
return (
135
145
< ChatInput
@@ -142,11 +152,12 @@ export class AIChatInputWidget extends ReactWidget {
142
152
onDeleteChangeSetElement = { this . _onDeleteChangeSetElement . bind ( this ) }
143
153
onAddContextElement = { this . addContextElement . bind ( this ) }
144
154
onDeleteContextElement = { this . deleteContextElement . bind ( this ) }
145
- context = { this . _chatModel . context . getVariables ( ) }
155
+ context = { this . getContext ( ) }
146
156
chatModel = { this . _chatModel }
147
157
pinnedAgent = { this . _pinnedAgent }
148
158
editorProvider = { this . editorProvider }
149
159
resources = { this . resources }
160
+ resourceUriProvider = { this . getResourceUri . bind ( this ) }
150
161
contextMenuCallback = { this . handleContextMenu . bind ( this ) }
151
162
isEnabled = { this . isEnabled }
152
163
setEditorRef = { editor => {
@@ -155,8 +166,10 @@ export class AIChatInputWidget extends ReactWidget {
155
166
} }
156
167
showContext = { this . configuration ?. showContext }
157
168
showPinnedAgent = { this . configuration ?. showPinnedAgent }
169
+ showChangeSet = { this . configuration ?. showChangeSet }
158
170
labelProvider = { this . labelProvider }
159
171
actionService = { this . changeSetActionService }
172
+ initialValue = { this . _initialValue }
160
173
/>
161
174
) ;
162
175
}
@@ -203,7 +216,7 @@ export class AIChatInputWidget extends ReactWidget {
203
216
protected addContextElement ( ) : void {
204
217
this . contextVariablePicker . pickContextVariable ( ) . then ( contextElement => {
205
218
if ( contextElement ) {
206
- this . _chatModel . context . addVariables ( contextElement ) ;
219
+ this . addContext ( contextElement ) ;
207
220
}
208
221
} ) ;
209
222
}
@@ -225,6 +238,10 @@ export class AIChatInputWidget extends ReactWidget {
225
238
addContext ( variable : AIVariableResolutionRequest ) : void {
226
239
this . _chatModel . context . addVariables ( variable ) ;
227
240
}
241
+
242
+ protected getContext ( ) : readonly AIVariableResolutionRequest [ ] {
243
+ return this . _chatModel . context . getVariables ( ) ;
244
+ }
228
245
}
229
246
230
247
interface ChatInputProperties {
@@ -243,12 +260,15 @@ interface ChatInputProperties {
243
260
pinnedAgent ?: ChatAgent ;
244
261
editorProvider : MonacoEditorProvider ;
245
262
resources : InMemoryResources ;
263
+ resourceUriProvider : ( ) => URI ;
246
264
contextMenuCallback : ( event : IMouseEvent ) => void ;
247
265
setEditorRef : ( editor : MonacoEditor | undefined ) => void ;
248
266
showContext ?: boolean ;
249
267
showPinnedAgent ?: boolean ;
268
+ showChangeSet ?: boolean ;
250
269
labelProvider : LabelProvider ;
251
270
actionService : ChangeSetActionService ;
271
+ initialValue ?: string ;
252
272
}
253
273
254
274
const ChatInput : React . FunctionComponent < ChatInputProperties > = ( props : ChatInputProperties ) => {
@@ -276,7 +296,7 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
276
296
const editorRef = React . useRef < MonacoEditor | undefined > ( undefined ) ;
277
297
278
298
React . useEffect ( ( ) => {
279
- const uri = new URI ( `ai-chat:/input. ${ CHAT_VIEW_LANGUAGE_EXTENSION } ` ) ;
299
+ const uri = props . resourceUriProvider ( ) ;
280
300
const resource = props . resources . add ( uri , '' ) ;
281
301
const createInputElement = async ( ) => {
282
302
const paddingTop = 6 ;
@@ -323,6 +343,7 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
323
343
editorContainerRef . current . style . height = `${ Math . min ( contentHeight , maxHeight ) } px` ;
324
344
}
325
345
} ;
346
+
326
347
editor . getControl ( ) . onDidChangeModelContent ( ( ) => {
327
348
const value = editor . getControl ( ) . getValue ( ) ;
328
349
setIsInputEmpty ( ! value || value . length === 0 ) ;
@@ -343,6 +364,10 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
343
364
344
365
editorRef . current = editor ;
345
366
props . setEditorRef ( editor ) ;
367
+
368
+ if ( props . initialValue ) {
369
+ setValue ( props . initialValue ) ;
370
+ }
346
371
} ;
347
372
createInputElement ( ) ;
348
373
@@ -408,16 +433,20 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
408
433
return ( ) => disposable . dispose ( ) ;
409
434
} ) ;
410
435
436
+ const setValue = React . useCallback ( ( value : string ) => {
437
+ if ( editorRef . current && ! editorRef . current . document . isDisposed ( ) ) {
438
+ editorRef . current . document . textEditorModel . setValue ( value ) ;
439
+ }
440
+ } , [ editorRef ] ) ;
441
+
411
442
const submit = React . useCallback ( function submit ( value : string ) : void {
412
443
if ( ! value || value . trim ( ) . length === 0 ) {
413
444
return ;
414
445
}
415
446
setInProgress ( true ) ;
416
447
props . onQuery ( value ) ;
417
- if ( editorRef . current ) {
418
- editorRef . current . document . textEditorModel . setValue ( '' ) ;
419
- }
420
- } , [ props . context , props . onQuery , editorRef ] ) ;
448
+ setValue ( '' ) ;
449
+ } , [ props . context , props . onQuery , setValue ] ) ;
421
450
422
451
const onKeyDown = React . useCallback ( ( event : React . KeyboardEvent ) => {
423
452
if ( ! props . isEnabled ) {
@@ -518,7 +547,7 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
518
547
const contextUI = buildContextUI ( props . context , props . labelProvider , props . onDeleteContextElement ) ;
519
548
520
549
return < div className = 'theia-ChatInput' onDragOver = { props . onDragOver } onDrop = { props . onDrop } >
521
- { changeSetUI ?. elements &&
550
+ { props . showChangeSet && changeSetUI ?. elements &&
522
551
< ChangeSetBox changeSet = { changeSetUI } />
523
552
}
524
553
< div className = 'theia-ChatInput-Editor-Box' >
0 commit comments