@@ -52,10 +52,13 @@ import { PromptHistory } from './prompts/promptHistory';
52
52
import type {
53
53
SendMessageToParticipantOptions ,
54
54
SendMessageToParticipantFromInputOptions ,
55
+ ParticipantCommand ,
56
+ ParticipantCommandType ,
55
57
} from './participantTypes' ;
56
58
import { DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX } from '../editors/exportToLanguageCodeLensProvider' ;
57
59
import { EXPORT_TO_LANGUAGE_ALIASES } from '../editors/playgroundSelectionCodeActionProvider' ;
58
60
import { CollectionTreeItem , DatabaseTreeItem } from '../explorer' ;
61
+ import { DocumentSource } from '../documentSource' ;
59
62
60
63
const log = createLogger ( 'participant' ) ;
61
64
@@ -72,8 +75,6 @@ export type RunParticipantCodeCommandArgs = {
72
75
runnableContent : string ;
73
76
} ;
74
77
75
- export type ParticipantCommand = '/query' | '/schema' | '/docs' ;
76
-
77
78
const MAX_MARKDOWN_LIST_LENGTH = 10 ;
78
79
79
80
export default class ParticipantController {
@@ -121,6 +122,7 @@ export default class ParticipantController {
121
122
participantId : this . _participant ?. id ,
122
123
} ) ;
123
124
this . _participant . onDidReceiveFeedback ( this . handleUserFeedback . bind ( this ) ) ;
125
+
124
126
return this . _participant ;
125
127
}
126
128
@@ -142,6 +144,8 @@ export default class ParticipantController {
142
144
message,
143
145
isNewChat = false ,
144
146
isPartialQuery = false ,
147
+ telemetry,
148
+ command,
145
149
...otherOptions
146
150
} = options ;
147
151
@@ -151,10 +155,28 @@ export default class ParticipantController {
151
155
'workbench.action.chat.clearHistory'
152
156
) ;
153
157
}
158
+ const commandPrefix = command ? `/${ command } ` : '' ;
159
+ const query = `@MongoDB ${ commandPrefix } ${ message } ` ;
160
+
161
+ if ( telemetry ) {
162
+ if ( isNewChat ) {
163
+ this . _telemetryService . trackParticipantChatOpenedFromAction ( {
164
+ ...telemetry ,
165
+ command,
166
+ } ) ;
167
+ }
168
+ if ( ! isPartialQuery ) {
169
+ this . _telemetryService . trackParticipantPromptSubmittedFromAction ( {
170
+ ...telemetry ,
171
+ command : command ?? 'generic' ,
172
+ input_length : query . length ,
173
+ } ) ;
174
+ }
175
+ }
154
176
155
177
return await vscode . commands . executeCommand ( 'workbench.action.chat.open' , {
156
178
...otherOptions ,
157
- query : `@MongoDB ${ message } ` ,
179
+ query,
158
180
isPartialQuery,
159
181
} ) ;
160
182
}
@@ -163,27 +185,34 @@ export default class ParticipantController {
163
185
options : SendMessageToParticipantFromInputOptions
164
186
) : Promise < unknown > {
165
187
const {
166
- messagePrefix = '' ,
167
- isNewChat = false ,
168
- isPartialQuery = false ,
169
- source ,
188
+ isNewChat ,
189
+ isPartialQuery ,
190
+ telemetry ,
191
+ command ,
170
192
...inputBoxOptions
171
193
} = options ;
172
194
173
- this . _telemetryService . trackCopilotParticipantSubmittedFromInputBox ( {
174
- source,
175
- } ) ;
176
-
177
195
const message = await vscode . window . showInputBox ( {
178
196
...inputBoxOptions ,
179
197
} ) ;
180
198
199
+ if ( telemetry ) {
200
+ this . _telemetryService . trackParticipantInputBoxSubmitted ( {
201
+ ...telemetry ,
202
+ input_length : message ?. length ,
203
+ dismissed : message === undefined ,
204
+ command,
205
+ } ) ;
206
+ }
207
+
181
208
if ( message === undefined || message . trim ( ) === '' ) {
182
209
return Promise . resolve ( ) ;
183
210
}
184
211
185
212
return this . sendMessageToParticipant ( {
186
- message : `${ messagePrefix ? `${ messagePrefix } ` : '' } ${ message } ` ,
213
+ message,
214
+ telemetry,
215
+ command,
187
216
isNewChat,
188
217
isPartialQuery,
189
218
} ) ;
@@ -198,13 +227,21 @@ export default class ParticipantController {
198
227
await this . sendMessageToParticipant ( {
199
228
message : `I want to ask questions about the \`${ databaseName } \` database.` ,
200
229
isNewChat : true ,
230
+ telemetry : {
231
+ source : DocumentSource . DOCUMENT_SOURCE_TREEVIEW ,
232
+ source_details : 'database' ,
233
+ } ,
201
234
} ) ;
202
235
} else if ( treeItem instanceof CollectionTreeItem ) {
203
236
const { databaseName, collectionName } = treeItem ;
204
237
205
238
await this . sendMessageToParticipant ( {
206
239
message : `I want to ask questions about the \`${ databaseName } \` database's \`${ collectionName } \` collection.` ,
207
240
isNewChat : true ,
241
+ telemetry : {
242
+ source : DocumentSource . DOCUMENT_SOURCE_TREEVIEW ,
243
+ source_details : 'collection' ,
244
+ } ,
208
245
} ) ;
209
246
} else {
210
247
throw new Error ( 'Unsupported tree item type' ) ;
@@ -233,7 +270,7 @@ export default class ParticipantController {
233
270
} )
234
271
) ,
235
272
} ) ;
236
- this . _telemetryService . trackCopilotParticipantPrompt ( modelInput . stats ) ;
273
+ this . _telemetryService . trackParticipantPrompt ( modelInput . stats ) ;
237
274
238
275
const modelResponse = await model . sendRequest (
239
276
modelInput . messages ,
@@ -413,7 +450,7 @@ export default class ParticipantController {
413
450
stream,
414
451
} ) ;
415
452
416
- this . _telemetryService . trackCopilotParticipantResponse ( {
453
+ this . _telemetryService . trackParticipantResponse ( {
417
454
command : 'generic' ,
418
455
has_cta : false ,
419
456
found_namespace : false ,
@@ -1380,7 +1417,7 @@ export default class ParticipantController {
1380
1417
] ,
1381
1418
} ) ;
1382
1419
1383
- this . _telemetryService . trackCopilotParticipantResponse ( {
1420
+ this . _telemetryService . trackParticipantResponse ( {
1384
1421
command : 'schema' ,
1385
1422
has_cta : true ,
1386
1423
found_namespace : true ,
@@ -1491,7 +1528,7 @@ export default class ParticipantController {
1491
1528
token,
1492
1529
} ) ;
1493
1530
1494
- this . _telemetryService . trackCopilotParticipantResponse ( {
1531
+ this . _telemetryService . trackParticipantResponse ( {
1495
1532
command : 'query' ,
1496
1533
has_cta : false ,
1497
1534
found_namespace : true ,
@@ -1597,7 +1634,7 @@ export default class ParticipantController {
1597
1634
1598
1635
this . _streamGenericDocsLink ( stream ) ;
1599
1636
1600
- this . _telemetryService . trackCopilotParticipantResponse ( {
1637
+ this . _telemetryService . trackParticipantResponse ( {
1601
1638
command : 'docs/copilot' ,
1602
1639
has_cta : true ,
1603
1640
found_namespace : false ,
@@ -1677,7 +1714,7 @@ export default class ParticipantController {
1677
1714
}
1678
1715
}
1679
1716
1680
- this . _telemetryService . trackCopilotParticipantResponse ( {
1717
+ this . _telemetryService . trackParticipantResponse ( {
1681
1718
command : 'docs/chatbot' ,
1682
1719
has_cta : ! ! docsResult . responseReferences ,
1683
1720
found_namespace : false ,
@@ -1795,10 +1832,7 @@ export default class ParticipantController {
1795
1832
return true ;
1796
1833
} catch ( error ) {
1797
1834
const message = formatError ( error ) . message ;
1798
- this . _telemetryService . trackCopilotParticipantError (
1799
- error ,
1800
- 'exportToPlayground'
1801
- ) ;
1835
+ this . _telemetryService . trackParticipantError ( error , 'exportToPlayground' ) ;
1802
1836
void vscode . window . showErrorMessage (
1803
1837
`An error occurred exporting to a playground: ${ message } `
1804
1838
) ;
@@ -1905,9 +1939,9 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
1905
1939
return await this . handleGenericRequest ( ...args ) ;
1906
1940
}
1907
1941
} catch ( error ) {
1908
- this . _telemetryService . trackCopilotParticipantError (
1942
+ this . _telemetryService . trackParticipantError (
1909
1943
error ,
1910
- request . command || 'generic'
1944
+ ( request . command as ParticipantCommandType ) || 'generic'
1911
1945
) ;
1912
1946
// Re-throw other errors so they show up in the UI.
1913
1947
throw error ;
@@ -1956,7 +1990,7 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
1956
1990
'unhelpfulReason' in feedback
1957
1991
? ( feedback . unhelpfulReason as string )
1958
1992
: undefined ;
1959
- this . _telemetryService . trackCopilotParticipantFeedback ( {
1993
+ this . _telemetryService . trackParticipantFeedback ( {
1960
1994
feedback : chatResultFeedbackKindToTelemetryValue ( feedback . kind ) ,
1961
1995
reason : unhelpfulReason ,
1962
1996
response_type : ( feedback . result as ChatResult ) ?. metadata . intent ,
0 commit comments