Skip to content

Commit 2937290

Browse files
authored
Adopt copilot chat setup command (#7625)
* Adopt copilot chat setup command Part of #7614 * Use additional scopes
1 parent 8fd0a5c commit 2937290

4 files changed

Lines changed: 39 additions & 20 deletions

File tree

src/common/executeCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export namespace contexts {
2424

2525
export namespace commands {
2626
export const OPEN_CHAT = 'workbench.action.chat.open';
27+
export const CHAT_SETUP_ACTION_ID = 'workbench.action.chat.triggerSetup';
2728

2829
export const QUICK_CHAT_OPEN = 'workbench.action.quickchat.toggle';
2930

src/github/copilotRemoteAgent.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,9 @@ export class CopilotRemoteAgentManager extends Disposable {
263263
}
264264
}
265265

266-
async tryAcquireAuth(): Promise<FolderRepositoryManager | undefined> {
267-
if (this.credentialStore.isAnyAuthenticated()) {
268-
return this.chooseFolderManager();
269-
}
270-
271-
const result = await this.credentialStore.create({ createIfNone: { detail: vscode.l10n.t('Sign in to start delegating tasks to the GitHub coding agent.') } });
272-
273-
/* __GDPR__
274-
"remoteAgent.command.auth" : {
275-
"succeeded" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
276-
}
277-
*/
278-
this.telemetry.sendTelemetryEvent('remoteAgent.command.auth', {
279-
succeeded: result.canceled ? 'false' : 'true'
280-
});
281-
282-
if (result.canceled) {
266+
async tryPromptForAuthAndRepo(): Promise<FolderRepositoryManager | undefined> {
267+
const authResult = await this.credentialStore.tryPromptForCopilotAuth();
268+
if (!authResult) {
283269
return undefined;
284270
}
285271
// Wait for repos to update
@@ -293,7 +279,7 @@ export class CopilotRemoteAgentManager extends Disposable {
293279
return;
294280
}
295281
const { userPrompt, summary, source, followup, _version } = args;
296-
const fm = await this.tryAcquireAuth();
282+
const fm = await this.tryPromptForAuthAndRepo();
297283
if (!fm) {
298284
return;
299285
}

src/github/credentials.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createHttpLink } from 'apollo-link-http';
1010
import fetch from 'cross-fetch';
1111
import * as vscode from 'vscode';
1212
import { AuthProvider } from '../common/authentication';
13+
import { commands } from '../common/executeCommands';
1314
import { Disposable } from '../common/lifecycle';
1415
import Logger from '../common/logger';
1516
import * 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);

src/lm/tools/copilotRemoteAgentTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
3030

3131
async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<CopilotRemoteAgentToolParameters>): Promise<vscode.PreparedToolInvocation> {
3232
const { title, existingPullRequest } = options.input;
33-
const folderManager = existingPullRequest ? undefined : await this.manager.tryAcquireAuth();
33+
const folderManager = existingPullRequest ? undefined : await this.manager.tryPromptForAuthAndRepo();
3434

3535
// Check if the coding agent is available (enabled and assignable)
3636
const isAvailable = await this.manager.isAvailable();
@@ -68,7 +68,7 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
6868
const title = options.input.title;
6969
const body = options.input.body || '';
7070
const existingPullRequest = options.input.existingPullRequest || '';
71-
const folderManager = existingPullRequest ? undefined : await this.manager.tryAcquireAuth();
71+
const folderManager = existingPullRequest ? undefined : await this.manager.tryPromptForAuthAndRepo();
7272

7373
const targetRepo = await this.manager.repoInfo(folderManager);
7474
if (!targetRepo) {

0 commit comments

Comments
 (0)