Skip to content

Commit c8f53ea

Browse files
authored
chat - some fixes to setup and quotas (microsoft#235457)
1 parent 6287936 commit c8f53ea

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/vs/workbench/contrib/chat/browser/chatQuotasService.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface IChatQuotasService {
3232
readonly quotas: IChatQuotas;
3333

3434
acceptQuotas(quotas: IChatQuotas): void;
35+
clearQuotas(): void;
3536
}
3637

3738
export interface IChatQuotas {
@@ -113,9 +114,12 @@ export class ChatQuotasService extends Disposable implements IChatQuotasService
113114
id: MenuId.ChatCommandCenter,
114115
group: 'a_first',
115116
order: 1,
116-
when: ContextKeyExpr.or(
117-
ChatContextKeys.chatQuotaExceeded,
118-
ChatContextKeys.completionsQuotaExceeded
117+
when: ContextKeyExpr.and(
118+
ChatContextKeys.Setup.installed,
119+
ContextKeyExpr.or(
120+
ChatContextKeys.chatQuotaExceeded,
121+
ChatContextKeys.completionsQuotaExceeded
122+
)
119123
)
120124
}
121125
});
@@ -221,6 +225,12 @@ export class ChatQuotasService extends Disposable implements IChatQuotasService
221225
this._onDidChangeQuotas.fire();
222226
}
223227

228+
clearQuotas(): void {
229+
if (this.quotas.chatQuotaExceeded || this.quotas.completionsQuotaExceeded) {
230+
this.acceptQuotas({ chatQuotaExceeded: false, completionsQuotaExceeded: false, quotaResetDate: new Date(0) });
231+
}
232+
}
233+
224234
private updateContextKeys(): void {
225235
this.chatQuotaExceededContextKey.set(this._quotas.chatQuotaExceeded);
226236
this.completionsQuotaExceededContextKey.set(this._quotas.completionsQuotaExceeded);

src/vs/workbench/contrib/chat/browser/chatSetup.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { CHAT_EDITING_SIDEBAR_PANEL_ID, CHAT_SIDEBAR_PANEL_ID } from './chatView
5656
import { ChatViewsWelcomeExtensions, IChatViewsWelcomeContributionRegistry } from './viewsWelcome/chatViewsWelcome.js';
5757
import { IChatQuotasService } from './chatQuotasService.js';
5858
import { Checkbox } from '../../../../base/browser/ui/toggle/toggle.js';
59+
import { mainWindow } from '../../../../base/browser/window.js';
5960

6061
const defaultChat = {
6162
extensionId: product.defaultChatAgent?.extensionId ?? '',
@@ -341,6 +342,15 @@ class ChatSetupRequests extends Disposable {
341342
this.resolve();
342343
}
343344
}));
345+
346+
this._register(this.context.onDidChange(() => {
347+
if (!this.context.state.installed || this.context.state.entitlement === ChatEntitlement.Unknown) {
348+
// When the extension is not installed or the user is not entitled
349+
// make sure to clear quotas so that any indicators are also gone
350+
this.state = { entitlement: this.state.entitlement, quotas: undefined };
351+
this.chatQuotasService.clearQuotas();
352+
}
353+
}));
344354
}
345355

346356
private async resolve(): Promise<void> {
@@ -737,7 +747,8 @@ class ChatSetupController extends Disposable {
737747

738748
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult, signedIn });
739749

740-
if (activeElement === getActiveElement()) {
750+
const currentActiveElement = getActiveElement();
751+
if (activeElement === currentActiveElement || currentActiveElement === mainWindow.document.body) {
741752
(await showCopilotView(this.viewsService))?.focusInput();
742753
}
743754
}

0 commit comments

Comments
 (0)