mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): Antigravity IDE & composer mount, modular preferences, session charts, and per-model context windows (v1.5.0)
This commit is contained in:
@@ -122,9 +122,21 @@ export async function callLsRpc(method, body = {}, timeoutMs = 5000) {
|
||||
* 向 LS 传递 `{ forceRefresh: true }`,绕过 `language_server.exe` 自身的 3 分钟缓存。
|
||||
*
|
||||
* @param {boolean} [forceRefresh=false] 是否强制穿透本地缓存与失败冷却
|
||||
* @param {string} [accountName=''] 发起查询时宿主报告的账号,用于隔离配额缓存
|
||||
* @returns {Promise<{data: object|null, fetchedAtMs: number, isStale: boolean, refreshFailed: boolean, error: string|null, fromCache: boolean}>}
|
||||
*/
|
||||
export async function getOfficialQuotaSummary(forceRefresh = false) {
|
||||
export async function getOfficialQuotaSummary(forceRefresh = false, accountName = '') {
|
||||
if (quotaSummaryCache.accountName !== accountName) {
|
||||
Object.assign(quotaSummaryCache, {
|
||||
accountName,
|
||||
accountGeneration: quotaSummaryCache.accountGeneration + 1,
|
||||
ts: 0,
|
||||
lastAttemptTs: 0,
|
||||
data: null,
|
||||
error: null,
|
||||
});
|
||||
}
|
||||
const generation = quotaSummaryCache.accountGeneration;
|
||||
const now = Date.now();
|
||||
if (!forceRefresh && quotaSummaryCache.data && now - quotaSummaryCache.ts < QUOTA_CACHE_TTL_MS) {
|
||||
return {
|
||||
@@ -155,6 +167,9 @@ export async function getOfficialQuotaSummary(forceRefresh = false) {
|
||||
quotaSummaryCache.lastAttemptTs = now;
|
||||
try {
|
||||
const res = await callLsRpc('RetrieveUserQuotaSummary', { forceRefresh: true }, 6000);
|
||||
const { userStatus } = await callLsRpc('GetUserStatus', {}, 2000);
|
||||
if ((userStatus?.email || userStatus?.name || '') !== accountName) return {};
|
||||
if (generation !== quotaSummaryCache.accountGeneration) return {};
|
||||
const payload = res?.response !== undefined ? res.response : res;
|
||||
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
||||
const normalized =
|
||||
@@ -175,6 +190,7 @@ export async function getOfficialQuotaSummary(forceRefresh = false) {
|
||||
}
|
||||
quotaSummaryCache.error = 'Quota summary empty';
|
||||
} catch (err) {
|
||||
if (generation !== quotaSummaryCache.accountGeneration) return {};
|
||||
console.error(`RetrieveUserQuotaSummary failed: ${err.message}`);
|
||||
quotaSummaryCache.error = err.message;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user