@@ -52,7 +52,7 @@ import { CHAT_CATEGORY, CHAT_SETUP_ACTION_ID, CHAT_SETUP_ACTION_LABEL } from './
52
52
import { ChatViewId , EditsViewId , ensureSideBarChatViewSize , preferCopilotEditsView , showCopilotView } from './chat.js' ;
53
53
import { CHAT_EDITING_SIDEBAR_PANEL_ID , CHAT_SIDEBAR_PANEL_ID } from './chatViewPane.js' ;
54
54
import { ChatViewsWelcomeExtensions , IChatViewsWelcomeContributionRegistry } from './viewsWelcome/chatViewsWelcome.js' ;
55
- import { IChatQuotasService } from '../common/chatQuotasService.js' ;
55
+ import { ChatQuotasService , IChatQuotasService } from '../common/chatQuotasService.js' ;
56
56
import { mainWindow } from '../../../../base/browser/window.js' ;
57
57
import { IOpenerService } from '../../../../platform/opener/common/opener.js' ;
58
58
import { URI } from '../../../../base/common/uri.js' ;
@@ -64,11 +64,10 @@ import { ExtensionUrlHandlerOverrideRegistry } from '../../../services/extension
64
64
import { IWorkspaceTrustRequestService } from '../../../../platform/workspace/common/workspaceTrust.js' ;
65
65
import { toErrorMessage } from '../../../../base/common/errorMessage.js' ;
66
66
import { StopWatch } from '../../../../base/common/stopwatch.js' ;
67
- import { IConfigurationRegistry , Extensions as ConfigurationExtensions , IConfigurationNode } from '../../../../platform/configuration/common/configurationRegistry.js' ;
67
+ import { IConfigurationRegistry , Extensions as ConfigurationExtensions } from '../../../../platform/configuration/common/configurationRegistry.js' ;
68
68
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js' ;
69
69
import { ILifecycleService } from '../../../services/lifecycle/common/lifecycle.js' ;
70
70
import { equalsIgnoreCase } from '../../../../base/common/strings.js' ;
71
- import { IWorkbenchAssignmentService } from '../../../services/assignment/common/assignmentService.js' ;
72
71
import { ChatEntitlement , IChatEntitlements , IChatEntitlementsService } from '../common/chatEntitlementsService.js' ;
73
72
import { IStatusbarService } from '../../../services/statusbar/browser/statusbar.js' ;
74
73
@@ -99,13 +98,39 @@ export class ChatEntitlementsService extends Disposable implements IChatEntitlem
99
98
100
99
declare _serviceBrand : undefined ;
101
100
101
+ readonly onDidChangeEntitlement = Event . map (
102
+ Event . filter (
103
+ this . contextKeyService . onDidChangeContext , e => e . affectsSome ( new Set ( [
104
+ ChatContextKeys . Setup . pro . key ,
105
+ ChatContextKeys . Setup . limited . key ,
106
+ ChatContextKeys . Setup . canSignUp . key ,
107
+ ChatContextKeys . Setup . signedOut . key
108
+ ] ) ) , this . _store
109
+ ) , ( ) => { } , this . _store
110
+ ) ;
111
+
102
112
readonly context : Lazy < ChatSetupContext > | undefined ;
103
113
readonly requests : Lazy < ChatSetupRequests > | undefined ;
104
114
115
+ get entitlement ( ) : ChatEntitlement {
116
+ if ( this . contextKeyService . getContextKeyValue < boolean > ( ChatContextKeys . Setup . pro . key ) === true ) {
117
+ return ChatEntitlement . Pro ;
118
+ } else if ( this . contextKeyService . getContextKeyValue < boolean > ( ChatContextKeys . Setup . limited . key ) === true ) {
119
+ return ChatEntitlement . Limited ;
120
+ } else if ( this . contextKeyService . getContextKeyValue < boolean > ( ChatContextKeys . Setup . canSignUp . key ) === true ) {
121
+ return ChatEntitlement . Available ;
122
+ } else if ( this . contextKeyService . getContextKeyValue < boolean > ( ChatContextKeys . Setup . signedOut . key ) === true ) {
123
+ return ChatEntitlement . Unknown ;
124
+ }
125
+
126
+ return ChatEntitlement . Unresolved ;
127
+ }
128
+
105
129
constructor (
106
130
@IInstantiationService instantiationService : IInstantiationService ,
107
131
@IProductService productService : IProductService ,
108
- @IWorkbenchEnvironmentService environmentService : IWorkbenchEnvironmentService
132
+ @IWorkbenchEnvironmentService environmentService : IWorkbenchEnvironmentService ,
133
+ @IContextKeyService private readonly contextKeyService : IContextKeyService ,
109
134
) {
110
135
super ( ) ;
111
136
@@ -138,8 +163,7 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr
138
163
@IInstantiationService private readonly instantiationService : IInstantiationService ,
139
164
@ICommandService private readonly commandService : ICommandService ,
140
165
@ITelemetryService private readonly telemetryService : ITelemetryService ,
141
- @IWorkbenchAssignmentService private readonly experimentService : IWorkbenchAssignmentService ,
142
- @IChatEntitlementsService chatEntitlementsService : ChatEntitlementsService ,
166
+ @IChatEntitlementsService chatEntitlementsService : ChatEntitlementsService
143
167
) {
144
168
super ( ) ;
145
169
@@ -154,7 +178,6 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr
154
178
this . registerChatWelcome ( controller , context ) ;
155
179
this . registerActions ( context , requests ) ;
156
180
this . registerUrlLinkHandler ( ) ;
157
- this . registerSetting ( context ) ;
158
181
}
159
182
160
183
private registerChatWelcome ( controller : Lazy < ChatSetupController > , context : ChatSetupContext ) : void {
@@ -335,36 +358,6 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr
335
358
}
336
359
} ) ) ;
337
360
}
338
-
339
- private registerSetting ( context : ChatSetupContext ) : void {
340
- const configurationRegistry = Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration ) ;
341
-
342
- let lastNode : IConfigurationNode | undefined ;
343
- const registerSetting = ( ) => {
344
- const treatmentId = context . state . entitlement === ChatEntitlement . Limited ?
345
- 'chatAgentMaxRequestsFree' :
346
- 'chatAgentMaxRequestsPro' ;
347
- this . experimentService . getTreatment < number > ( treatmentId ) . then ( value => {
348
- const defaultValue = value ?? ( context . state . entitlement === ChatEntitlement . Limited ? 5 : 15 ) ;
349
- const node : IConfigurationNode = {
350
- id : 'chatSidebar' ,
351
- title : localize ( 'interactiveSessionConfigurationTitle' , "Chat" ) ,
352
- type : 'object' ,
353
- properties : {
354
- 'chat.agent.maxRequests' : {
355
- type : 'number' ,
356
- markdownDescription : localize ( 'chat.agent.maxRequests' , "The maximum number of requests to allow Copilot Edits to use per-turn in agent mode. When the limit is reached, Copilot will ask the user to confirm that it should keep working. \n\n> **Note**: For users on the Copilot Free plan, note that each agent mode request currently uses one chat request." ) ,
357
- default : defaultValue ,
358
- tags : [ 'experimental' ]
359
- } ,
360
- }
361
- } ;
362
- configurationRegistry . updateConfigurations ( { remove : lastNode ? [ lastNode ] : [ ] , add : [ node ] } ) ;
363
- lastNode = node ;
364
- } ) ;
365
- } ;
366
- this . _register ( Event . runAndSubscribe ( Event . debounce ( context . onDidChange , ( ) => { } , 1000 ) , ( ) => registerSetting ( ) ) ) ;
367
- }
368
361
}
369
362
370
363
//#endregion
@@ -427,7 +420,7 @@ class ChatSetupRequests extends Disposable {
427
420
@IAuthenticationService private readonly authenticationService : IAuthenticationService ,
428
421
@ILogService private readonly logService : ILogService ,
429
422
@IRequestService private readonly requestService : IRequestService ,
430
- @IChatQuotasService private readonly chatQuotasService : IChatQuotasService ,
423
+ @IChatQuotasService private readonly chatQuotasService : ChatQuotasService ,
431
424
@IDialogService private readonly dialogService : IDialogService ,
432
425
@IOpenerService private readonly openerService : IOpenerService ,
433
426
@IConfigurationService private readonly configurationService : IConfigurationService
@@ -602,13 +595,16 @@ class ChatSetupRequests extends Disposable {
602
595
entitlement = ChatEntitlement . Unavailable ;
603
596
}
604
597
598
+ const chatRemaining = entitlementsResponse . limited_user_quotas ?. chat ;
599
+ const completionsRemaining = entitlementsResponse . limited_user_quotas ?. completions ;
600
+
605
601
const entitlements : IChatEntitlements = {
606
602
entitlement,
607
603
quotas : {
608
604
chatTotal : entitlementsResponse . monthly_quotas ?. chat ,
609
605
completionsTotal : entitlementsResponse . monthly_quotas ?. completions ,
610
- chatRemaining : entitlementsResponse . limited_user_quotas ?. chat ,
611
- completionsRemaining : entitlementsResponse . limited_user_quotas ?. completions ,
606
+ chatRemaining : typeof chatRemaining === 'number' ? Math . max ( 0 , chatRemaining ) : undefined ,
607
+ completionsRemaining : typeof completionsRemaining === 'number' ? Math . max ( 0 , completionsRemaining ) : undefined ,
612
608
resetDate : entitlementsResponse . limited_user_reset_date
613
609
}
614
610
} ;
0 commit comments