Path: blob/main/extensions/copilot/src/platform/chat/common/chatQuotaService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { createServiceIdentifier } from '../../../util/common/services';6import { Event } from '../../../util/vs/base/common/event';7import { IHeaders } from '../../networking/common/fetcherService';89/**10* This is the quota info we get from the `copilot_internal/user` endpoint.11* It is accessed via the copilot token object12*/13export interface CopilotUserQuotaInfo {14quota_reset_date?: string;15quota_snapshots?: {16chat: {17quota_id: string;18entitlement: number;19remaining: number;20unlimited: boolean;21overage_count: number;22overage_permitted: boolean;23percent_remaining: number;24};25completions: {26quota_id: string;27entitlement: number;28remaining: number;29unlimited: boolean;30overage_count: number;31overage_permitted: boolean;32percent_remaining: number;33};34premium_interactions: {35quota_id: string;36entitlement: number;37remaining: number;38unlimited: boolean;39overage_count: number;40overage_permitted: boolean;41percent_remaining: number;42};43};44}4546export interface IChatQuota {47quota: number;48percentRemaining: number;49unlimited: boolean;50additionalUsageUsed: number;51additionalUsageEnabled: boolean;52resetDate: Date;53}5455export interface QuotaSnapshot {56/** String representation of the entitlement count, "-1" for unlimited. */57readonly entitlement: string;58/** Percentage of quota remaining (0–100), rounded up to 1 decimal. */59readonly percent_remaining: number;60/** Whether additional usage (usage beyond included credits) is permitted. */61readonly overage_permitted: boolean;62/** Number of additional usage units consumed, rounded up to 1 decimal. */63readonly overage_count: number;64/** ISO 8601 date when the quota resets, if applicable. */65readonly reset_date?: string;66}6768export type QuotaSnapshots = Record<string, QuotaSnapshot>;6970export interface IChatQuotaService {71readonly _serviceBrand: undefined;72readonly onDidChange: Event<void>;73readonly quotaInfo: IChatQuota | undefined;74readonly rateLimitInfo: { readonly session: IChatQuota | undefined; readonly weekly: IChatQuota | undefined };75quotaExhausted: boolean;76additionalUsageEnabled: boolean;77processQuotaHeaders(headers: IHeaders): void;78processQuotaSnapshots(snapshots: QuotaSnapshots): void;79clearQuota(): void;80}8182export const IChatQuotaService = createServiceIdentifier<IChatQuotaService>('IChatQuotaService');838485