Fix duplicate session billing and align pricing with DeepSeek ×3.

Serialize billSessionUsage with row locks, expose rates on recharge, add compensation script and admin usage views.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
John
2026-06-16 03:10:05 -07:00
parent befeedfd37
commit 03690ee354
14 changed files with 472 additions and 52 deletions
+22 -4
View File
@@ -41,6 +41,7 @@ import type {
SessionEvent,
SessionListResponse,
UsageRecord,
UsageSummary,
BalanceUpdate,
} from '../types';
@@ -299,8 +300,14 @@ export async function getMe(): Promise<{
return portalFetch('/auth/me');
}
export async function getMyUsage(): Promise<UsageRecord[]> {
const result = await portalFetch<{ records: UsageRecord[] }>('/auth/usage');
export async function getMyUsageSummary(): Promise<UsageSummary> {
const result = await portalFetch<{ summary: UsageSummary }>('/auth/usage/summary');
return result.summary;
}
export async function getMyUsage(limit = 20): Promise<UsageRecord[]> {
const query = limit ? `?limit=${encodeURIComponent(String(limit))}` : '';
const result = await portalFetch<{ records: UsageRecord[] }>(`/auth/usage${query}`);
return result.records ?? [];
}
@@ -1010,8 +1017,19 @@ export async function getAdminDashboardSummary(): Promise<AdminDashboardSummary>
return result.summary;
}
export async function listAdminUsage(userId?: string): Promise<UsageRecord[]> {
const query = userId ? `?userId=${encodeURIComponent(userId)}` : '';
export async function getAdminUsageSummary(userId?: string): Promise<UsageSummary> {
const params = new URLSearchParams();
if (userId) params.set('userId', userId);
const query = params.toString() ? `?${params.toString()}` : '';
const result = await portalFetch<{ summary: UsageSummary }>(`/admin-api/usage/summary${query}`);
return result.summary;
}
export async function listAdminUsage(userId?: string, limit = 20): Promise<UsageRecord[]> {
const params = new URLSearchParams();
if (userId) params.set('userId', userId);
if (limit) params.set('limit', String(limit));
const query = params.toString() ? `?${params.toString()}` : '';
const result = await portalFetch<{ records: UsageRecord[] }>(`/admin-api/usage${query}`);
return result.records ?? [];
}