Skip to content

Commit e8c27bc

Browse files
authored
chat - merge quota and entitlement service (microsoft#242408)
1 parent 207f99d commit e8c27bc

File tree

8 files changed

+850
-840
lines changed

8 files changed

+850
-840
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import { ILanguageModelToolsService } from '../../common/languageModelToolsServi
4646
import { ChatViewId, EditsViewId, IChatWidget, IChatWidgetService, showChatView, showCopilotView } from '../chat.js';
4747
import { IChatEditorOptions } from '../chatEditor.js';
4848
import { ChatEditorInput } from '../chatEditorInput.js';
49-
import { IChatQuotasService } from '../../common/chatQuotasService.js';
5049
import { ChatViewPane } from '../chatViewPane.js';
5150
import { convertBufferToScreenshotVariable } from '../contrib/screenshot.js';
5251
import { clearChatEditor } from './chatClear.js';
@@ -55,7 +54,7 @@ import { language } from '../../../../../base/common/platform.js';
5554
import { MarkdownString } from '../../../../../base/common/htmlContent.js';
5655
import { IWorkbenchLayoutService, Parts } from '../../../../services/layout/browser/layoutService.js';
5756
import { IViewDescriptorService, ViewContainerLocation } from '../../../../common/views.js';
58-
import { ChatEntitlement, IChatEntitlementsService } from '../../common/chatEntitlementsService.js';
57+
import { ChatEntitlement, IChatEntitlementService } from '../../common/chatEntitlementService.js';
5958

6059
export const CHAT_CATEGORY = localize2('chat.category', 'Chat');
6160

@@ -587,20 +586,20 @@ export function registerChatActions() {
587586
}
588587

589588
override async run(accessor: ServicesAccessor) {
590-
const chatQuotasService = accessor.get(IChatQuotasService);
589+
const chatEntitlementService = accessor.get(IChatEntitlementService);
591590
const commandService = accessor.get(ICommandService);
592591
const dialogService = accessor.get(IDialogService);
593592

594593
const dateFormatter = safeIntl.DateTimeFormat(language, { year: 'numeric', month: 'long', day: 'numeric' });
595594

596595
let message: string;
597-
const { chatQuotaExceeded, completionsQuotaExceeded } = chatQuotasService.quotas;
596+
const { chatQuotaExceeded, completionsQuotaExceeded } = chatEntitlementService.quotas;
598597
if (chatQuotaExceeded && !completionsQuotaExceeded) {
599-
message = localize('chatQuotaExceeded', "You've run out of free chat messages. You still have free code completions available in the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatQuotasService.quotas.quotaResetDate));
598+
message = localize('chatQuotaExceeded', "You've run out of free chat messages. You still have free code completions available in the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatEntitlementService.quotas.quotaResetDate));
600599
} else if (completionsQuotaExceeded && !chatQuotaExceeded) {
601-
message = localize('completionsQuotaExceeded', "You've run out of free code completions. You still have free chat messages available in the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatQuotasService.quotas.quotaResetDate));
600+
message = localize('completionsQuotaExceeded', "You've run out of free code completions. You still have free chat messages available in the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatEntitlementService.quotas.quotaResetDate));
602601
} else {
603-
message = localize('chatAndCompletionsQuotaExceeded', "You've reached the limit of the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatQuotasService.quotas.quotaResetDate));
602+
message = localize('chatAndCompletionsQuotaExceeded', "You've reached the limit of the Copilot Free plan. These limits will reset on {0}.", dateFormatter.format(chatEntitlementService.quotas.quotaResetDate));
604603
}
605604

606605
const upgradeToPro = localize('upgradeToPro', "Upgrade to Copilot Pro (your first 30 days are free) for:\n- Unlimited code completions\n- Unlimited chat messages\n- Access to additional models");
@@ -693,9 +692,8 @@ export class CopilotTitleBarMenuRendering extends Disposable implements IWorkben
693692
constructor(
694693
@IActionViewItemService actionViewItemService: IActionViewItemService,
695694
@IChatAgentService agentService: IChatAgentService,
696-
@IChatQuotasService chatQuotasService: IChatQuotasService,
697695
@IInstantiationService instantiationService: IInstantiationService,
698-
@IChatEntitlementsService chatEntitlementsService: IChatEntitlementsService
696+
@IChatEntitlementService chatEntitlementService: IChatEntitlementService
699697
) {
700698
super();
701699

@@ -711,8 +709,8 @@ export class CopilotTitleBarMenuRendering extends Disposable implements IWorkben
711709
});
712710

713711
const chatExtensionInstalled = agentService.getAgents().some(agent => agent.isDefault);
714-
const { chatQuotaExceeded, completionsQuotaExceeded } = chatQuotasService.quotas;
715-
const signedOut = chatEntitlementsService.entitlement === ChatEntitlement.Unknown;
712+
const { chatQuotaExceeded, completionsQuotaExceeded } = chatEntitlementService.quotas;
713+
const signedOut = chatEntitlementService.entitlement === ChatEntitlement.Unknown;
716714

717715
let primaryActionId: string;
718716
let primaryActionTitle: string;
@@ -743,8 +741,8 @@ export class CopilotTitleBarMenuRendering extends Disposable implements IWorkben
743741
}, undefined, undefined, undefined, undefined), dropdownAction, action.actions, '', { ...options, skipTelemetry: true });
744742
}, Event.any(
745743
agentService.onDidChangeAgents,
746-
chatQuotasService.onDidChangeQuotaExceeded,
747-
chatEntitlementsService.onDidChangeEntitlement
744+
chatEntitlementService.onDidChangeQuotaExceeded,
745+
chatEntitlementService.onDidChangeEntitlement
748746
));
749747

750748
// Reduces flicker a bit on reload/restart

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ import { agentSlashCommandToMarkdown, agentToMarkdown } from './chatMarkdownDeco
7878
import { ChatCompatibilityNotifier, ChatExtensionPointHandler } from './chatParticipant.contribution.js';
7979
import { ChatPasteProvidersFeature } from './chatPasteProviders.js';
8080
import { QuickChatService } from './chatQuick.js';
81-
import { ChatQuotasService, IChatQuotasService } from '../common/chatQuotasService.js';
8281
import { ChatResponseAccessibleView } from './chatResponseAccessibleView.js';
83-
import { ChatEntitlementsService, ChatSetupContribution } from './chatSetup.js';
84-
import { ChatEntitlement, IChatEntitlementsService } from '../common/chatEntitlementsService.js';
82+
import { ChatSetupContribution } from './chatSetup.js';
83+
import { ChatEntitlement, ChatEntitlementService, IChatEntitlementService } from '../common/chatEntitlementService.js';
8584
import { ChatVariablesService } from './chatVariables.js';
8685
import { ChatWidgetService } from './chatWidget.js';
8786
import { ChatCodeBlockContextProviderService } from './codeBlockContextProviderService.js';
@@ -310,7 +309,7 @@ class ChatAgentSettingContribution extends Disposable implements IWorkbenchContr
310309
@IWorkbenchAssignmentService private readonly experimentService: IWorkbenchAssignmentService,
311310
@IProductService private readonly productService: IProductService,
312311
@IContextKeyService contextKeyService: IContextKeyService,
313-
@IChatEntitlementsService private readonly entitlementService: IChatEntitlementsService,
312+
@IChatEntitlementService private readonly entitlementService: IChatEntitlementService,
314313
) {
315314
super();
316315

@@ -547,8 +546,7 @@ registerSingleton(ICodeMapperService, CodeMapperService, InstantiationType.Delay
547546
registerSingleton(IChatEditingService, ChatEditingService, InstantiationType.Delayed);
548547
registerSingleton(IChatMarkdownAnchorService, ChatMarkdownAnchorService, InstantiationType.Delayed);
549548
registerSingleton(ILanguageModelIgnoredFilesService, LanguageModelIgnoredFilesService, InstantiationType.Delayed);
550-
registerSingleton(IChatQuotasService, ChatQuotasService, InstantiationType.Delayed);
551-
registerSingleton(IChatEntitlementsService, ChatEntitlementsService, InstantiationType.Delayed);
549+
registerSingleton(IChatEntitlementService, ChatEntitlementService, InstantiationType.Delayed);
552550
registerSingleton(IPromptsService, PromptsService, InstantiationType.Delayed);
553551

554552
registerWorkbenchContribution2(ChatEditingNotebookFileSystemProviderContrib.ID, ChatEditingNotebookFileSystemProviderContrib, WorkbenchPhase.BlockStartup);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import { revealInSideBarCommand } from '../../files/browser/fileActions.contribu
7777
import { ChatAgentLocation, IChatAgentService } from '../common/chatAgents.js';
7878
import { ChatContextKeys } from '../common/chatContextKeys.js';
7979
import { IChatEditingSession, WorkingSetEntryRemovalReason, WorkingSetEntryState } from '../common/chatEditingService.js';
80-
import { ChatEntitlement, IChatEntitlementsService } from '../common/chatEntitlementsService.js';
80+
import { ChatEntitlement, IChatEntitlementService } from '../common/chatEntitlementService.js';
8181
import { IChatRequestVariableEntry, isImageVariableEntry, isLinkVariableEntry, isPasteVariableEntry } from '../common/chatModel.js';
8282
import { IChatFollowup } from '../common/chatService.js';
8383
import { IChatVariablesService } from '../common/chatVariables.js';
@@ -1619,7 +1619,7 @@ class ModelPickerActionViewItem extends DropdownMenuActionViewItemWithKeybinding
16191619
@IContextMenuService contextMenuService: IContextMenuService,
16201620
@IKeybindingService keybindingService: IKeybindingService,
16211621
@IContextKeyService contextKeyService: IContextKeyService,
1622-
@IChatEntitlementsService chatEntitlementsService: IChatEntitlementsService,
1622+
@IChatEntitlementService chatEntitlementService: IChatEntitlementService,
16231623
@ICommandService commandService: ICommandService,
16241624
) {
16251625
const modelActionsProvider: IActionProvider = {
@@ -1642,7 +1642,7 @@ class ModelPickerActionViewItem extends DropdownMenuActionViewItemWithKeybinding
16421642

16431643
const models: ILanguageModelChatMetadataAndIdentifier[] = this.delegate.getModels();
16441644
const actions = models.map(entry => setLanguageModelAction(entry));
1645-
if (chatEntitlementsService.entitlement === ChatEntitlement.Limited) {
1645+
if (chatEntitlementService.entitlement === ChatEntitlement.Limited) {
16461646
actions.push(new Separator());
16471647
actions.push(toAction({ id: 'moreModels', label: localize('chat.moreModels', "Add More Models..."), run: () => commandService.executeCommand('workbench.action.chat.upgradePlan') }));
16481648
}

0 commit comments

Comments
 (0)