chatEntitlementService.ts ×8

Frontier kind: Code frontier

unlabeled · c_da90480f29fe

14 tests · 25059 LOC · 136 files · introduces 0 tests · 52 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
8 ranges52 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2865 ranges25059 lines · 136 files · Browse complete extent
All tests (intent)
14 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 52 introduced LOC across 8 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/chat/common/chatEntitlementService.ts 52 introduced LOC · 8 ranges

Open complete file

847
848 export function parseQuotas(entitlementsData: IEntitlementsData): IQuotas {
849 > const quotas: Mutable<IQuotas> = { chatEntitlementService.ts
850 > resetDate: entitlementsData.quota_reset_date_utc ?? entitlementsData.quota_reset_date ?? entitlementsData.limited_user_reset_date,
851 > resetDateHasTime: typeof entitlementsData.quota_reset_date_utc === 'string',
852 > usageBasedBilling: entitlementsData.token_based_billing,
853 > canUpgradePlan: entitlementsData.can_upgrade_plan,
854 > };
855 >
856 > // Legacy Free SKU Quota
857 > if (entitlementsData.monthly_quotas?.chat && typeof entitlementsData.limited_user_quotas?.chat === 'number') {
858 quotas.chat = {
859 percentRemaining: Math.min(100, Math.max(0, (entitlementsData.limited_user_quotas.chat / entitlementsData.monthly_quotas.chat) * 100)),
861 };
862 }
864 > if (entitlementsData.monthly_quotas?.completions && typeof entitlementsData.limited_user_quotas?.completions === 'number') {
865 quotas.completions = {
866 percentRemaining: Math.min(100, Math.max(0, (entitlementsData.limited_user_quotas.completions / entitlementsData.monthly_quotas.completions) * 100)),
868 };
869 }
871 > // New Quota Snapshot
872 > if (entitlementsData.quota_snapshots) {
873 > for (const quotaType of ['chat', 'completions', 'premium_interactions'] as const) {
874 > const rawQuotaSnapshot = entitlementsData.quota_snapshots[quotaType];
875 > if (!rawQuotaSnapshot) {
876 continue;
877 }
878 > const parsedEntitlement = rawQuotaSnapshot.entitlement !== undefined ? Number(rawQuotaSnapshot.entitlement) : undefined; chatEntitlementService.ts
879 > const parsedCreditsUsed = rawQuotaSnapshot.credits_used !== undefined ? Number(rawQuotaSnapshot.credits_used) : undefined;
880 >
881 > // Skip snapshots where the user has no allocated entitlement for this
882 > // category (e.g. free tier premium_interactions with 0 credits). Under
883 > // TBB, has_quota is always false at the per-snapshot level so we cannot
884 > // rely on it; instead check the actual entitlement value.
885 > if (!rawQuotaSnapshot.unlimited && parsedEntitlement === 0) {
886 continue;
887 }
889 > const parsedQuotaRemaining = rawQuotaSnapshot.quota_remaining !== undefined ? Number(rawQuotaSnapshot.quota_remaining) : undefined;
890 > const quotaSnapshot: IQuotaSnapshot = {
891 > percentRemaining: Math.min(100, Math.max(0, rawQuotaSnapshot.percent_remaining)),
892 > unlimited: rawQuotaSnapshot.unlimited,
893 > hasQuota: rawQuotaSnapshot.has_quota,
894 > usageBasedBilling: entitlementsData.token_based_billing,
895 > resetAt: rawQuotaSnapshot.quota_reset_at || undefined,
896 > entitlement: parsedEntitlement !== undefined && Number.isFinite(parsedEntitlement) && parsedEntitlement >= 0 ? parsedEntitlement : undefined,
897 > quotaRemaining: parsedQuotaRemaining !== undefined && Number.isFinite(parsedQuotaRemaining) && parsedQuotaRemaining >= 0 ? parsedQuotaRemaining : undefined,
898 > creditsUsed: parsedCreditsUsed !== undefined && Number.isFinite(parsedCreditsUsed) && parsedCreditsUsed >= 0 ? parsedCreditsUsed : undefined,
899 > };
900 >
901 > switch (quotaType) {
902 > case 'chat':
903 quotas.chat = quotaSnapshot;
904 break;
905 > case 'completions': chatEntitlementService.ts
906 quotas.completions = quotaSnapshot;
907 break;
908 > case 'premium_interactions': chatEntitlementService.ts
909 quotas.premiumChat = quotaSnapshot;
910 break;
912 > }
913 >
914 > const overageSource = entitlementsData.quota_snapshots['premium_interactions'];
915 > quotas.additionalUsageEnabled = overageSource?.overage_permitted ?? false;
916 > quotas.additionalUsageCount = overageSource?.overage_count ?? 0;
917 > quotas.additionalUsageEntitlement = overageSource?.overage_entitlement ?? 0;
918 > }
919 > return quotas;
920 > }
921
922 export class ChatEntitlementRequests extends Disposable {