@@ -53,13 +53,13 @@ import { IWorkspaceContextService, WorkbenchState } from '../../../../platform/w
5353import { EditorResourceAccessor } from '../../../../workbench/common/editor.js' ;
5454import { IEditorService } from '../../../../workbench/services/editor/common/editorService.js' ;
5555import { ViewContainerLocation } from '../../../common/views.js' ;
56- import { IChatEntitlementService } from '../../../services/chat/common/chatEntitlementService.js' ;
5756import { IWorkbenchLayoutService , Position } from '../../../services/layout/browser/layoutService.js' ;
5857import { IViewsService } from '../../../services/views/common/viewsService.js' ;
5958import { checkModeOption } from '../common/chat.js' ;
6059import { IChatAgentCommand , IChatAgentData , IChatAgentService } from '../common/chatAgents.js' ;
61- import { ChatContextKeyExprs , ChatContextKeys } from '../common/chatContextKeys.js' ;
60+ import { ChatContextKeys } from '../common/chatContextKeys.js' ;
6261import { applyingChatEditsFailedContextKey , decidedChatEditingResourceContextKey , hasAppliedChatEditsContextKey , hasUndecidedChatEditingResourceContextKey , IChatEditingService , IChatEditingSession , inChatEditingSessionContextKey , ModifiedFileEntryState } from '../common/chatEditingService.js' ;
62+ import { ChatEntitlement , IChatEntitlementService } from '../../../services/chat/common/chatEntitlementService.js' ;
6363import { IChatLayoutService } from '../common/chatLayoutService.js' ;
6464import { IChatModel , IChatResponseModel } from '../common/chatModel.js' ;
6565import { IChatModeService } from '../common/chatModes.js' ;
@@ -431,6 +431,12 @@ export class ChatWidget extends Disposable implements IChatWidget {
431431
432432 readonly viewContext : IChatWidgetViewContext ;
433433
434+ private shouldShowChatSetup ( ) : boolean {
435+ // Check if chat is not installed OR user can sign up for free
436+ // Equivalent to: ChatContextKeys.Setup.installed.negate() OR ChatContextKeys.Entitlement.canSignUp
437+ return ! this . chatEntitlementService . sentiment . installed || this . chatEntitlementService . entitlement === ChatEntitlement . Available ;
438+ }
439+
434440 get supportsChangingModes ( ) : boolean {
435441 return ! ! this . viewOptions . supportsChangingModes ;
436442 }
@@ -657,23 +663,30 @@ export class ChatWidget extends Disposable implements IChatWidget {
657663
658664 this . _register ( this . onDidChangeParsedInput ( ( ) => this . updateChatInputContext ( ) ) ) ;
659665
660- this . _register ( this . contextKeyService . onDidChangeContext ( e => {
661- if ( e . affectsSome ( new Set ( [
662- ChatContextKeys . Setup . installed . key ,
663- ChatContextKeys . Entitlement . canSignUp . key
664- ] ) ) ) {
665- // reset the input in welcome view if it was rendered in experimental mode
666- if ( this . container . classList . contains ( 'new-welcome-view' ) && ! this . contextKeyService . contextMatchesRules ( ChatContextKeyExprs . chatSetupTriggerContext ) ) {
667- this . container . classList . remove ( 'new-welcome-view' ) ;
668- const renderFollowups = this . viewOptions . renderFollowups ?? false ;
669- const renderStyle = this . viewOptions . renderStyle ;
670- this . createInput ( this . container , { renderFollowups, renderStyle } ) ;
671- this . input . setChatMode ( this . lastWelcomeViewChatMode ?? ChatModeKind . Ask ) ;
672- }
666+ // Listen to entitlement and sentiment changes instead of context keys
667+ this . _register ( this . chatEntitlementService . onDidChangeEntitlement ( ( ) => {
668+ if ( ! this . shouldShowChatSetup ( ) ) {
669+ this . resetWelcomeViewInput ( ) ;
670+ }
671+ } ) ) ;
672+ this . _register ( this . chatEntitlementService . onDidChangeSentiment ( ( ) => {
673+ if ( ! this . shouldShowChatSetup ( ) ) {
674+ this . resetWelcomeViewInput ( ) ;
673675 }
674676 } ) ) ;
675677 }
676678
679+ private resetWelcomeViewInput ( ) : void {
680+ // reset the input in welcome view if it was rendered in experimental mode
681+ if ( this . container . classList . contains ( 'new-welcome-view' ) ) {
682+ this . container . classList . remove ( 'new-welcome-view' ) ;
683+ const renderFollowups = this . viewOptions . renderFollowups ?? false ;
684+ const renderStyle = this . viewOptions . renderStyle ;
685+ this . createInput ( this . container , { renderFollowups, renderStyle } ) ;
686+ this . input . setChatMode ( this . lastWelcomeViewChatMode ?? ChatModeKind . Ask ) ;
687+ }
688+ }
689+
677690 private _lastSelectedAgent : IChatAgentData | undefined ;
678691 set lastSelectedAgent ( agent : IChatAgentData | undefined ) {
679692 this . parsedChatRequest = undefined ;
@@ -929,12 +942,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
929942
930943
931944 // reset the input in welcome view if it was rendered in experimental mode
932- if ( this . container . classList . contains ( 'new-welcome-view' ) && this . viewModel ?. getItems ( ) . length ) {
933- this . container . classList . remove ( 'new-welcome-view' ) ;
934- const renderFollowups = this . viewOptions . renderFollowups ?? false ;
935- const renderStyle = this . viewOptions . renderStyle ;
936- this . createInput ( this . container , { renderFollowups, renderStyle } ) ;
937- this . input . setChatMode ( this . lastWelcomeViewChatMode ?? ChatModeKind . Ask ) ;
945+ if ( this . viewModel ?. getItems ( ) . length ) {
946+ this . resetWelcomeViewInput ( ) ;
938947 this . focusInput ( ) ;
939948 }
940949
@@ -1021,7 +1030,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
10211030 if ( ! additionalMessage ) {
10221031 additionalMessage = this . _getGenerateInstructionsMessage ( ) ;
10231032 }
1024- if ( this . contextKeyService . contextMatchesRules ( ChatContextKeyExprs . chatSetupTriggerContext ) ) {
1033+ if ( this . shouldShowChatSetup ( ) ) {
10251034 welcomeContent = this . getNewWelcomeViewContent ( ) ;
10261035 this . container . classList . add ( 'new-welcome-view' ) ;
10271036 } else if ( expEmptyState ) {
0 commit comments