Skip to content

Commit 81828ea

Browse files
authored
Ben/active-ocelot (microsoft#235494) (microsoft#235496)
* chat - make quota reset date explicitly `undefined` if neede * chat - tweak status quota indication * chat - tweak status indicator further
1 parent 83c06ce commit 81828ea

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

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

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export interface IChatQuotasService {
3636
}
3737

3838
export interface IChatQuotas {
39-
readonly chatQuotaExceeded: boolean;
40-
readonly completionsQuotaExceeded: boolean;
41-
readonly quotaResetDate: Date;
39+
chatQuotaExceeded: boolean;
40+
completionsQuotaExceeded: boolean;
41+
quotaResetDate: Date | undefined;
4242
}
4343

4444
export const OPEN_CHAT_QUOTA_EXCEEDED_DIALOG = 'workbench.action.chat.openQuotaExceededDialog';
@@ -50,7 +50,7 @@ export class ChatQuotasService extends Disposable implements IChatQuotasService
5050
private readonly _onDidChangeQuotas = this._register(new Emitter<void>());
5151
readonly onDidChangeQuotas: Event<void> = this._onDidChangeQuotas.event;
5252

53-
private _quotas = { chatQuotaExceeded: false, completionsQuotaExceeded: false, quotaResetDate: new Date(0) };
53+
private _quotas: IChatQuotas = { chatQuotaExceeded: false, completionsQuotaExceeded: false, quotaResetDate: undefined };
5454
get quotas(): IChatQuotas { return this._quotas; }
5555

5656
private readonly chatQuotaExceededContextKey = ChatContextKeys.chatQuotaExceeded.bindTo(this.contextKeyService);
@@ -227,7 +227,7 @@ export class ChatQuotasService extends Disposable implements IChatQuotasService
227227

228228
clearQuotas(): void {
229229
if (this.quotas.chatQuotaExceeded || this.quotas.completionsQuotaExceeded) {
230-
this.acceptQuotas({ chatQuotaExceeded: false, completionsQuotaExceeded: false, quotaResetDate: new Date(0) });
230+
this.acceptQuotas({ chatQuotaExceeded: false, completionsQuotaExceeded: false, quotaResetDate: undefined });
231231
}
232232
}
233233

@@ -241,6 +241,8 @@ export class ChatQuotasStatusBarEntry extends Disposable implements IWorkbenchCo
241241

242242
static readonly ID = 'chat.quotasStatusBarEntry';
243243

244+
private static readonly COPILOT_STATUS_ID = 'GitHub.copilot.status'; // TODO@bpasero unify into 1 core indicator
245+
244246
private readonly _entry = this._register(new MutableDisposable<IStatusbarEntryAccessor>());
245247

246248
constructor(
@@ -254,19 +256,39 @@ export class ChatQuotasStatusBarEntry extends Disposable implements IWorkbenchCo
254256

255257
private updateStatusbarEntry(): void {
256258
const { chatQuotaExceeded, completionsQuotaExceeded } = this.chatQuotasService.quotas;
259+
260+
// Some quota exceeded, show indicator
257261
if (chatQuotaExceeded || completionsQuotaExceeded) {
258-
// Some quota exceeded, show indicator
262+
let text: string;
263+
if (chatQuotaExceeded && !completionsQuotaExceeded) {
264+
text = localize('chatQuotaExceededStatus', "Chat limit reached");
265+
} else if (completionsQuotaExceeded && !chatQuotaExceeded) {
266+
text = localize('completionsQuotaExceededStatus', "Completions limit reached");
267+
} else {
268+
text = localize('chatAndCompletionsQuotaExceededStatus', "Copilot limit reached");
269+
}
270+
271+
const isCopilotStatusVisible = this.statusbarService.isEntryVisible(ChatQuotasStatusBarEntry.COPILOT_STATUS_ID);
272+
if (!isCopilotStatusVisible) {
273+
text = `$(copilot-warning) ${text}`;
274+
}
275+
259276
this._entry.value = this.statusbarService.addEntry({
260-
name: localize('indicator', "Copilot Quota Indicator"),
261-
text: localize('limitReached', "Copilot Limit Reached"),
262-
ariaLabel: localize('copilotQuotaExceeded', "Copilot Limit Reached"),
277+
name: localize('indicator', "Copilot Limit Indicator"),
278+
text,
279+
ariaLabel: text,
263280
command: OPEN_CHAT_QUOTA_EXCEEDED_DIALOG,
264-
kind: 'prominent',
265281
showInAllWindows: true,
266-
tooltip: quotaToButtonMessage({ chatQuotaExceeded, completionsQuotaExceeded }),
267-
}, ChatQuotasStatusBarEntry.ID, StatusbarAlignment.RIGHT, { id: 'GitHub.copilot.status', alignment: StatusbarAlignment.RIGHT }); // TODO@bpasero unify into 1 core indicator
268-
} else {
269-
// No quota exceeded, remove indicator
282+
tooltip: quotaToButtonMessage({ chatQuotaExceeded, completionsQuotaExceeded })
283+
}, ChatQuotasStatusBarEntry.ID, StatusbarAlignment.RIGHT, {
284+
id: ChatQuotasStatusBarEntry.COPILOT_STATUS_ID,
285+
alignment: StatusbarAlignment.RIGHT,
286+
compact: isCopilotStatusVisible
287+
});
288+
}
289+
290+
// No quota exceeded, remove indicator
291+
else {
270292
this._entry.clear();
271293
}
272294
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class ChatSetupRequests extends Disposable {
512512
this.chatQuotasService.acceptQuotas({
513513
chatQuotaExceeded: typeof state.quotas.chat === 'number' ? state.quotas.chat <= 0 : false,
514514
completionsQuotaExceeded: typeof state.quotas.completions === 'number' ? state.quotas.completions <= 0 : false,
515-
quotaResetDate: state.quotas.resetDate ? new Date(state.quotas.resetDate) : new Date(0)
515+
quotaResetDate: state.quotas.resetDate ? new Date(state.quotas.resetDate) : undefined
516516
});
517517
}
518518
}

0 commit comments

Comments
 (0)