when-does-my-quota-refresh 1.0.0

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.
@@ -0,0 +1,350 @@
1
+ /**
2
+ * Core types for when-does-my-quota-refresh SDK
3
+ */
4
+ interface QuotaSnapshot {
5
+ timestamp: string;
6
+ email?: string;
7
+ method: DataSource;
8
+ planType?: string;
9
+ groups: QuotaGroup[];
10
+ promptCredits?: PromptCreditsInfo;
11
+ }
12
+ interface QuotaGroup {
13
+ displayName: string;
14
+ buckets: QuotaBucket[];
15
+ }
16
+ interface QuotaBucket {
17
+ bucketId: string;
18
+ displayName: string;
19
+ description: string;
20
+ remainingFraction: number;
21
+ resetTime?: string;
22
+ timeUntilResetMs?: number;
23
+ }
24
+ interface PromptCreditsInfo {
25
+ available: number;
26
+ monthly: number;
27
+ usedPercentage: number;
28
+ remainingPercentage: number;
29
+ }
30
+ type DataSource = 'local' | 'cli' | 'cloud' | 'oauth';
31
+ interface ModelQuotaInfo {
32
+ label: string;
33
+ modelId: string;
34
+ remainingPercentage?: number;
35
+ isExhausted: boolean;
36
+ resetTime?: string;
37
+ timeUntilResetMs?: number;
38
+ isAutocompleteOnly?: boolean;
39
+ }
40
+ interface AccountInfo {
41
+ email: string;
42
+ displayName?: string;
43
+ isActive: boolean;
44
+ tokenExpiresAt?: number;
45
+ }
46
+ interface StoredTokens {
47
+ accessToken: string;
48
+ refreshToken: string;
49
+ expiresAt: number;
50
+ email?: string;
51
+ projectId?: string;
52
+ }
53
+ interface DataSourceAdapter {
54
+ readonly name: DataSource;
55
+ readonly priority: number;
56
+ isAvailable(): Promise<boolean>;
57
+ fetchQuota(): Promise<QuotaSnapshot>;
58
+ }
59
+ interface Plugin {
60
+ name: string;
61
+ version: string;
62
+ onQuotaUpdate?: (snapshot: QuotaSnapshot) => Promise<void>;
63
+ onQuotaLow?: (group: string, bucket: string, remaining: number) => Promise<void>;
64
+ onReset?: (group: string, nextReset: Date) => Promise<void>;
65
+ onInit?: () => Promise<void>;
66
+ onDestroy?: () => Promise<void>;
67
+ }
68
+ interface UsageRecord {
69
+ timestamp: string;
70
+ email: string;
71
+ geminiWeeklyRemaining: number | null;
72
+ geminiSessionRemaining: number | null;
73
+ claudeWeeklyRemaining: number | null;
74
+ claudeSessionRemaining: number | null;
75
+ }
76
+ interface AppConfig {
77
+ defaultMode: DataSource;
78
+ cacheTtlMs: number;
79
+ refreshIntervalMs: number;
80
+ wakeupModels: string[];
81
+ wakeupAccounts: string[];
82
+ notifications: boolean;
83
+ plugins: string[];
84
+ daemon: {
85
+ pollIntervalMs: number;
86
+ enabled: boolean;
87
+ };
88
+ }
89
+ interface ClientOptions {
90
+ mode?: DataSource;
91
+ cacheTtlMs?: number;
92
+ verbose?: boolean;
93
+ }
94
+
95
+ /**
96
+ * Source registry — manages data source adapters and implements the fallback chain
97
+ *
98
+ * Priority order:
99
+ * 1. Local (Antigravity app language server) — fastest, offline
100
+ * 2. CLI (agy CLI HTTPS server) — no app needed, requires signed-in agy
101
+ * 3. OAuth (Google Cloud Code API) — works anywhere, requires login
102
+ */
103
+
104
+ declare class SourceRegistry {
105
+ private sources;
106
+ private health;
107
+ constructor();
108
+ /**
109
+ * Register an additional data source (e.g., OAuth)
110
+ */
111
+ addSource(source: DataSourceAdapter): void;
112
+ /**
113
+ * Remove a source by name
114
+ */
115
+ removeSource(name: DataSource): void;
116
+ /**
117
+ * Fetch quota using the best available source
118
+ *
119
+ * @param preferredSource Force a specific source
120
+ */
121
+ fetchQuota(preferredSource?: DataSource): Promise<QuotaSnapshot>;
122
+ /**
123
+ * Get health status of all sources
124
+ */
125
+ getHealth(): Map<DataSource, {
126
+ available: boolean;
127
+ lastCheck: number;
128
+ }>;
129
+ /**
130
+ * Get registered source names
131
+ */
132
+ getSourceNames(): DataSource[];
133
+ }
134
+
135
+ /**
136
+ * SQLite storage for usage history and analytics
137
+ */
138
+
139
+ /**
140
+ * Store a quota snapshot for history tracking
141
+ */
142
+ declare function storeSnapshot(snapshot: QuotaSnapshot): void;
143
+ /**
144
+ * Retrieve usage history for an account
145
+ */
146
+ declare function getHistory(email: string, options?: {
147
+ days?: number;
148
+ limit?: number;
149
+ }): UsageRecord[];
150
+ /**
151
+ * Get the most recent snapshot for an account
152
+ */
153
+ declare function getLatestSnapshot(email: string): UsageRecord | null;
154
+ /**
155
+ * Get daily usage summary (average remaining per day)
156
+ */
157
+ declare function getDailySummary(email: string, days?: number): Array<{
158
+ date: string;
159
+ geminiWeeklyAvg: number | null;
160
+ geminiSessionAvg: number | null;
161
+ claudeWeeklyAvg: number | null;
162
+ claudeSessionAvg: number | null;
163
+ count: number;
164
+ }>;
165
+ /**
166
+ * Clean up old snapshots (older than N days)
167
+ */
168
+ declare function cleanupHistory(keepDays?: number): number;
169
+ /**
170
+ * Close the database connection
171
+ */
172
+ declare function closeStore(): void;
173
+
174
+ /**
175
+ * Quota fetching orchestration
176
+ *
177
+ * Coordinates between the source registry, cache, storage, and plugins
178
+ * to provide a unified quota fetching experience.
179
+ */
180
+
181
+ declare class QuotaClient {
182
+ private registry;
183
+ private cache;
184
+ private verbose;
185
+ constructor(options?: ClientOptions);
186
+ /**
187
+ * Fetch quota for the active account (or all accounts)
188
+ */
189
+ fetchQuota(options?: {
190
+ source?: DataSource;
191
+ refresh?: boolean;
192
+ allAccounts?: boolean;
193
+ }): Promise<QuotaSnapshot | QuotaSnapshot[]>;
194
+ /**
195
+ * Fetch quota for all stored accounts
196
+ */
197
+ private fetchAllAccounts;
198
+ /**
199
+ * Get the full dashboard data for all accounts
200
+ */
201
+ getFullDashboard(): Promise<{
202
+ snapshots: QuotaSnapshot[];
203
+ history: Record<string, UsageRecord[]>;
204
+ dailySummary: Record<string, ReturnType<typeof getDailySummary>>;
205
+ }>;
206
+ /**
207
+ * Get usage history for an account
208
+ */
209
+ getHistory(email: string, days?: number): UsageRecord[];
210
+ /**
211
+ * Get daily summary for an account
212
+ */
213
+ getDailySummary(email: string, days?: number): {
214
+ date: string;
215
+ geminiWeeklyAvg: number | null;
216
+ geminiSessionAvg: number | null;
217
+ claudeWeeklyAvg: number | null;
218
+ claudeSessionAvg: number | null;
219
+ count: number;
220
+ }[];
221
+ /**
222
+ * Register OAuth sources for all stored accounts
223
+ */
224
+ private registerOAuthSources;
225
+ /**
226
+ * Get the source registry (for doctor/status checks)
227
+ */
228
+ getRegistry(): SourceRegistry;
229
+ }
230
+
231
+ /**
232
+ * Smart caching layer for quota data
233
+ *
234
+ * Caches quota snapshots to avoid hitting API rate limits.
235
+ * Cache is keyed by email + source combination.
236
+ */
237
+
238
+ declare class QuotaCache {
239
+ private cache;
240
+ private ttlMs;
241
+ constructor(ttlMs?: number);
242
+ /**
243
+ * Get cached quota if available and not expired
244
+ */
245
+ get(email: string, source: string): QuotaSnapshot | null;
246
+ /**
247
+ * Store a quota snapshot in cache
248
+ */
249
+ set(email: string, source: string, snapshot: QuotaSnapshot): void;
250
+ /**
251
+ * Check if a cached entry is still fresh
252
+ */
253
+ isFresh(email: string, source: string): boolean;
254
+ /**
255
+ * Clear all cached entries
256
+ */
257
+ clear(): void;
258
+ /**
259
+ * Get cache age in seconds for a key
260
+ */
261
+ getAgeMs(email: string, source: string): number | null;
262
+ }
263
+
264
+ /**
265
+ * Token storage for account credentials
266
+ *
267
+ * Stores OAuth tokens locally in the config directory.
268
+ * Tokens are stored as plain JSON (local machine only).
269
+ */
270
+
271
+ /**
272
+ * Get tokens for a specific account
273
+ */
274
+ declare function getAccountTokens(email: string): StoredTokens | null;
275
+ /**
276
+ * Get the active account's tokens
277
+ */
278
+ declare function getActiveAccountTokens(): StoredTokens | null;
279
+ /**
280
+ * Set the active account
281
+ */
282
+ declare function setActiveAccount(email: string): boolean;
283
+ /**
284
+ * Remove an account
285
+ */
286
+ declare function removeAccount(email: string): boolean;
287
+ /**
288
+ * List all stored accounts
289
+ */
290
+ declare function listAccounts(): Array<{
291
+ email: string;
292
+ isActive: boolean;
293
+ addedAt: string;
294
+ }>;
295
+
296
+ /**
297
+ * OAuth authentication flow for Google accounts
298
+ */
299
+ /**
300
+ * Start an interactive OAuth login flow
301
+ *
302
+ * Opens the browser for Google login, then captures the redirect
303
+ * to exchange the authorization code for tokens.
304
+ */
305
+ declare function loginAccount(): Promise<string>;
306
+
307
+ /**
308
+ * Config file management — reads/writes app configuration
309
+ */
310
+
311
+ declare function loadConfig(): AppConfig;
312
+ declare function saveConfig(config: AppConfig): void;
313
+ declare function getConfigDirPath(): string;
314
+ declare function getDataDirPath(): string;
315
+
316
+ /**
317
+ * Custom error types for when-does-my-quota-refresh
318
+ */
319
+ declare class SourceUnavailableError extends Error {
320
+ constructor(source: string, reason?: string);
321
+ }
322
+ declare class AuthError extends Error {
323
+ constructor(message: string);
324
+ }
325
+ declare class QuotaFetchError extends Error {
326
+ constructor(source: string, reason?: string);
327
+ }
328
+
329
+ /**
330
+ * when-does-my-quota-refresh SDK
331
+ *
332
+ * Core library for fetching and managing Antigravity AI model quotas.
333
+ * Import this for programmatic use in your own tools and extensions.
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * import { createClient } from 'when-does-my-quota-refresh'
338
+ *
339
+ * const client = createClient()
340
+ * const snapshot = await client.fetchQuota()
341
+ * console.log(snapshot.groups)
342
+ * ```
343
+ */
344
+
345
+ /**
346
+ * Create a new when-does-my-quota-refresh client
347
+ */
348
+ declare function createClient(options?: ClientOptions): QuotaClient;
349
+
350
+ export { type AccountInfo, AuthError, type ClientOptions, type DataSource, type ModelQuotaInfo, type Plugin, type PromptCreditsInfo, type QuotaBucket, QuotaCache, QuotaClient, QuotaFetchError, type QuotaGroup, type QuotaSnapshot, SourceRegistry, SourceUnavailableError, type UsageRecord, cleanupHistory, closeStore, createClient, getAccountTokens, getActiveAccountTokens, getConfigDirPath, getDailySummary, getDataDirPath, getHistory, getLatestSnapshot, listAccounts, loadConfig, loginAccount, removeAccount, saveConfig, setActiveAccount, storeSnapshot };