Skip to content

Commit bf66d60

Browse files
authored
no auth - offer sign-in dialog when rate limited (#1124)
1 parent dd5af4c commit bf66d60

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/extension/prompt/node/gitCommitMessageGenerator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IInstantiationService } from '../../../util/vs/platform/instantiation/c
1515
import { PromptRenderer } from '../../prompts/node/base/promptRenderer';
1616
import { GitCommitMessagePrompt } from '../../prompts/node/git/gitCommitMessagePrompt';
1717
import { RecentCommitMessages } from '../common/repository';
18+
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
1819

1920
type ResponseFormat = 'noTextCodeBlock' | 'oneTextCodeBlock' | 'multipleTextCodeBlocks';
2021

@@ -27,6 +28,7 @@ export class GitCommitMessageGenerator {
2728
@ITelemetryService private readonly telemetryService: ITelemetryService,
2829
@INotificationService private readonly notificationService: INotificationService,
2930
@IInteractionService private readonly interactionService: IInteractionService,
31+
@IAuthenticationService private readonly authService: IAuthenticationService,
3032
) { }
3133

3234
async generateGitCommitMessage(changes: Diff[], recentCommitMessages: RecentCommitMessages, attemptCount: number, token: CancellationToken): Promise<string | undefined> {
@@ -81,8 +83,8 @@ export class GitCommitMessageGenerator {
8183
timeToComplete: Date.now() - startTime
8284
});
8385

84-
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded) {
85-
await this.notificationService.showQuotaExceededDialog();
86+
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded || (fetchResult.type === ChatFetchResponseType.RateLimited && this.authService.copilotToken?.isNoAuthUser)) {
87+
await this.notificationService.showQuotaExceededDialog({ isNoAuthUser: this.authService.copilotToken?.isNoAuthUser ?? false });
8688
return undefined;
8789
}
8890

src/extension/prompt/node/githubPullRequestTitleAndDescriptionGenerator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { RenderPromptResult } from '@vscode/prompt-tsx';
7+
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
78
import { ChatFetchResponseType, ChatLocation } from '../../../platform/chat/common/commonTypes';
89
import { IConversationOptions } from '../../../platform/chat/common/conversationOptions';
910
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
@@ -30,6 +31,7 @@ export class GitHubPullRequestTitleAndDescriptionGenerator implements TitleAndDe
3031
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
3132
@IInstantiationService private readonly instantiationService: IInstantiationService,
3233
@INotificationService private readonly notificationService: INotificationService,
34+
@IAuthenticationService private readonly authService: IAuthenticationService,
3335
) {
3436
this.logService.info('[githubTitleAndDescriptionProvider] Initializing GitHub PR title and description provider provider.');
3537
}
@@ -95,8 +97,8 @@ export class GitHubPullRequestTitleAndDescriptionGenerator implements TitleAndDe
9597
);
9698

9799
this.lastContext = { commitMessages, patches };
98-
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded) {
99-
await this.notificationService.showQuotaExceededDialog();
100+
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded || (fetchResult.type === ChatFetchResponseType.RateLimited && this.authService.copilotToken?.isNoAuthUser)) {
101+
await this.notificationService.showQuotaExceededDialog({ isNoAuthUser: this.authService.copilotToken?.isNoAuthUser ?? false });
100102
}
101103

102104
if (fetchResult.type !== ChatFetchResponseType.Success) {

src/extension/renameSuggestions/node/renameSuggestionsProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ export class RenameSuggestionsProvider implements vscode.NewSymbolNamesProvider
155155
);
156156
const fetchTime = sw.elapsed();
157157

158-
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded) {
159-
await this._notificationService.showQuotaExceededDialog();
158+
if (fetchResult.type === ChatFetchResponseType.QuotaExceeded || (fetchResult.type === ChatFetchResponseType.RateLimited && this._authService.copilotToken?.isNoAuthUser)) {
159+
await this._notificationService.showQuotaExceededDialog({ isNoAuthUser: this._authService.copilotToken?.isNoAuthUser ?? false });
160160
}
161161

162162
if (token.isCancellationRequested) {

src/platform/notification/common/notificationService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface INotificationService {
3535
showInformationMessage(message: string, ...items: string[]): Promise<string | undefined>;
3636
showInformationMessage<T extends string>(message: string, options: MessageOptions, ...items: T[]): Promise<T | undefined>;
3737
showWarningMessage(message: string, ...items: string[]): Promise<string | undefined>;
38-
showQuotaExceededDialog(): Promise<unknown>;
38+
showQuotaExceededDialog(options: { isNoAuthUser: boolean }): Promise<unknown>;
3939
withProgress<R>(options: ProgressOptions, task: (progress: Progress<{
4040
message?: string;
4141
increment?: number;
@@ -56,7 +56,7 @@ export class NullNotificationService implements INotificationService {
5656
return Promise.resolve(undefined);
5757
}
5858

59-
showQuotaExceededDialog(): Promise<unknown> {
59+
showQuotaExceededDialog(options: { isNoAuthUser: boolean }): Promise<unknown> {
6060
return Promise.resolve();
6161
}
6262

src/platform/notification/vscode/notificationServiceImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class NotificationService implements INotificationService {
3131
return window.showWarningMessage(message, ...items);
3232
}
3333

34-
async showQuotaExceededDialog(): Promise<unknown> {
35-
return commands.executeCommand('workbench.action.chat.openQuotaExceededDialog');
34+
async showQuotaExceededDialog(options: { isNoAuthUser: boolean }): Promise<unknown> {
35+
return commands.executeCommand(options.isNoAuthUser ? 'workbench.action.chat.triggerSetup' : 'workbench.action.chat.openQuotaExceededDialog');
3636
}
3737
}

0 commit comments

Comments
 (0)