@cortexkit/opencode-antigravity-auth 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +308 -81
- package/dist/cli.js.map +4 -4
- package/dist/index.js +16634 -15416
- package/dist/index.js.map +4 -4
- package/dist/src/plugin/account-command-oauth.d.ts +34 -0
- package/dist/src/plugin/account-command-oauth.d.ts.map +1 -0
- package/dist/src/plugin/account-command-oauth.js +156 -0
- package/dist/src/plugin/account-command-oauth.js.map +1 -0
- package/dist/src/plugin/auth-loader.d.ts +16 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +113 -32
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/background-quota-refresh.d.ts +146 -0
- package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -0
- package/dist/src/plugin/background-quota-refresh.js +347 -0
- package/dist/src/plugin/background-quota-refresh.js.map +1 -0
- package/dist/src/plugin/command-data.d.ts +61 -8
- package/dist/src/plugin/command-data.d.ts.map +1 -1
- package/dist/src/plugin/command-data.js +231 -39
- package/dist/src/plugin/command-data.js.map +1 -1
- package/dist/src/plugin/commands.d.ts +12 -9
- package/dist/src/plugin/commands.d.ts.map +1 -1
- package/dist/src/plugin/commands.js +140 -33
- package/dist/src/plugin/commands.js.map +1 -1
- package/dist/src/plugin/config/schema.d.ts +2 -0
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +24 -0
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin/debug.d.ts +7 -0
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +25 -0
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +13 -1
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/index.d.ts +7 -0
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +127 -24
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/src/plugin/killswitch.js +12 -9
- package/dist/src/plugin/killswitch.js.map +1 -1
- package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/src/plugin/oauth-methods.js +2 -10
- package/dist/src/plugin/oauth-methods.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +42 -1
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +185 -41
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.js +2 -4
- package/dist/src/plugin/ui/auth-menu.js.map +1 -1
- package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
- package/dist/src/plugin/ui/quota-status.js +3 -5
- package/dist/src/plugin/ui/quota-status.js.map +1 -1
- package/dist/src/sidebar-state.d.ts +126 -9
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +185 -25
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui/command-dialogs.js +101 -3
- package/dist/src/tui/command-dialogs.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +55 -20
- package/dist/src/tui.js.map +1 -1
- package/package.json +6 -6
- package/src/plugin/command-data.ts +331 -51
- package/src/sidebar-state.ts +306 -32
- package/src/tui/command-dialogs.tsx +136 -3
- package/src/tui-compiled/plugin/command-data.ts +331 -51
- package/src/tui-compiled/sidebar-state.ts +306 -32
- package/src/tui-compiled/tui/command-dialogs.tsx +189 -69
- package/src/tui-compiled/tui.tsx +73 -30
- package/src/tui.tsx +82 -28
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background quota poller.
|
|
3
|
+
*
|
|
4
|
+
* Runs a jittered, `unref()`'d timer that periodically refreshes quota for
|
|
5
|
+
* all accounts and pushes ONE sidebar snapshot per tick. Three-layer
|
|
6
|
+
* cross-process dedup:
|
|
7
|
+
*
|
|
8
|
+
* 1. Freshness gate — the only hard correctness bound for quota snapshots.
|
|
9
|
+
* Reads `checkedAt` from the on-disk sidebar state; skips quota work when
|
|
10
|
+
* it is fresher than
|
|
11
|
+
* `max(intervalMs − 60_000, floor(intervalMs / 2))`. The /2 floor
|
|
12
|
+
* ensures the gate still fires at the 1-minute minimum interval.
|
|
13
|
+
*
|
|
14
|
+
* 2. Advisory fenced lock — an optimization that lets a single process do
|
|
15
|
+
* the network work when several wake up simultaneously. Held → skip.
|
|
16
|
+
*
|
|
17
|
+
* 3. Lock throws → FAIL CLOSED (skip this tick, add jitter to next). A
|
|
18
|
+
* fallback mutex is NOT used here. The correct reasoning is: the
|
|
19
|
+
* freshness gate (layer 1) already bounds how many refreshes can land;
|
|
20
|
+
* a secondary "claim marker" file is just a worse re-implementation of
|
|
21
|
+
* the fenced lock we just failed to acquire — it replicates the same
|
|
22
|
+
* ownership problem without the protocol guarantees, and any transient
|
|
23
|
+
* I/O error that made the lock throw will likely affect a claim file
|
|
24
|
+
* too. The previous poller attempt fell into this trap across three
|
|
25
|
+
* review rounds; this comment exists so a future reviewer stops
|
|
26
|
+
* re-litigating it.
|
|
27
|
+
*/
|
|
28
|
+
import { createHash } from 'node:crypto';
|
|
29
|
+
import { acquireFencedFileLock, } from '@cortexkit/antigravity-auth-core/file-lock';
|
|
30
|
+
import { readSidebarState, toCapturedTier } from '../sidebar-state';
|
|
31
|
+
import { pushSidebarQuotaSnapshot } from './quota';
|
|
32
|
+
/**
|
|
33
|
+
* Opaque identity derived from a refresh token. Three callers keep
|
|
34
|
+
* independent copies: this module, `command-data.ts` (ships into the TUI
|
|
35
|
+
* compiled tree and cannot reach the core barrel), and `index.ts`. All
|
|
36
|
+
* three must produce the same 16-char hex prefix.
|
|
37
|
+
*/
|
|
38
|
+
function quotaAccountIdentity(refreshToken) {
|
|
39
|
+
return createHash('sha256').update(refreshToken).digest('hex').slice(0, 16);
|
|
40
|
+
}
|
|
41
|
+
/** Minimum poll interval (1 minute, matching the config schema min). */
|
|
42
|
+
const MIN_INTERVAL_MS = 60_000;
|
|
43
|
+
/** Spread startup jitter so N processes don't all fire at once on launch. */
|
|
44
|
+
const STARTUP_JITTER_MS = 30_000;
|
|
45
|
+
/** Additional jitter added to the next tick when the lock mechanism throws. */
|
|
46
|
+
const ERROR_JITTER_MS = 15_000;
|
|
47
|
+
/** TTL for the renewable advisory poll lock. */
|
|
48
|
+
const POLL_LOCK_TTL_MS = 60_000;
|
|
49
|
+
/** Maximum age of a captured tier before the poller refreshes it. 24 h. */
|
|
50
|
+
const TIER_STALENESS_TTL_MS = 24 * 60 * 60 * 1_000;
|
|
51
|
+
/** A capture at this version distinguishes an absent paid tier from old data. */
|
|
52
|
+
const CAPTURED_TIER_SCHEMA_VERSION = 1;
|
|
53
|
+
/**
|
|
54
|
+
* Per-loader-instance background quota poller.
|
|
55
|
+
*
|
|
56
|
+
* Must be created after the plugin has initialised (so `getAccountManager()`
|
|
57
|
+
* is populated) and disposed via the producer lifecycle phase.
|
|
58
|
+
*/
|
|
59
|
+
export class BackgroundQuotaRefresh {
|
|
60
|
+
intervalMs;
|
|
61
|
+
sidebarStateFile;
|
|
62
|
+
getAccountManager;
|
|
63
|
+
quotaManager;
|
|
64
|
+
loadAccountTier;
|
|
65
|
+
now;
|
|
66
|
+
random;
|
|
67
|
+
acquireLock;
|
|
68
|
+
timer = null;
|
|
69
|
+
/** Resolves when the currently-running tick completes (or immediately if none). */
|
|
70
|
+
inFlight = null;
|
|
71
|
+
disposed = false;
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.intervalMs = options.intervalMs;
|
|
74
|
+
this.sidebarStateFile = options.sidebarStateFile;
|
|
75
|
+
this.getAccountManager = options.getAccountManager;
|
|
76
|
+
this.quotaManager = options.quotaManager;
|
|
77
|
+
this.loadAccountTier = options.loadAccountTier;
|
|
78
|
+
this.now = options.now ?? (() => Date.now());
|
|
79
|
+
this.random = options.random ?? Math.random;
|
|
80
|
+
this.acquireLock = options.acquireLock ?? acquireFencedFileLock;
|
|
81
|
+
}
|
|
82
|
+
/** Start the background timer. Idempotent: a second call is a no-op. */
|
|
83
|
+
start() {
|
|
84
|
+
if (this.disposed || this.timer !== null)
|
|
85
|
+
return;
|
|
86
|
+
this.scheduleNext(this.jitteredStartDelay());
|
|
87
|
+
}
|
|
88
|
+
/** Stop the timer and await any in-flight tick. */
|
|
89
|
+
async dispose() {
|
|
90
|
+
if (this.disposed)
|
|
91
|
+
return;
|
|
92
|
+
this.disposed = true;
|
|
93
|
+
if (this.timer !== null) {
|
|
94
|
+
clearTimeout(this.timer);
|
|
95
|
+
this.timer = null;
|
|
96
|
+
}
|
|
97
|
+
await this.inFlight;
|
|
98
|
+
}
|
|
99
|
+
// ── internals ─────────────────────────────────────────────────────────────
|
|
100
|
+
jitteredStartDelay() {
|
|
101
|
+
return Math.floor(this.random() * STARTUP_JITTER_MS);
|
|
102
|
+
}
|
|
103
|
+
jitteredInterval(extraJitterMs = 0) {
|
|
104
|
+
// ±10% on top of the base interval prevents phase-locking across restarts.
|
|
105
|
+
const jitter = Math.floor(this.random() * this.intervalMs * 0.1);
|
|
106
|
+
return this.intervalMs + jitter + extraJitterMs;
|
|
107
|
+
}
|
|
108
|
+
scheduleNext(delayMs) {
|
|
109
|
+
if (this.disposed)
|
|
110
|
+
return;
|
|
111
|
+
this.timer = setTimeout(() => {
|
|
112
|
+
this.timer = null;
|
|
113
|
+
// Re-entry guard: if the previous tick is still in flight (refresh
|
|
114
|
+
// duration > interval), skip this timer callback. The in-flight tick
|
|
115
|
+
// calls scheduleNext itself when it completes, so the poller continues.
|
|
116
|
+
// Without this guard, assigning this.inFlight here would overwrite the
|
|
117
|
+
// first tick's promise and dispose() would await the wrong one.
|
|
118
|
+
if (this.inFlight !== null)
|
|
119
|
+
return;
|
|
120
|
+
this.inFlight = this.runTick()
|
|
121
|
+
.catch(() => {
|
|
122
|
+
// Errors inside runTick are already caught per-phase. An unexpected
|
|
123
|
+
// throw here (before any internal reschedule) means no next tick
|
|
124
|
+
// was queued — reschedule with error jitter so the poller degrades
|
|
125
|
+
// to a delayed tick rather than dying permanently.
|
|
126
|
+
this.scheduleNext(this.jitteredInterval(ERROR_JITTER_MS));
|
|
127
|
+
})
|
|
128
|
+
.finally(() => {
|
|
129
|
+
this.inFlight = null;
|
|
130
|
+
});
|
|
131
|
+
}, delayMs);
|
|
132
|
+
// Unreffing lets the process exit while the timer is pending — the poller
|
|
133
|
+
// must never be the reason an idle session stays alive.
|
|
134
|
+
if (this.timer.unref)
|
|
135
|
+
this.timer.unref();
|
|
136
|
+
}
|
|
137
|
+
async runTick() {
|
|
138
|
+
// ── 1. Quota freshness gate ──────────────────────────────────────────
|
|
139
|
+
//
|
|
140
|
+
// Bound: `max(intervalMs − 60_000, floor(intervalMs / 2))`.
|
|
141
|
+
//
|
|
142
|
+
// - intervalMs − 60_000: at 5-minute intervals this is 240 s — tight
|
|
143
|
+
// enough to prevent double refreshes while allowing drift.
|
|
144
|
+
// - floor(intervalMs / 2): the fallback that keeps the gate non-trivial
|
|
145
|
+
// at the 1-minute minimum (floor(60000/2) = 30 000 ms, i.e. 30 s).
|
|
146
|
+
const freshnessThresholdMs = Math.max(this.intervalMs - MIN_INTERVAL_MS, Math.floor(this.intervalMs / 2));
|
|
147
|
+
const state = readSidebarState(this.sidebarStateFile);
|
|
148
|
+
const ageMs = this.now() - state.checkedAt;
|
|
149
|
+
// ── 2. Advisory fenced lock ──────────────────────────────────────────
|
|
150
|
+
let lock = null;
|
|
151
|
+
try {
|
|
152
|
+
lock = await this.acquireLock({
|
|
153
|
+
path: this.sidebarStateFile,
|
|
154
|
+
name: 'bg-quota-poll',
|
|
155
|
+
ttlMs: POLL_LOCK_TTL_MS,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Lock mechanism threw (I/O error, filesystem issue). FAIL CLOSED:
|
|
160
|
+
// skip this tick. See module-level invariant comment for why we do not
|
|
161
|
+
// invent a fallback mutex here.
|
|
162
|
+
this.scheduleNext(this.jitteredInterval(ERROR_JITTER_MS));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (lock === null) {
|
|
166
|
+
// Another process holds the lock — its tier phase owns this tick's
|
|
167
|
+
// metadata work as well as any quota snapshot write.
|
|
168
|
+
this.scheduleNext(this.jitteredInterval());
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
if (ageMs >= freshnessThresholdMs)
|
|
173
|
+
await this.refresh();
|
|
174
|
+
else
|
|
175
|
+
await this.refreshTierSlot();
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
await lock.release().catch(() => {
|
|
179
|
+
// Release is best-effort; the TTL expires it if we can't reach it.
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (!this.disposed) {
|
|
183
|
+
this.scheduleNext(this.jitteredInterval());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async refresh() {
|
|
187
|
+
const refreshedQuota = await this.refreshQuota();
|
|
188
|
+
await this.refreshTierSlot();
|
|
189
|
+
if (refreshedQuota)
|
|
190
|
+
await this.pushSnapshot();
|
|
191
|
+
}
|
|
192
|
+
async refreshQuota() {
|
|
193
|
+
if (this.disposed)
|
|
194
|
+
return false;
|
|
195
|
+
const manager = this.getAccountManager();
|
|
196
|
+
if (!manager)
|
|
197
|
+
return false;
|
|
198
|
+
const accounts = manager.getAccountsForQuotaCheck();
|
|
199
|
+
if (accounts.length === 0)
|
|
200
|
+
return false;
|
|
201
|
+
// Refresh all accounts, then stamp the live manager once per result.
|
|
202
|
+
// Using the shared quotaManager deduplicates in-flight refreshes with
|
|
203
|
+
// any concurrent modal or fetch-interceptor refresh.
|
|
204
|
+
let results;
|
|
205
|
+
try {
|
|
206
|
+
results = await this.quotaManager.refreshAccounts(accounts, {
|
|
207
|
+
indexFor: (account) => accounts.indexOf(account),
|
|
208
|
+
// Do not force: the quota manager's per-account dedup and backoff
|
|
209
|
+
// apply — an account that already refreshed recently is skipped.
|
|
210
|
+
force: false,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
if (this.disposed)
|
|
217
|
+
return false;
|
|
218
|
+
// Re-resolve live indices after the await: a concurrent add/remove may
|
|
219
|
+
// have shifted positions.
|
|
220
|
+
const liveAccounts = manager.getAccounts();
|
|
221
|
+
const liveIndexByToken = new Map();
|
|
222
|
+
for (const entry of liveAccounts) {
|
|
223
|
+
liveIndexByToken.set(entry.parts.refreshToken, entry.index);
|
|
224
|
+
}
|
|
225
|
+
let anyUpdated = false;
|
|
226
|
+
for (let i = 0; i < results.length; i++) {
|
|
227
|
+
const result = results[i];
|
|
228
|
+
if (result?.status !== 'ok' || !result.quota?.groups)
|
|
229
|
+
continue;
|
|
230
|
+
const candidateTokens = [
|
|
231
|
+
result.updatedAccount?.refreshToken,
|
|
232
|
+
accounts[i]?.refreshToken,
|
|
233
|
+
].filter((token) => Boolean(token));
|
|
234
|
+
const liveIndex = candidateTokens
|
|
235
|
+
.map((token) => liveIndexByToken.get(token))
|
|
236
|
+
.find((index) => index !== undefined);
|
|
237
|
+
if (liveIndex === undefined)
|
|
238
|
+
continue;
|
|
239
|
+
const liveToken = liveAccounts[liveIndex]?.parts.refreshToken;
|
|
240
|
+
if (!liveToken)
|
|
241
|
+
continue;
|
|
242
|
+
manager.updateQuotaCache(liveIndex, result.quota.groups, liveToken);
|
|
243
|
+
// Persist tier captured during ensureProjectContext (same tick, no extra
|
|
244
|
+
// network call) so the sidebar snapshot carries it after every poll.
|
|
245
|
+
const uaTier = toCapturedTier(result.updatedAccount ?? {});
|
|
246
|
+
if (uaTier !== undefined) {
|
|
247
|
+
manager.applyUpdatedAccount(liveIndex, {
|
|
248
|
+
capturedTierId: uaTier.id,
|
|
249
|
+
...(uaTier.paidId !== undefined
|
|
250
|
+
? { capturedPaidTierId: uaTier.paidId }
|
|
251
|
+
: {}),
|
|
252
|
+
capturedTierAt: uaTier.capturedAt,
|
|
253
|
+
capturedTierSchemaVersion: CAPTURED_TIER_SCHEMA_VERSION,
|
|
254
|
+
}, liveToken);
|
|
255
|
+
}
|
|
256
|
+
anyUpdated = true;
|
|
257
|
+
}
|
|
258
|
+
if (anyUpdated)
|
|
259
|
+
manager.requestSaveToDisk();
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
async refreshTierSlot() {
|
|
263
|
+
if (this.disposed || !this.loadAccountTier)
|
|
264
|
+
return;
|
|
265
|
+
const manager = this.getAccountManager();
|
|
266
|
+
if (!manager)
|
|
267
|
+
return;
|
|
268
|
+
const liveAccounts = manager.getAccounts();
|
|
269
|
+
const accounts = manager.getAccountsForQuotaCheck();
|
|
270
|
+
const accountByToken = new Map(accounts.map((account) => [account.refreshToken, account]));
|
|
271
|
+
const now = this.now();
|
|
272
|
+
let stalestEntry;
|
|
273
|
+
for (const entry of liveAccounts) {
|
|
274
|
+
const needsPaidTierBackfill = entry.capturedPaidTierId === undefined &&
|
|
275
|
+
entry.capturedTierSchemaVersion !== CAPTURED_TIER_SCHEMA_VERSION;
|
|
276
|
+
const isTierStale = entry.capturedTierAt === undefined ||
|
|
277
|
+
now - entry.capturedTierAt >= TIER_STALENESS_TTL_MS ||
|
|
278
|
+
needsPaidTierBackfill;
|
|
279
|
+
if (isTierStale &&
|
|
280
|
+
(stalestEntry === undefined ||
|
|
281
|
+
(entry.capturedTierAt ?? 0) < (stalestEntry.capturedTierAt ?? 0))) {
|
|
282
|
+
stalestEntry = entry;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (stalestEntry === undefined)
|
|
286
|
+
return;
|
|
287
|
+
const refreshToken = stalestEntry.parts.refreshToken;
|
|
288
|
+
const accountForTier = accountByToken.get(refreshToken);
|
|
289
|
+
if (!accountForTier)
|
|
290
|
+
return;
|
|
291
|
+
try {
|
|
292
|
+
const tier = await this.loadAccountTier(accountForTier);
|
|
293
|
+
if (tier === null || this.disposed)
|
|
294
|
+
return;
|
|
295
|
+
const liveEntry = manager
|
|
296
|
+
.getAccounts()
|
|
297
|
+
.find((entry) => entry.parts.refreshToken === refreshToken);
|
|
298
|
+
if (!liveEntry)
|
|
299
|
+
return;
|
|
300
|
+
manager.applyUpdatedAccount(liveEntry.index, {
|
|
301
|
+
capturedTierId: tier.id,
|
|
302
|
+
...(tier.paidId !== undefined
|
|
303
|
+
? { capturedPaidTierId: tier.paidId }
|
|
304
|
+
: {}),
|
|
305
|
+
capturedTierAt: tier.capturedAt,
|
|
306
|
+
capturedTierSchemaVersion: CAPTURED_TIER_SCHEMA_VERSION,
|
|
307
|
+
}, refreshToken);
|
|
308
|
+
manager.requestSaveToDisk();
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
// Tier is best-effort; a failure must never break the tick.
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async pushSnapshot() {
|
|
315
|
+
// ONE sidebar write per poll. `pushSidebarQuotaSnapshot` reads the live
|
|
316
|
+
// account view (with the just-updated cached values) and writes atomically.
|
|
317
|
+
const getAccounts = () => {
|
|
318
|
+
const m = this.getAccountManager();
|
|
319
|
+
return m ? m.getAccounts() : null;
|
|
320
|
+
};
|
|
321
|
+
await pushSidebarQuotaSnapshot(() => {
|
|
322
|
+
const accts = getAccounts();
|
|
323
|
+
if (!accts)
|
|
324
|
+
return null;
|
|
325
|
+
return accts.map((entry) => ({
|
|
326
|
+
index: entry.index,
|
|
327
|
+
label: entry.label,
|
|
328
|
+
enabled: entry.enabled,
|
|
329
|
+
coolingDownUntil: entry.coolingDownUntil,
|
|
330
|
+
cachedQuota: entry.cachedQuota,
|
|
331
|
+
cachedQuotaAccountId: entry.cachedQuotaAccountId,
|
|
332
|
+
// Derive current identity from the LIVE refresh token, independent
|
|
333
|
+
// of whatever stamp the cached snapshot carries. Mirrors index.ts's
|
|
334
|
+
// two correct call sites so the sidebar can detect a stale snapshot
|
|
335
|
+
// after an account reorder.
|
|
336
|
+
currentQuotaAccountId: quotaAccountIdentity(entry.parts.refreshToken),
|
|
337
|
+
tier: toCapturedTier(entry),
|
|
338
|
+
}));
|
|
339
|
+
}, 0, () => {
|
|
340
|
+
const m = this.getAccountManager();
|
|
341
|
+
return m ? m.getActiveIndexByFamily() : null;
|
|
342
|
+
}).catch(() => {
|
|
343
|
+
// Sidebar write failure is not fatal; the next tick will retry.
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=background-quota-refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-quota-refresh.js","sourceRoot":"","sources":["../../../src/plugin/background-quota-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAMxC,OAAO,EACL,qBAAqB,GAEtB,MAAM,4CAA4C,CAAA;AAEnD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAuDlD;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,YAAoB;IAChD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAC7E,CAAC;AAED,wEAAwE;AACxE,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,MAAM,CAAA;AAEhC,+EAA+E;AAC/E,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B,gDAAgD;AAChD,MAAM,gBAAgB,GAAG,MAAM,C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rE,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC;aAC5B,CAAC,CAAC,CAAA;QACL,CAAC,EACD,CAAC,EACD,GAAG,EAAE;YACH,MAAM,CAAC,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;YAClC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QAC9C,CAAC,CACF,CAAC,KAAK,CAAC,GAAG,EAAE;YACX,gEAAgE;QAClE,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -61,13 +61,19 @@ type CommandDataAccountMetadata = {
|
|
|
61
61
|
label?: string;
|
|
62
62
|
cachedQuota?: Partial<Record<CommandDataQuotaGroup, CommandDataQuotaGroupSummary>>;
|
|
63
63
|
cachedQuotaUpdatedAt?: number;
|
|
64
|
+
cachedQuotaAccountId?: string;
|
|
64
65
|
accountIneligible?: boolean;
|
|
65
66
|
};
|
|
66
|
-
type CommandDataQuotaGroup = '
|
|
67
|
+
type CommandDataQuotaGroup = 'gemini' | 'non-gemini';
|
|
67
68
|
type CommandDataQuotaGroupSummary = {
|
|
68
69
|
remainingFraction?: number;
|
|
69
70
|
resetTime?: string;
|
|
70
71
|
modelCount: number;
|
|
72
|
+
windows?: Array<{
|
|
73
|
+
window: 'weekly' | '5h';
|
|
74
|
+
remainingFraction: number;
|
|
75
|
+
resetTime: string;
|
|
76
|
+
}>;
|
|
71
77
|
};
|
|
72
78
|
type CommandDataAccountQuotaResult = {
|
|
73
79
|
index: number;
|
|
@@ -88,7 +94,7 @@ type CommandDataAccountQuotaResult = {
|
|
|
88
94
|
};
|
|
89
95
|
updatedAccount?: CommandDataAccountMetadata;
|
|
90
96
|
};
|
|
91
|
-
|
|
97
|
+
export interface CommandDataAccountStorage {
|
|
92
98
|
version: 4;
|
|
93
99
|
activeIndex: number;
|
|
94
100
|
activeIndexByFamily?: {
|
|
@@ -96,7 +102,7 @@ type CommandDataAccountStorage = {
|
|
|
96
102
|
gemini?: number;
|
|
97
103
|
};
|
|
98
104
|
accounts: CommandDataAccountMetadata[];
|
|
99
|
-
}
|
|
105
|
+
}
|
|
100
106
|
/**
|
|
101
107
|
* Privacy-safe per-account row shown in `/antigravity-*` data-first
|
|
102
108
|
* dialogs. Carries the cached quota percentages and the labels the
|
|
@@ -118,12 +124,30 @@ export interface CommandAccountRow {
|
|
|
118
124
|
enabled: boolean;
|
|
119
125
|
/** `true` when this row matches the harness-active account. */
|
|
120
126
|
current: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Absolute timestamp (ms) until which this account is rate-limited.
|
|
129
|
+
* Carried on the row so the sidebar refresher can match cooldowns
|
|
130
|
+
* without relying on unstable numeric indices.
|
|
131
|
+
*/
|
|
132
|
+
coolingDownUntil?: number;
|
|
133
|
+
/** Health score in [0, 100], forwarded from the live tracker. */
|
|
134
|
+
healthScore?: number;
|
|
121
135
|
quota: Array<{
|
|
122
|
-
key: '
|
|
136
|
+
key: 'gemini' | 'non-gemini';
|
|
123
137
|
label: string;
|
|
124
138
|
remainingPercent: number | null;
|
|
125
139
|
resetAt?: number;
|
|
140
|
+
windows?: Array<{
|
|
141
|
+
window: 'weekly' | '5h';
|
|
142
|
+
remainingPercent: number;
|
|
143
|
+
resetAt?: number;
|
|
144
|
+
}>;
|
|
126
145
|
}>;
|
|
146
|
+
/** Captured plan tier. Absent when unknown; never defaulted. */
|
|
147
|
+
tier?: {
|
|
148
|
+
id: string;
|
|
149
|
+
capturedAt: number;
|
|
150
|
+
};
|
|
127
151
|
}
|
|
128
152
|
interface LiveAccountSnapshot {
|
|
129
153
|
index: number;
|
|
@@ -133,8 +157,18 @@ interface LiveAccountSnapshot {
|
|
|
133
157
|
active: boolean;
|
|
134
158
|
cachedQuota?: Partial<Record<CommandDataQuotaGroup, CommandDataQuotaGroupSummary>>;
|
|
135
159
|
cachedQuotaUpdatedAt?: number;
|
|
160
|
+
cachedQuotaAccountId?: string;
|
|
136
161
|
accountIneligible?: boolean;
|
|
162
|
+
coolingDownUntil?: number;
|
|
163
|
+
healthScore?: number;
|
|
164
|
+
/** Captured plan tier from the most recent loadCodeAssist response. */
|
|
165
|
+
capturedTierId?: string;
|
|
166
|
+
/** Captured paid-tier ID from the most recent loadCodeAssist response. */
|
|
167
|
+
capturedPaidTierId?: string;
|
|
168
|
+
/** Epoch ms when capturedTierId was last recorded. */
|
|
169
|
+
capturedTierAt?: number;
|
|
137
170
|
}
|
|
171
|
+
export declare function projectCommandAccountRows(storage: CommandDataAccountStorage | null | undefined): CommandAccountRow[];
|
|
138
172
|
/**
|
|
139
173
|
* Live AccountManager view the data service needs.
|
|
140
174
|
*
|
|
@@ -157,16 +191,23 @@ interface LiveAccountSnapshot {
|
|
|
157
191
|
* dialog-triggered mutation lands on disk before the dialog's response
|
|
158
192
|
* returns. Without it, the dialog could toast "Account removed" while
|
|
159
193
|
* the file still carries the old pool.
|
|
160
|
-
* - `activeIndex()` returns the position the harness considers active;
|
|
161
|
-
* the service uses it to mark the matching row as `current: true`.
|
|
162
194
|
*/
|
|
163
195
|
export interface CommandDataAccountManagerView {
|
|
164
196
|
getAccounts(): LiveAccountSnapshot[];
|
|
165
197
|
getAccountsForQuotaCheck(): CommandDataAccountMetadata[];
|
|
166
|
-
updateQuotaCache(index: number, groups: Partial<Record<CommandDataQuotaGroup, CommandDataQuotaGroupSummary
|
|
198
|
+
updateQuotaCache(index: number, groups: Partial<Record<CommandDataQuotaGroup, CommandDataQuotaGroupSummary>>, expectedRefreshToken?: string): void;
|
|
167
199
|
requestSaveToDisk(): void;
|
|
168
200
|
flushSaveToDisk(): Promise<void>;
|
|
169
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Per-family live cursor. Used by the remove path so the persisted
|
|
203
|
+
* `activeIndexByFamily` follows each model's currently-active account
|
|
204
|
+
* independently — collapsing both families to a single index would
|
|
205
|
+
* silently unelect one family on every restart.
|
|
206
|
+
*/
|
|
207
|
+
getActiveIndexByFamily(): {
|
|
208
|
+
claude: number;
|
|
209
|
+
gemini: number;
|
|
210
|
+
};
|
|
170
211
|
/** Enable/disable the account at `index`. Returns true when it changed. */
|
|
171
212
|
setAccountEnabled(index: number, enabled: boolean): boolean;
|
|
172
213
|
/** Pin `index` as the active account for every family the dialog cares about. */
|
|
@@ -233,8 +274,20 @@ export interface CommandDataService {
|
|
|
233
274
|
* refresh token, bump `cachedQuotaUpdatedAt`, and push a label-only
|
|
234
275
|
* sidebar snapshot. Returns the freshly persisted rows so the
|
|
235
276
|
* dialog can re-render in place.
|
|
277
|
+
*
|
|
278
|
+
* Bypass flag is intentional: explicit user-triggered refreshes
|
|
279
|
+
* ("Refresh" button, direct slash-command with `refresh` argument)
|
|
280
|
+
* must always fetch, even if the quota manager has backed off.
|
|
236
281
|
*/
|
|
237
282
|
refreshQuota(): Promise<CommandAccountRow[]>;
|
|
283
|
+
/**
|
|
284
|
+
* Non-forced quota check that RESPECTS the quota manager's per-account
|
|
285
|
+
* backoff. Used by the dialog OPEN path — which is a VIEW, not a user
|
|
286
|
+
* request to fetch. Accounts already fresh (or in backoff) are skipped;
|
|
287
|
+
* the result is discarded (the sidebar poller carries the freshness
|
|
288
|
+
* guarantee for idle accounts).
|
|
289
|
+
*/
|
|
290
|
+
refreshQuotaRespectingBackoff(): Promise<void>;
|
|
238
291
|
/**
|
|
239
292
|
* Pin `index` as the active account for every family the dialog
|
|
240
293
|
* tracks (claude + gemini). Mutates the live AccountManager AND the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-data.d.ts","sourceRoot":"","sources":["../../../src/plugin/command-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;
|
|
1
|
+
{"version":3,"file":"command-data.d.ts","sourceRoot":"","sources":["../../../src/plugin/command-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAYH;;;;;;;;;;GAUG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