55
66import vscode from 'vscode' ;
77import { Repository } from '../api/api' ;
8- import { AuthProvider } from '../common/authentication' ;
98import { COPILOT_LOGINS } from '../common/copilot' ;
109import { commands } from '../common/executeCommands' ;
1110import { Disposable } from '../common/lifecycle' ;
1211import Logger from '../common/logger' ;
1312import { GitHubRemote } from '../common/remote' ;
1413import { CODING_AGENT , CODING_AGENT_AUTO_COMMIT_AND_PUSH , CODING_AGENT_ENABLED } from '../common/settingKeys' ;
14+ import { ITelemetry } from '../common/telemetry' ;
1515import { toOpenPullRequestWebviewUri } from '../common/uri' ;
1616import { OctokitCommon } from './common' ;
17- import { CopilotApi , RemoteAgentJobPayload , SessionInfo } from './copilotApi' ;
17+ import { CopilotApi , getCopilotApi , RemoteAgentJobPayload , SessionInfo } from './copilotApi' ;
1818import { CopilotPRWatcher , CopilotStateModel } from './copilotPrWatcher' ;
1919import { CredentialStore } from './credentials' ;
2020import { FolderRepositoryManager } from './folderRepositoryManager' ;
@@ -59,7 +59,7 @@ export class CopilotRemoteAgentManager extends Disposable {
5959 private readonly _onDidCreatePullRequest = this . _register ( new vscode . EventEmitter < number > ( ) ) ;
6060 readonly onDidCreatePullRequest = this . _onDidCreatePullRequest . event ;
6161
62- constructor ( private credentialStore : CredentialStore , public repositoriesManager : RepositoriesManager ) {
62+ constructor ( private credentialStore : CredentialStore , public repositoriesManager : RepositoriesManager , private telemetry : ITelemetry ) {
6363 super ( ) ;
6464 this . _register ( this . credentialStore . onDidChangeSessions ( ( e : vscode . AuthenticationSessionsChangeEvent ) => {
6565 if ( e . provider . id === 'github' ) {
@@ -104,12 +104,7 @@ export class CopilotRemoteAgentManager extends Disposable {
104104 }
105105
106106 private async initializeCopilotApi ( ) : Promise < CopilotApi | undefined > {
107- const gh = await this . credentialStore . getHubOrLogin ( AuthProvider . github ) ;
108- const { token } = await gh ?. octokit . api . auth ( ) as { token : string } ;
109- if ( ! token || ! gh ?. octokit ) {
110- return ;
111- }
112- return new CopilotApi ( gh . octokit , token ) ;
107+ return await getCopilotApi ( this . credentialStore , this . telemetry ) ;
113108 }
114109
115110 enabled ( ) : boolean {
@@ -264,21 +259,48 @@ export class CopilotRemoteAgentManager extends Disposable {
264259 if ( ! args ) {
265260 return ;
266261 }
262+ const { userPrompt, summary, source, followup } = args ;
263+
264+ /* __GDPR__
265+ "remoteAgent.command.args" : {
266+ "source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
267+ "isFollowup" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
268+ "userPromptLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
269+ "summaryLength" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
270+ }
271+ */
272+ this . telemetry . sendTelemetryEvent ( 'remoteAgent.command.args' , {
273+ source : source ?. toString ( ) || 'unknown' ,
274+ isFollowup : ! ! followup ? 'true' : 'false' ,
275+ userPromptLength : userPrompt . length . toString ( ) ,
276+ summaryLength : summary ? summary . length . toString ( ) : '0'
277+ } ) ;
267278
268- const { userPrompt, summary, source } = args ;
269279 if ( ! userPrompt || userPrompt . trim ( ) . length === 0 ) {
270280 return ;
271281 }
272282
273283 const repoInfo = await this . repoInfo ( ) ;
274284 if ( ! repoInfo ) {
285+ /* __GDPR__
286+ "remoteAgent.command.result" : {
287+ "reason" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
288+ }
289+ */
290+ this . telemetry . sendTelemetryErrorEvent ( 'remoteAgent.command.result' , { reason : 'noRepositoryInfo' } ) ;
275291 return ;
276292 }
277293 const { repository, owner, repo } = repoInfo ;
278294
279295 const repoName = `${ owner } /${ repo } ` ;
280296 const hasChanges = repository . state . workingTreeChanges . length > 0 || repository . state . indexChanges . length > 0 ;
281297 const learnMoreCb = async ( ) => {
298+ /* __GDPR__
299+ "remoteAgent.command.result" : {
300+ "reason" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
301+ }
302+ */
303+ this . telemetry . sendTelemetryErrorEvent ( 'remoteAgent.command.result' , { reason : 'learnMore' } ) ;
282304 vscode . env . openExternal ( vscode . Uri . parse ( 'https://docs.github.com/copilot/using-github-copilot/coding-agent' ) ) ;
283305 } ;
284306
@@ -299,6 +321,12 @@ export class CopilotRemoteAgentManager extends Disposable {
299321 ) ;
300322
301323 if ( ! modalResult ) {
324+ /* __GDPR__
325+ "remoteAgent.command.result" : {
326+ "reason" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
327+ }
328+ */
329+ this . telemetry . sendTelemetryErrorEvent ( 'remoteAgent.command.result' , { reason : 'cancel' } ) ;
302330 return ;
303331 }
304332
@@ -338,11 +366,24 @@ export class CopilotRemoteAgentManager extends Disposable {
338366 ) ;
339367
340368 if ( result . state !== 'success' ) {
369+ /* __GDPR__
370+ "remoteAgent.command.result" : {
371+ "reason" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
372+ }
373+ */
374+ this . telemetry . sendTelemetryErrorEvent ( 'remoteAgent.command.result' , { reason : 'invocationFailure' } ) ;
341375 vscode . window . showErrorMessage ( result . error ) ;
342376 return ;
343377 }
344378
345379 const { webviewUri, link, number } = result ;
380+
381+ this . telemetry . sendTelemetryEvent ( 'remoteAgent.command' , {
382+ source : source || 'unknown' ,
383+ hasFollowup : ( ! ! followup ) . toString ( ) ,
384+ outcome : 'success'
385+ } ) ;
386+
346387 vscode . commands . executeCommand ( 'vscode.open' , webviewUri ) ;
347388
348389 // allow-any-unicode-next-line
0 commit comments