@@ -10,6 +10,7 @@ import { createHttpLink } from 'apollo-link-http';
1010import fetch from 'cross-fetch' ;
1111import * as vscode from 'vscode' ;
1212import { AuthProvider } from '../common/authentication' ;
13+ import { commands } from '../common/executeCommands' ;
1314import { Disposable } from '../common/lifecycle' ;
1415import Logger from '../common/logger' ;
1516import * as PersistentState from '../common/persistentState' ;
@@ -121,6 +122,10 @@ export class CredentialStore extends Disposable {
121122 this . _scopesEnterprise = this . context . globalState . get ( LAST_USED_SCOPES_ENTERPRISE_KEY , SCOPES_OLD ) ;
122123 }
123124
125+ get scopes ( ) {
126+ return this . _scopes ;
127+ }
128+
124129 private async saveScopesInState ( ) {
125130 await this . context . globalState . update ( LAST_USED_SCOPES_GITHUB_KEY , this . _scopes ) ;
126131 await this . context . globalState . update ( LAST_USED_SCOPES_ENTERPRISE_KEY , this . _scopesEnterprise ) ;
@@ -287,6 +292,33 @@ export class CredentialStore extends Disposable {
287292 return ! this . allScopesIncluded ( this . _scopesEnterprise , SCOPES_OLD ) ;
288293 }
289294
295+ async tryPromptForCopilotAuth ( ) : Promise < boolean > {
296+ if ( this . isAnyAuthenticated ( ) ) {
297+ return true ;
298+ }
299+
300+ const chatSetupResult = await commands . executeCommand ( commands . CHAT_SETUP_ACTION_ID , 'agent' , { additionalScopes : this . scopes } ) ;
301+ if ( ! chatSetupResult ) {
302+ return false ;
303+ }
304+
305+ const result = await this . create ( { createIfNone : { detail : vscode . l10n . t ( 'Sign in to start delegating tasks to the GitHub coding agent.' ) } } ) ;
306+
307+ /* __GDPR__
308+ "remoteAgent.command.auth" : {
309+ "succeeded" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
310+ }
311+ */
312+ this . _telemetry . sendTelemetryEvent ( 'remoteAgent.command.auth' , {
313+ succeeded : result . canceled ? 'false' : 'true'
314+ } ) ;
315+
316+ if ( result . canceled ) {
317+ return false ;
318+ }
319+ return true ;
320+ }
321+
290322 public areScopesExtra ( authProviderId : AuthProvider ) : boolean {
291323 if ( ! isEnterprise ( authProviderId ) ) {
292324 return this . allScopesIncluded ( this . _scopes , SCOPES_WITH_ADDITIONAL ) ;
0 commit comments