Skip to content

Commit 99ef746

Browse files
authored
chat - some setup and quotas tweaks (microsoft#235484)
chat - some setup and quotas tweaks (microsoft#235477)
1 parent 846621d commit 99ef746

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed

src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@
207207
border-color: var(--vscode-commandCenter-inactiveBorder) !important;
208208
}
209209

210-
.monaco-workbench .part.titlebar > .titlebar-container > .titlebar-center > .window-title > .command-center .codicon-copilot {
211-
font-size: 14px;
212-
}
213-
214210
.monaco-workbench .part.titlebar > .titlebar-container > .titlebar-center > .window-title > .command-center .action-item.command-center-center:HOVER {
215211
color: var(--vscode-commandCenter-activeForeground);
216212
background-color: var(--vscode-commandCenter-activeBackground);

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ILocalizedString, localize, localize2 } from '../../../../../nls.js';
2020
import { IActionViewItemService } from '../../../../../platform/actions/browser/actionViewItemService.js';
2121
import { DropdownWithPrimaryActionViewItem } from '../../../../../platform/actions/browser/dropdownWithPrimaryActionViewItem.js';
2222
import { Action2, MenuId, MenuItemAction, MenuRegistry, registerAction2, SubmenuItemAction } from '../../../../../platform/actions/common/actions.js';
23-
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
23+
import { ContextKeyExpr, IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
2424
import { IsLinuxContext, IsWindowsContext } from '../../../../../platform/contextkey/common/contextkeys.js';
2525
import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
2626
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
@@ -571,9 +571,12 @@ export class ChatCommandCenterRendering extends Disposable implements IWorkbench
571571
@IChatAgentService agentService: IChatAgentService,
572572
@IChatQuotasService chatQuotasService: IChatQuotasService,
573573
@IInstantiationService instantiationService: IInstantiationService,
574+
@IContextKeyService contextKeyService: IContextKeyService,
574575
) {
575576
super();
576577

578+
const contextKeySet = new Set([ChatContextKeys.Setup.signedOut.key]);
579+
577580
actionViewItemService.register(MenuId.CommandCenter, MenuId.ChatCommandCenter, (action, options) => {
578581
if (!(action instanceof SubmenuItemAction)) {
579582
return undefined;
@@ -587,29 +590,39 @@ export class ChatCommandCenterRendering extends Disposable implements IWorkbench
587590

588591
const chatExtensionInstalled = agentService.getAgents().some(agent => agent.isDefault);
589592
const { chatQuotaExceeded, completionsQuotaExceeded } = chatQuotasService.quotas;
590-
591-
let primaryAction: MenuItemAction;
592-
if (chatExtensionInstalled && !chatQuotaExceeded && !completionsQuotaExceeded) {
593-
primaryAction = instantiationService.createInstance(MenuItemAction, {
594-
id: CHAT_OPEN_ACTION_ID,
595-
title: OpenChatGlobalAction.TITLE,
596-
icon: Codicon.copilot,
597-
}, undefined, undefined, undefined, undefined);
598-
} else if (!chatExtensionInstalled) {
599-
primaryAction = instantiationService.createInstance(MenuItemAction, {
600-
id: 'workbench.action.chat.triggerSetup',
601-
title: localize2('triggerChatSetup', "Use AI Features with Copilot for Free..."),
602-
icon: Codicon.copilot,
603-
}, undefined, undefined, undefined, undefined);
593+
const signedOut = contextKeyService.getContextKeyValue<boolean>(ChatContextKeys.Setup.signedOut.key) ?? false;
594+
595+
let primaryActionId: string;
596+
let primaryActionTitle: string;
597+
let primaryActionIcon: ThemeIcon;
598+
if (!chatExtensionInstalled) {
599+
primaryActionId = 'workbench.action.chat.triggerSetup';
600+
primaryActionTitle = localize('triggerChatSetup', "Use AI Features with Copilot for Free...");
601+
primaryActionIcon = Codicon.copilot;
604602
} else {
605-
primaryAction = instantiationService.createInstance(MenuItemAction, {
606-
id: OPEN_CHAT_QUOTA_EXCEEDED_DIALOG,
607-
title: quotaToButtonMessage({ chatQuotaExceeded, completionsQuotaExceeded }),
608-
icon: Codicon.copilotWarning,
609-
}, undefined, undefined, undefined, undefined);
603+
if (signedOut) {
604+
primaryActionId = CHAT_OPEN_ACTION_ID;
605+
primaryActionTitle = localize('signInToChatSetup', "Sign in to Use Copilot...");
606+
primaryActionIcon = Codicon.copilotWarning;
607+
} else if (chatQuotaExceeded || completionsQuotaExceeded) {
608+
primaryActionId = OPEN_CHAT_QUOTA_EXCEEDED_DIALOG;
609+
primaryActionTitle = quotaToButtonMessage({ chatQuotaExceeded, completionsQuotaExceeded });
610+
primaryActionIcon = Codicon.copilotWarning;
611+
} else {
612+
primaryActionId = CHAT_OPEN_ACTION_ID;
613+
primaryActionTitle = OpenChatGlobalAction.TITLE.value;
614+
primaryActionIcon = Codicon.copilot;
615+
}
610616
}
611-
612-
return instantiationService.createInstance(DropdownWithPrimaryActionViewItem, primaryAction, dropdownAction, action.actions, '', { ...options, skipTelemetry: true });
613-
}, Event.any(agentService.onDidChangeAgents, chatQuotasService.onDidChangeQuotas));
617+
return instantiationService.createInstance(DropdownWithPrimaryActionViewItem, instantiationService.createInstance(MenuItemAction, {
618+
id: primaryActionId,
619+
title: primaryActionTitle,
620+
icon: primaryActionIcon,
621+
}, undefined, undefined, undefined, undefined), dropdownAction, action.actions, '', { ...options, skipTelemetry: true });
622+
}, Event.any(
623+
agentService.onDidChangeAgents,
624+
chatQuotasService.onDidChangeQuotas,
625+
Event.filter(contextKeyService.onDidChangeContext, e => e.affectsSome(contextKeySet))
626+
));
614627
}
615628
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class ChatQuotasService extends Disposable implements IChatQuotasService
173173
],
174174
custom: {
175175
closeOnLinkClick: true,
176-
icon: Codicon.copilotWarning,
176+
icon: Codicon.copilotWarningLarge,
177177
markdownDetails: [
178178
{ markdown: new MarkdownString(message, true) },
179179
{ markdown: new MarkdownString(upgradeToPro, true) }

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr
180180

181181
await that.context.update({ triggered: true });
182182

183-
showCopilotView(viewsService);
183+
showCopilotView(viewsService, layoutService);
184184
ensureSideBarChatViewSize(400, viewDescriptorService, layoutService);
185185

186186
if (startSetup === true && !ASK_FOR_PUBLIC_CODE_MATCHES) {
@@ -616,7 +616,8 @@ class ChatSetupController extends Disposable {
616616
@IProgressService private readonly progressService: IProgressService,
617617
@IChatAgentService private readonly chatAgentService: IChatAgentService,
618618
@IActivityService private readonly activityService: IActivityService,
619-
@ICommandService private readonly commandService: ICommandService
619+
@ICommandService private readonly commandService: ICommandService,
620+
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService
620621
) {
621622
super();
622623

@@ -692,7 +693,7 @@ class ChatSetupController extends Disposable {
692693
let session: AuthenticationSession | undefined;
693694
let entitlement: ChatEntitlement | undefined;
694695
try {
695-
showCopilotView(this.viewsService);
696+
showCopilotView(this.viewsService, this.layoutService);
696697
session = await this.authenticationService.createSession(defaultChat.providerId, defaultChat.providerScopes[0]);
697698
entitlement = await this.requests.forceResolveEntitlement(session);
698699
} catch (error) {
@@ -714,7 +715,7 @@ class ChatSetupController extends Disposable {
714715
const wasInstalled = this.context.state.installed;
715716
let didSignUp = false;
716717
try {
717-
showCopilotView(this.viewsService);
718+
showCopilotView(this.viewsService, this.layoutService);
718719

719720
if (entitlement !== ChatEntitlement.Limited && entitlement !== ChatEntitlement.Pro && entitlement !== ChatEntitlement.Unavailable) {
720721
didSignUp = await this.requests.signUpLimited(session, options);
@@ -749,7 +750,7 @@ class ChatSetupController extends Disposable {
749750

750751
const currentActiveElement = getActiveElement();
751752
if (activeElement === currentActiveElement || currentActiveElement === mainWindow.document.body) {
752-
(await showCopilotView(this.viewsService))?.focusInput();
753+
(await showCopilotView(this.viewsService, this.layoutService))?.focusInput();
753754
}
754755
}
755756
}
@@ -953,7 +954,7 @@ class ChatSetupContext extends Disposable {
953954
super();
954955

955956
this.checkExtensionInstallation();
956-
this.updateContext();
957+
this.updateContextSync();
957958
}
958959

959960
private async checkExtensionInstallation(): Promise<void> {
@@ -1014,6 +1015,10 @@ class ChatSetupContext extends Disposable {
10141015
private async updateContext(): Promise<void> {
10151016
await this.updateBarrier?.wait();
10161017

1018+
this.updateContextSync();
1019+
}
1020+
1021+
private updateContextSync(): void {
10171022
this.logService.trace(`[chat setup] updateContext(): ${JSON.stringify(this._state)}`);
10181023

10191024
if (this._state.triggered && !this._state.installed) {
@@ -1060,7 +1065,14 @@ function isCopilotEditsViewActive(viewsService: IViewsService): boolean {
10601065
return viewsService.getFocusedView()?.id === EditsViewId;
10611066
}
10621067

1063-
function showCopilotView(viewsService: IViewsService): Promise<IChatWidget | undefined> {
1068+
function showCopilotView(viewsService: IViewsService, layoutService: IWorkbenchLayoutService): Promise<IChatWidget | undefined> {
1069+
1070+
// Ensure main window is in front
1071+
if (layoutService.activeContainer !== layoutService.mainContainer) {
1072+
layoutService.mainContainer.focus();
1073+
}
1074+
1075+
// Bring up the correct view
10641076
if (isCopilotEditsViewActive(viewsService)) {
10651077
return showEditsView(viewsService);
10661078
} else {

0 commit comments

Comments
 (0)