@@ -190,14 +190,21 @@ export default class ParticipantController {
190
190
modelInput : ModelInput ;
191
191
stream : vscode . ChatResponseStream ;
192
192
token : vscode . CancellationToken ;
193
- } ) : Promise < void > {
193
+ } ) : Promise < { outputLength : number } > {
194
194
const chatResponse = await this . _getChatResponse ( {
195
195
modelInput,
196
196
token,
197
197
} ) ;
198
+
199
+ let length = 0 ;
198
200
for await ( const fragment of chatResponse . text ) {
199
201
stream . markdown ( fragment ) ;
202
+ length += fragment . length ;
200
203
}
204
+
205
+ return {
206
+ outputLength : length ,
207
+ } ;
201
208
}
202
209
203
210
_streamCodeBlockActions ( {
@@ -236,22 +243,34 @@ export default class ParticipantController {
236
243
modelInput : ModelInput ;
237
244
stream : vscode . ChatResponseStream ;
238
245
token : vscode . CancellationToken ;
239
- } ) : Promise < void > {
246
+ } ) : Promise < {
247
+ outputLength : number ;
248
+ hasCodeBlock : boolean ;
249
+ } > {
240
250
const chatResponse = await this . _getChatResponse ( {
241
251
modelInput,
242
252
token,
243
253
} ) ;
244
254
255
+ let outputLength = 0 ;
256
+ let hasCodeBlock = false ;
245
257
await processStreamWithIdentifiers ( {
246
258
processStreamFragment : ( fragment : string ) => {
247
259
stream . markdown ( fragment ) ;
260
+ outputLength += fragment . length ;
248
261
} ,
249
262
onStreamIdentifier : ( content : string ) => {
250
263
this . _streamCodeBlockActions ( { runnableContent : content , stream } ) ;
264
+ hasCodeBlock = true ;
251
265
} ,
252
266
inputIterable : chatResponse . text ,
253
267
identifier : codeBlockIdentifier ,
254
268
} ) ;
269
+
270
+ return {
271
+ outputLength,
272
+ hasCodeBlock,
273
+ } ;
255
274
}
256
275
257
276
// This will stream all of the response content and create a string from it.
@@ -287,10 +306,19 @@ export default class ParticipantController {
287
306
connectionNames : this . _getConnectionNames ( ) ,
288
307
} ) ;
289
308
290
- await this . streamChatResponseContentWithCodeActions ( {
291
- modelInput,
292
- token,
293
- stream,
309
+ const { hasCodeBlock, outputLength } =
310
+ await this . streamChatResponseContentWithCodeActions ( {
311
+ modelInput,
312
+ token,
313
+ stream,
314
+ } ) ;
315
+
316
+ this . _telemetryService . trackCopilotParticipantResponse ( {
317
+ command : 'generic' ,
318
+ has_cta : false ,
319
+ found_namespace : false ,
320
+ has_runnable_content : hasCodeBlock ,
321
+ output_length : outputLength ,
294
322
} ) ;
295
323
296
324
return genericRequestChatResult ( context . history ) ;
@@ -995,6 +1023,7 @@ export default class ParticipantController {
995
1023
context,
996
1024
token,
997
1025
} ) ;
1026
+
998
1027
if ( ! databaseName || ! collectionName ) {
999
1028
return await this . _askForNamespace ( {
1000
1029
command : '/schema' ,
@@ -1056,7 +1085,7 @@ export default class ParticipantController {
1056
1085
connectionNames : this . _getConnectionNames ( ) ,
1057
1086
...( sampleDocuments ? { sampleDocuments } : { } ) ,
1058
1087
} ) ;
1059
- await this . streamChatResponse ( {
1088
+ const response = await this . streamChatResponse ( {
1060
1089
modelInput,
1061
1090
stream,
1062
1091
token,
@@ -1072,6 +1101,14 @@ export default class ParticipantController {
1072
1101
] ,
1073
1102
} ) ;
1074
1103
1104
+ this . _telemetryService . trackCopilotParticipantResponse ( {
1105
+ command : 'schema' ,
1106
+ has_cta : true ,
1107
+ found_namespace : true ,
1108
+ has_runnable_content : false ,
1109
+ output_length : response . outputLength ,
1110
+ } ) ;
1111
+
1075
1112
return schemaRequestChatResult ( context . history ) ;
1076
1113
}
1077
1114
@@ -1160,10 +1197,19 @@ export default class ParticipantController {
1160
1197
...( sampleDocuments ? { sampleDocuments } : { } ) ,
1161
1198
} ) ;
1162
1199
1163
- await this . streamChatResponseContentWithCodeActions ( {
1164
- modelInput,
1165
- stream,
1166
- token,
1200
+ const { hasCodeBlock, outputLength } =
1201
+ await this . streamChatResponseContentWithCodeActions ( {
1202
+ modelInput,
1203
+ stream,
1204
+ token,
1205
+ } ) ;
1206
+
1207
+ this . _telemetryService . trackCopilotParticipantResponse ( {
1208
+ command : 'query' ,
1209
+ has_cta : false ,
1210
+ found_namespace : true ,
1211
+ has_runnable_content : hasCodeBlock ,
1212
+ output_length : outputLength ,
1167
1213
} ) ;
1168
1214
1169
1215
return queryRequestChatResult ( context . history ) ;
@@ -1239,11 +1285,12 @@ export default class ParticipantController {
1239
1285
connectionNames : this . _getConnectionNames ( ) ,
1240
1286
} ) ;
1241
1287
1242
- await this . streamChatResponseContentWithCodeActions ( {
1243
- modelInput,
1244
- stream,
1245
- token,
1246
- } ) ;
1288
+ const { hasCodeBlock, outputLength } =
1289
+ await this . streamChatResponseContentWithCodeActions ( {
1290
+ modelInput,
1291
+ stream,
1292
+ token,
1293
+ } ) ;
1247
1294
1248
1295
this . _streamResponseReference ( {
1249
1296
reference : {
@@ -1252,6 +1299,14 @@ export default class ParticipantController {
1252
1299
} ,
1253
1300
stream,
1254
1301
} ) ;
1302
+
1303
+ this . _telemetryService . trackCopilotParticipantResponse ( {
1304
+ command : 'docs/copilot' ,
1305
+ has_cta : true ,
1306
+ found_namespace : false ,
1307
+ has_runnable_content : hasCodeBlock ,
1308
+ output_length : outputLength ,
1309
+ } ) ;
1255
1310
}
1256
1311
1257
1312
_streamResponseReference ( {
@@ -1307,6 +1362,14 @@ export default class ParticipantController {
1307
1362
if ( docsResult . responseContent ) {
1308
1363
stream . markdown ( docsResult . responseContent ) ;
1309
1364
}
1365
+
1366
+ this . _telemetryService . trackCopilotParticipantResponse ( {
1367
+ command : 'docs/chatbot' ,
1368
+ has_cta : ! ! docsResult . responseReferences ,
1369
+ found_namespace : false ,
1370
+ has_runnable_content : false ,
1371
+ output_length : docsResult . responseContent ?. length ?? 0 ,
1372
+ } ) ;
1310
1373
} catch ( error ) {
1311
1374
// If the docs chatbot API is not available, fall back to Copilot’s LLM and include
1312
1375
// the MongoDB documentation link for users to go to our documentation site directly.
0 commit comments