@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
2
2
import { getSimplifiedSchema , parseSchema } from 'mongodb-schema' ;
3
3
import type { Document } from 'bson' ;
4
4
import type { Reference } from 'mongodb-rag-core' ;
5
+ import util from 'util' ;
5
6
6
7
import { createLogger } from '../logging' ;
7
8
import type ConnectionController from '../connectionController' ;
@@ -138,6 +139,12 @@ export default class ParticipantController {
138
139
errorName = ParticipantErrorTypes . OTHER ;
139
140
}
140
141
142
+ log . error ( 'Participant encountered an error' , {
143
+ command,
144
+ error_code : errorCode ,
145
+ error_name : errorName ,
146
+ } ) ;
147
+
141
148
this . _telemetryService . track (
142
149
TelemetryEventTypes . PARTICIPANT_RESPONSE_FAILED ,
143
150
{
@@ -177,9 +184,26 @@ export default class ParticipantController {
177
184
throw new Error ( 'Copilot model not found' ) ;
178
185
}
179
186
187
+ log . info ( 'Sending request to model' , {
188
+ messages : modelInput . messages . map (
189
+ ( message : vscode . LanguageModelChatMessage ) =>
190
+ util . inspect ( {
191
+ role : message . role ,
192
+ contentLength : message . content . length ,
193
+ } )
194
+ ) ,
195
+ } ) ;
180
196
this . _telemetryService . trackCopilotParticipantPrompt ( modelInput . stats ) ;
181
197
182
- return await model . sendRequest ( modelInput . messages , { } , token ) ;
198
+ const modelResponse = await model . sendRequest (
199
+ modelInput . messages ,
200
+ { } ,
201
+ token
202
+ ) ;
203
+
204
+ log . info ( 'Model response received' ) ;
205
+
206
+ return modelResponse ;
183
207
}
184
208
185
209
async streamChatResponse ( {
@@ -267,6 +291,11 @@ export default class ParticipantController {
267
291
identifier : codeBlockIdentifier ,
268
292
} ) ;
269
293
294
+ log . info ( 'Streamed response to chat' , {
295
+ outputLength,
296
+ hasCodeBlock,
297
+ } ) ;
298
+
270
299
return {
271
300
outputLength,
272
301
hasCodeBlock,
@@ -376,6 +405,10 @@ export default class ParticipantController {
376
405
token,
377
406
} ) ;
378
407
408
+ log . info ( 'Received intent response from model' , {
409
+ responseContentLength : responseContent . length ,
410
+ } ) ;
411
+
379
412
return Prompts . intent . getIntentFromModelResponse ( responseContent ) ;
380
413
}
381
414
@@ -738,14 +771,41 @@ export default class ParticipantController {
738
771
request,
739
772
connectionNames : this . _getConnectionNames ( ) ,
740
773
} ) ;
741
- const responseContentWithNamespace = await this . getChatResponseContent ( {
742
- modelInput : messagesWithNamespace ,
743
- token,
744
- } ) ;
745
- const { databaseName, collectionName } =
746
- Prompts . namespace . extractDatabaseAndCollectionNameFromResponse (
747
- responseContentWithNamespace
748
- ) ;
774
+
775
+ let {
776
+ databaseName,
777
+ collectionName,
778
+ } : {
779
+ databaseName : string | undefined ;
780
+ collectionName : string | undefined ;
781
+ } = {
782
+ databaseName : undefined ,
783
+ collectionName : undefined ,
784
+ } ;
785
+
786
+ // When there's no user message content we can
787
+ // skip the request to the model. This would happen with /schema.
788
+ if ( Prompts . doMessagesContainUserInput ( messagesWithNamespace . messages ) ) {
789
+ // VSCODE-626: When there's an empty message sent to the ai model,
790
+ // it currently errors (not on insiders, only main VSCode).
791
+ // Here we're defaulting to have some content as a workaround.
792
+ // TODO: Remove this when the issue is fixed.
793
+ messagesWithNamespace . messages [
794
+ messagesWithNamespace . messages . length - 1
795
+ ] . content =
796
+ messagesWithNamespace . messages [
797
+ messagesWithNamespace . messages . length - 1
798
+ ] . content . trim ( ) || 'see previous messages' ;
799
+
800
+ const responseContentWithNamespace = await this . getChatResponseContent ( {
801
+ modelInput : messagesWithNamespace ,
802
+ token,
803
+ } ) ;
804
+ ( { databaseName, collectionName } =
805
+ Prompts . namespace . extractDatabaseAndCollectionNameFromResponse (
806
+ responseContentWithNamespace
807
+ ) ) ;
808
+ }
749
809
750
810
// See if there's a namespace set in the
751
811
// chat metadata we can fallback to if the model didn't find it.
@@ -757,6 +817,11 @@ export default class ParticipantController {
757
817
collectionName : collectionNameFromMetadata ,
758
818
} = this . _chatMetadataStore . getChatMetadata ( chatId ) ?? { } ;
759
819
820
+ log . info ( 'Namespaces found in chat' , {
821
+ databaseName : databaseName || databaseNameFromMetadata ,
822
+ collectionName : collectionName || collectionNameFromMetadata ,
823
+ } ) ;
824
+
760
825
return {
761
826
databaseName : databaseName || databaseNameFromMetadata ,
762
827
collectionName : collectionName || collectionNameFromMetadata ,
@@ -831,6 +896,8 @@ export default class ParticipantController {
831
896
context : vscode . ChatContext ;
832
897
stream : vscode . ChatResponseStream ;
833
898
} ) : ChatResult {
899
+ log . info ( 'Participant asked user to connect' ) ;
900
+
834
901
stream . markdown (
835
902
"Looks like you aren't currently connected, first let's get you connected to the cluster we'd like to create this query to run against.\n\n"
836
903
) ;
0 commit comments