Skip to content

Commit

Permalink
add limited
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 24, 2024
1 parent 6ed36ff commit 977c6b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/vs/base/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,6 @@ export interface IDefaultChatAgent {
readonly entitlementChatEnabled: string;
readonly entitlementSkuLimitedUrl: string;
readonly entitlementSkuLimitedEnabled: string;
readonly entitlementSkuType: string;
readonly entitlementSkuTypeLimited: string;
}
28 changes: 20 additions & 8 deletions src/vs/workbench/contrib/chat/browser/chatSetup.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const defaultChat = {
entitlementUrl: product.defaultChatAgent?.entitlementUrl ?? '',
entitlementChatEnabled: product.defaultChatAgent?.entitlementChatEnabled ?? '',
entitlementSkuLimitedUrl: product.defaultChatAgent?.entitlementSkuLimitedUrl ?? '',
entitlementSkuLimitedEnabled: product.defaultChatAgent?.entitlementSkuLimitedEnabled ?? ''
entitlementSkuLimitedEnabled: product.defaultChatAgent?.entitlementSkuLimitedEnabled ?? '',
entitlementSkuType: product.defaultChatAgent?.entitlementSkuType ?? '',
entitlementSkuTypeLimited: product.defaultChatAgent?.entitlementSkuTypeLimited ?? ''
};

enum ChatEntitlement {
Expand Down Expand Up @@ -138,15 +140,17 @@ class ChatSetupContribution extends Disposable implements IWorkbenchContribution
//#region Entitlements Resolver

type ChatSetupEntitlementClassification = {
entitled: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Flag indicating if the user is chat setup entitled' };
entitlement: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Flag indicating the chat entitlement state' };
entitled: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Flag indicating if the user is chat setup entitled' };
limited: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Flag indicating if the user is chat setup limited' };
owner: 'bpasero';
comment: 'Reporting chat setup entitlements';
};

type ChatSetupEntitlementEvent = {
entitled: boolean;
entitlement: ChatEntitlement;
entitled: boolean;
limited: boolean;
};

class ChatSetupEntitlementResolver extends Disposable {
Expand Down Expand Up @@ -293,12 +297,13 @@ class ChatSetupEntitlementResolver extends Disposable {

const result = {
entitlement: Boolean(parsedResult[defaultChat.entitlementSkuLimitedEnabled]) ? ChatEntitlement.Available : ChatEntitlement.Unavailable,
entitled: Boolean(parsedResult[defaultChat.entitlementChatEnabled])
entitled: Boolean(parsedResult[defaultChat.entitlementChatEnabled]),
limited: Boolean(parsedResult[defaultChat.entitlementSkuType] === defaultChat.entitlementSkuTypeLimited)
};

this.chatSetupContextKeys.update({ entitled: result.entitled });
this.chatSetupContextKeys.update({ entitled: result.entitled, limited: result.limited });

this.logService.trace(`[chat setup] entitlement: resolved to ${result.entitlement}, entitled: ${result.entitled}`);
this.logService.trace(`[chat setup] entitlement: resolved to ${result.entitlement}, entitled: ${result.entitled}, limited: ${result.limited}`);
this.telemetryService.publicLog2<ChatSetupEntitlementEvent, ChatSetupEntitlementClassification>('chatInstallEntitlement', result);

return result.entitlement;
Expand Down Expand Up @@ -570,10 +575,12 @@ class ChatSetupContextKeys {
private static readonly CHAT_EXTENSION_INSTALLED = 'chat.extensionInstalled';

private readonly chatSetupEntitledContextKey = ChatContextKeys.Setup.entitled.bindTo(this.contextKeyService);
private readonly chatSetupLimitedContextKey = ChatContextKeys.Setup.limited.bindTo(this.contextKeyService);
private readonly chatSetupTriggeredContext = ChatContextKeys.Setup.triggered.bindTo(this.contextKeyService);
private readonly chatSetupInstalledContext = ChatContextKeys.Setup.installed.bindTo(this.contextKeyService);

private chatSetupEntitled = false;
private chatSetupLimited = false;

constructor(
@IContextKeyService private readonly contextKeyService: IContextKeyService,
Expand All @@ -585,8 +592,8 @@ class ChatSetupContextKeys {

update(context: { chatInstalled: boolean }): void;
update(context: { triggered: boolean }): void;
update(context: { entitled: boolean }): void;
update(context: { triggered?: boolean; chatInstalled?: boolean; entitled?: boolean }): void {
update(context: { entitled: boolean; limited: boolean }): void;
update(context: { triggered?: boolean; chatInstalled?: boolean; entitled?: boolean; limited?: boolean }): void {
if (typeof context.chatInstalled === 'boolean') {
this.storageService.store(ChatSetupContextKeys.CHAT_EXTENSION_INSTALLED, context.chatInstalled, StorageScope.PROFILE, StorageTarget.MACHINE);
if (context.chatInstalled) {
Expand All @@ -606,6 +613,10 @@ class ChatSetupContextKeys {
this.chatSetupEntitled = context.entitled;
}

if (typeof context.limited === 'boolean') {
this.chatSetupLimited = context.limited;
}

this.updateContext();
}

Expand All @@ -623,6 +634,7 @@ class ChatSetupContextKeys {
this.chatSetupTriggeredContext.set(showChatSetup);
this.chatSetupInstalledContext.set(chatInstalled);
this.chatSetupEntitledContextKey.set(this.chatSetupEntitled);
this.chatSetupLimitedContextKey.set(this.chatSetupLimited);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export namespace ChatContextKeys {

export const Setup = {
entitled: new RawContextKey<boolean>('chatSetupEntitled', false, { type: 'boolean', description: localize('chatSetupEntitled', "True when user is a chat entitled user.") }),
limited: new RawContextKey<boolean>('chatSetupLimited', false, { type: 'boolean', description: localize('chatSetupLimited', "True when user is a chat limited user.") }),
triggered: new RawContextKey<boolean>('chatSetupTriggered', false, { type: 'boolean', description: localize('chatSetupTriggered', "True when chat setup is triggered.") }),
installed: new RawContextKey<boolean>('chatSetupInstalled', false, { type: 'boolean', description: localize('chatSetupInstalled', "True when the chat extension is installed.") }),
};
Expand Down

0 comments on commit 977c6b5

Please sign in to comment.