import { CancellationToken } from "../../../../base/common/cancellation.js"; import { Event } from "../../../../base/common/event.js"; import { Lazy } from "../../../../base/common/lazy.js"; import { Disposable } from "../../../../base/common/lifecycle.js"; import { IConfigurationService } from "../../../../platform/configuration/common/configuration.service.js"; import { RawContextKey } from "../../../../platform/contextkey/common/contextkey.js"; import { IContextKeyService } from "../../../../platform/contextkey/common/contextkey.service.js"; import { IDialogService } from "../../../../platform/dialogs/common/dialogs.service.js"; import { IInstantiationService } from "../../../../platform/instantiation/common/instantiation.js"; import { ILogService } from "../../../../platform/log/common/log.service.js"; import { IProductService } from "../../../../platform/product/common/productService.service.js"; import { IRequestService } from "../../../../platform/request/common/request.service.js"; import { IStorageService } from "../../../../platform/storage/common/storage.service.js"; import { ITelemetryService } from "../../../../platform/telemetry/common/telemetry.service.js"; import { IAuthenticationService } from "../../authentication/common/authentication.service.js"; import { IOpenerService } from "../../../../platform/opener/common/opener.service.js"; import { IWorkbenchEnvironmentService } from "../../environment/common/environmentService.service.js"; import { ILifecycleService } from "../../lifecycle/common/lifecycle.service.js"; import { IObservable } from "../../../../base/common/observable.js"; import { IDefaultAccountService } from "../../../../platform/defaultAccount/common/defaultAccount.service.js"; import { IDefaultAccount, IEntitlementsData } from "../../../../base/common/defaultAccount.js"; import { IChatEntitlementService } from "./chatEntitlementService.service.js"; export declare namespace ChatEntitlementContextKeys { const Setup: { hidden: RawContextKey; installed: RawContextKey; disabled: RawContextKey; disabledInWorkspace: RawContextKey; untrusted: RawContextKey; later: RawContextKey; registered: RawContextKey; completed: RawContextKey; }; const Entitlement: { signedOut: RawContextKey; canSignUp: RawContextKey; planFree: RawContextKey; planPro: RawContextKey; planEdu: RawContextKey; planProPlus: RawContextKey; planMax: RawContextKey; planBusiness: RawContextKey; planEnterprise: RawContextKey; organisations: RawContextKey; internal: RawContextKey; sku: RawContextKey; }; const chatQuotaExceeded: RawContextKey; const completionsQuotaExceeded: RawContextKey; const chatAnonymous: RawContextKey; const clientByokEnabled: RawContextKey; const hasByokModels: RawContextKey; } export declare enum ChatEntitlement { /** Signed out */ Unknown = 1, /** Signed in but not yet resolved */ Unresolved = 2, /** Signed in and entitled to Free */ Available = 3, /** Signed in but not entitled to Free */ Unavailable = 4, /** Signed-up to Free */ Free = 5, /** Signed-up to EDU */ EDU = 10, /** Signed-up to Pro */ Pro = 6, /** Signed-up to Pro Plus */ ProPlus = 7, /** Signed-up to Business */ Business = 8, /** Signed-up to Enterprise */ Enterprise = 9, /** Signed-up to Max */ Max = 11 } export interface IChatSentiment { /** * Whether the user has completed the setup flow or not, regardless of the outcome */ completed?: boolean; /** * User has Chat installed. */ installed?: boolean; /** * User signals no intent in using Chat. * * Note: in contrast to `disabled`, this should not only disable * Chat but also hide all of its UI. */ hidden?: boolean; /** * User signals intent to disable Chat. * * Note: in contrast to `hidden`, this should not hide * Chat but but disable its functionality. */ disabled?: boolean; /** * Chat is disabled at the workspace level * * Note: in contrast to `hidden` (which hides all UI globally), * this only disables Chat in the current workspace while * keeping its UI visible so the user can re-enable it. */ disabledInWorkspace?: boolean; /** * Chat is disabled due to missing workspace trust. * * Note: even though this disables Chat, we want to treat it * different from the `disabled` state that is by explicit * user choice. */ untrusted?: boolean; /** * User signals intent to use Chat later. */ later?: boolean; /** * User has registered as Free or Pro user. */ registered?: boolean; } /** * The inputs needed to decide whether Chat still requires the user to run setup * (sign in / sign up / trust / enable) before it can service a request. */ export interface IChatSetupRequirement { /** Whether the setup flow has been completed (any outcome). */ readonly completed: boolean; /** Whether the chat extension is disabled for a reason other than trust. */ readonly disabled: boolean; /** Whether the chat extension is disabled because the workspace is untrusted. */ readonly untrusted: boolean; /** The user's last known or resolved entitlement. */ readonly entitlement: ChatEntitlement; /** Whether anonymous (signed-out) Chat access is enabled. */ readonly anonymous: boolean; /** Whether BYOK models are available. */ readonly hasByokModels: boolean; } /** * Returns whether Chat requires setup before it can service a request. * The model picker uses a narrower condition that only surfaces interactive setup. */ export declare function chatRequiresSetup(context: IChatSetupRequirement): boolean; /** * Checks the chat entitlements to see if the user falls into the paid category * @param chatEntitlement The chat entitlement to check * @returns Whether or not they are a paid user */ export declare function isProUser(chatEntitlement: ChatEntitlement): boolean; /** * Gets the full plan name for the given chat entitlement * @param chatEntitlement The chat entitlement to get the plan name for * @returns The localized full plan name (e.g., "Copilot Pro", "Copilot Free") */ export declare function getChatPlanName(chatEntitlement: ChatEntitlement): string; interface IChatQuotasAccessor { clearQuotas(): void; acceptQuotas(quotas: IQuotas): void; } export declare class ChatEntitlementService extends Disposable implements IChatEntitlementService { private readonly contextKeyService; private readonly configurationService; private readonly telemetryService; private readonly logService; private readonly storageService; _serviceBrand: undefined; private static readonly CACHED_UBB_STORAGE_KEY; readonly context: Lazy | undefined; readonly requests: Lazy | undefined; constructor(instantiationService: IInstantiationService, productService: IProductService, environmentService: IWorkbenchEnvironmentService, contextKeyService: IContextKeyService, configurationService: IConfigurationService, telemetryService: ITelemetryService, logService: ILogService, storageService: IStorageService); readonly onDidChangeEntitlement: Event; readonly entitlementObs: IObservable; get entitlement(): ChatEntitlement; get isInternal(): boolean; get organisations(): string[] | undefined; get sku(): string | undefined; get copilotTrackingId(): string | undefined; get clientByokEnabled(): boolean; get hasByokModels(): boolean; private readonly _onDidChangeQuotaExceeded; readonly onDidChangeQuotaExceeded: Event; private readonly _onDidChangeQuotaRemaining; readonly onDidChangeQuotaRemaining: Event; private readonly _onDidChangeUsageBasedBilling; readonly onDidChangeUsageBasedBilling: Event; private _quotas; private quotaCopilotTrackingId; get quotas(): IQuotas; private readonly chatQuotaExceededContextKey; private readonly completionsQuotaExceededContextKey; private ExtensionQuotaContextKeys; private registerListeners; acceptQuotas(incomingQuotas: IQuotas): void; private compareQuotas; clearQuotas(): void; private updateContextKeys; readonly onDidChangeSentiment: Event; readonly sentimentObs: IObservable; get sentiment(): IChatSentiment; private readonly anonymousContextKey; private readonly _onDidChangeAnonymous; readonly onDidChangeAnonymous: Event; readonly anonymousObs: IObservable; get anonymous(): boolean; markAnonymousRateLimited(): void; markSetupCompleted(): void; setForceHidden(hidden: boolean): void; update(token: CancellationToken): Promise; } interface IEntitlements { readonly entitlement: ChatEntitlement; readonly organisations?: string[]; readonly isStaff?: boolean; readonly sku?: string; readonly copilotTrackingId?: string; readonly quotas?: IQuotas; } /** Shared exhaustion semantics for both controls and continuation suggestions. */ export declare function isChatQuotaExceeded(entitlement: ChatEntitlement, quotas: IChatEntitlementService["quotas"]): boolean; /** Unknown premium allowance cannot establish that a paid route is usable. */ export declare function hasUsableCopilotPremiumQuota(entitlement: ChatEntitlement, quotas: IChatEntitlementService["quotas"]): boolean; export interface IQuotaSnapshot { readonly percentRemaining: number; readonly unlimited: boolean; readonly hasQuota?: boolean; /** When this quota resets, as a Unix timestamp in *seconds*. */ readonly resetAt?: number; readonly usageBasedBilling?: boolean; readonly entitlement?: number; readonly quotaRemaining?: number; /** * Aggregate credits consumed, only for users whose org sets no user-level budget. Drawn from * an unmeterable pool, so it has no denominator. See microsoft/vscode#319589. */ readonly creditsUsed?: number; } export declare enum QuotaUsageKind { /** * Consumption measured against a known entitlement, best surfaced as a percentage. */ Percentage = 0, /** * Absolute credits consumed. Used for plans without a cap to measure a percentage against. */ CreditsUsed = 1 } export type IQuotaUsage = { readonly kind: QuotaUsageKind.Percentage; readonly usedPercentage: number; /** * Credits consumed and the entitlement they are measured against. Both are * `undefined` when the plan reports no entitlement to break the percentage down into. */ readonly used: number | undefined; readonly total: number | undefined; } | { readonly kind: QuotaUsageKind.CreditsUsed; readonly creditsUsed: number; }; /** * Derives how a quota snapshot should be surfaced, so that every quota display agrees on * what "used" means. Returns `undefined` when the snapshot carries no usage worth showing, * i.e. an unlimited plan that reports no credits, or a depleted pooled organization quota. */ export declare function getQuotaUsage(quota: IQuotaSnapshot | undefined): IQuotaUsage | undefined; export interface IQuotaReset { readonly date: Date; /** Whether the underlying source carries a time of day worth surfacing. */ readonly hasTime: boolean; } /** * Resolves which reset applies to a quota. A snapshot's own `resetAt` is authoritative for * that category and wins over the coarser account-level reset, so that a quota is never * paired with a clock that does not govern it. */ export declare function getQuotaReset(quota: IQuotaSnapshot | undefined, accountReset: { readonly resetDate?: string; readonly resetDateHasTime?: boolean; }): IQuotaReset | undefined; export interface IRateLimitSnapshot { readonly percentRemaining: number; readonly unlimited: boolean; readonly resetDate?: string; } export interface IQuotas { readonly resetDate?: string; readonly resetDateHasTime?: boolean; readonly usageBasedBilling?: boolean; readonly canUpgradePlan?: boolean; readonly chat?: IQuotaSnapshot; readonly completions?: IQuotaSnapshot; readonly premiumChat?: IQuotaSnapshot; readonly additionalUsageEnabled?: boolean; readonly additionalUsageCount?: number; readonly additionalUsageEntitlement?: number; readonly sessionRateLimit?: IRateLimitSnapshot; readonly weeklyRateLimit?: IRateLimitSnapshot; } export declare function parseQuotas(entitlementsData: IEntitlementsData): IQuotas; export declare class ChatEntitlementRequests extends Disposable { private readonly context; private readonly chatQuotasAccessor; private readonly telemetryService; private readonly logService; private readonly requestService; private readonly dialogService; private readonly openerService; private readonly lifecycleService; private readonly defaultAccountService; private readonly authenticationService; private state; private pendingResolveCts; constructor(context: ChatEntitlementContext, chatQuotasAccessor: IChatQuotasAccessor, telemetryService: ITelemetryService, logService: ILogService, requestService: IRequestService, dialogService: IDialogService, openerService: IOpenerService, lifecycleService: ILifecycleService, defaultAccountService: IDefaultAccountService, authenticationService: IAuthenticationService); private registerListeners; private resolve; private resolveEntitlement; private doResolveEntitlement; private toQuotas; private request; private update; forceResolveEntitlement(token?: Readonly): Promise; signUpFree(): Promise; private doSignUpFree; private getSessions; private onUnknownSignUpError; private onUnprocessableSignUpError; signIn(options?: { useSocialProvider?: string; additionalScopes?: readonly string[]; }): Promise<{ defaultAccount?: IDefaultAccount; entitlements?: IEntitlements; }>; dispose(): void; } export interface IChatEntitlementContextState extends IChatSentiment { /** * Users last known or resolved entitlement. */ entitlement: ChatEntitlement; /** * User's last known or resolved raw SKU type. */ sku: string | undefined; /** * User's last known or resolved organisations. */ organisations: string[] | undefined; /** * Whether the user's last known or resolved account is a GitHub or Microsoft staff account. */ isStaff: boolean | undefined; /** * User's Copilot tracking ID from the entitlement API. */ copilotTrackingId: string | undefined; } export declare class ChatEntitlementContext extends Disposable { private readonly storageService; private readonly logService; private readonly configurationService; private readonly telemetryService; private static readonly CHAT_ENTITLEMENT_CONTEXT_STORAGE_KEY; private static readonly CHAT_ENTITLEMENT_CONTEXT_MIGRATED_STORAGE_KEY; private readonly canSignUpContextKey; private readonly signedOutContextKey; private readonly freeContextKey; private readonly eduContextKey; private readonly proContextKey; private readonly proPlusContextKey; private readonly maxContextKey; private readonly businessContextKey; private readonly enterpriseContextKey; private readonly organisationsContextKey; private readonly isInternalContextKey; private readonly skuContextKey; private readonly completedContext; private readonly hiddenContext; private readonly disabledInWorkspaceContext; private readonly laterContext; private readonly installedContext; private readonly disabledContext; private readonly untrustedContext; private readonly registeredContext; private _state; private suspendedState; get state(): IChatEntitlementContextState; private readonly _onDidChange; readonly onDidChange: Event; private updateBarrier; constructor(contextKeyService: IContextKeyService, storageService: IStorageService, logService: ILogService, configurationService: IConfigurationService, telemetryService: ITelemetryService); private registerListeners; private _forceHidden; private withConfiguration; setForceHidden(hidden: boolean): void; update(context: { installed: boolean; disabled: boolean; untrusted: boolean; disabledInWorkspace: boolean; }): Promise; update(context: { completed: true; }): Promise; update(context: { hidden: false; }): Promise; update(context: { later: boolean; }): Promise; update(context: { entitlement: ChatEntitlement; organisations: string[] | undefined; isStaff: boolean | undefined; sku: string | undefined; copilotTrackingId: string | undefined; }): Promise; private updateContext; private updateContextSync; suspend(): void; resume(): void; } export {};