@@ -16,6 +16,8 @@ import { Disposable, toDisposable } from '../../../util/vs/base/common/lifecycle
1616import { body_suffix , CONTINUE_TRUNCATION , extractTitle , formatBodyPlaceholder , getAuthorDisplayName , getRepoId , JOBS_API_VERSION , RemoteAgentResult , SessionIdForPr , toOpenPullRequestWebviewUri , truncatePrompt } from '../vscode/copilotCodingAgentUtils' ;
1717import { ChatSessionContentBuilder } from './copilotCloudSessionContentBuilder' ;
1818import { IPullRequestFileChangesService } from './pullRequestFileChangesService' ;
19+ import { IAuthenticationChatUpgradeService } from '../../../platform/authentication/common/authenticationUpgrade' ;
20+ import { IAuthenticationService } from '../../../platform/authentication/common/authentication' ;
1921
2022export type ConfirmationResult = { step : string ; accepted : boolean ; metadata ?: ConfirmationMetadata } ;
2123
@@ -80,11 +82,17 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
8082 @ILogService private readonly logService : ILogService ,
8183 @IGitExtensionService private readonly _gitExtensionService : IGitExtensionService ,
8284 @IPullRequestFileChangesService private readonly _prFileChangesService : IPullRequestFileChangesService ,
85+ @IAuthenticationService private readonly _authenticationService : IAuthenticationService ,
86+ @IAuthenticationChatUpgradeService private readonly _authenticationUpgradeService : IAuthenticationChatUpgradeService ,
8387 ) {
8488 super ( ) ;
8589 const interval = setInterval ( async ( ) => {
8690 const repoId = await getRepoId ( this . _gitService ) ;
8791 if ( repoId ) {
92+ // TODO: handle no auth token case more gracefully
93+ if ( ! this . _authenticationService . permissiveGitHubSession ) {
94+ return ;
95+ }
8896 const sessions = await this . _octoKitService . getAllOpenSessions ( `${ repoId . org } /${ repoId . repo } ` ) ;
8997 if ( this . cachedSessionsSize !== sessions . length ) {
9098 this . refresh ( ) ;
@@ -104,6 +112,10 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
104112 return { optionGroups : [ ] } ;
105113 }
106114
115+ // TODO: handle no auth token case more gracefully
116+ if ( ! this . _authenticationService . permissiveGitHubSession ) {
117+ return { optionGroups : [ ] } ;
118+ }
107119 try {
108120 const customAgents = await this . _octoKitService . getCustomAgents ( repoId . org , repoId . repo ) ;
109121 const agentItems : vscode . ChatSessionProviderOptionItem [ ] = [
@@ -153,6 +165,10 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
153165 return [ ] ;
154166 }
155167
168+ // TODO: handle no auth token case more gracefully
169+ if ( ! this . _authenticationService . permissiveGitHubSession ) {
170+ return [ ] ;
171+ }
156172 const sessions = await this . _octoKitService . getAllOpenSessions ( `${ repoId . org } /${ repoId . repo } ` ) ;
157173 this . cachedSessionsSize = sessions . length ;
158174
@@ -430,9 +446,9 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
430446 }
431447
432448
433- private async handleConfirmationData ( request : vscode . ChatRequest , stream : vscode . ChatResponseStream , token : vscode . CancellationToken ) {
449+ private async handleConfirmationData ( request : vscode . ChatRequest , stream : vscode . ChatResponseStream , context : vscode . ChatContext , token : vscode . CancellationToken ) {
434450 const results : ConfirmationResult [ ] = [ ] ;
435- results . push ( ...( request . acceptedConfirmationData ?. map ( data => ( { step : data . step , accepted : true , metadata : data ?. metadata } ) ) ?? [ ] ) ) ;
451+ results . push ( ...( request . acceptedConfirmationData ?. filter ( data => ! data ?. authPermissionPrompted ) . map ( data => ( { step : data . step , accepted : true , metadata : data ?. metadata } ) ) ?? [ ] ) ) ;
436452 results . push ( ...( ( request . rejectedConfirmationData ?? [ ] ) . filter ( data => ! results . some ( r => r . step === data . step ) ) . map ( data => ( { step : data . step , accepted : false , metadata : data ?. metadata } ) ) ) ) ;
437453 for ( const data of results ) {
438454 switch ( data . step ) {
@@ -576,7 +592,26 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
576592
577593 private async chatParticipantImpl ( request : vscode . ChatRequest , context : vscode . ChatContext , stream : vscode . ChatResponseStream , token : vscode . CancellationToken ) {
578594 if ( request . acceptedConfirmationData || request . rejectedConfirmationData ) {
579- return await this . handleConfirmationData ( request , stream , token ) ;
595+ const findConfirmRequest = request . acceptedConfirmationData ?. find ( ref => ref ?. authPermissionPrompted ) ;
596+ if ( findConfirmRequest ) {
597+ const result = await this . _authenticationUpgradeService . handleConfirmationRequestWithContext ( stream , request , context . history ) ;
598+ request = result . request ;
599+ context = result . context ?? context ;
600+ } else {
601+ return await this . handleConfirmationData ( request , stream , context , token ) ;
602+ }
603+ }
604+
605+ const accessToken = this . _authenticationService . permissiveGitHubSession ;
606+ if ( ! accessToken ) {
607+ // Otherwise, show the permissive session upgrade prompt because it's required
608+ this . _authenticationUpgradeService . showPermissiveSessionUpgradeInChat (
609+ stream ,
610+ request ,
611+ vscode . l10n . t ( 'GitHub Copilot Cloud Agent requires access to your repositories on GitHub for handling requests.' ) ,
612+ context
613+ ) ;
614+ return { } ;
580615 }
581616
582617 /* __GDPR__
0 commit comments