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