antigravity-auth 1.6.0 → 1.7.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/README.md +79 -41
- package/dist/cli.js +17854 -0
- package/dist/handler.js +25147 -0
- package/dist/index.js +25138 -5
- package/package.json +66 -54
- package/dist/antigravity/oauth.d.ts +0 -30
- package/dist/antigravity/oauth.js +0 -170
- package/dist/claude/login.d.ts +0 -7
- package/dist/claude/login.js +0 -480
- package/dist/claude/menu-helpers.d.ts +0 -22
- package/dist/claude/menu-helpers.js +0 -281
- package/dist/claude/proxy-manager.d.ts +0 -11
- package/dist/claude/proxy-manager.js +0 -129
- package/dist/claude/proxy.d.ts +0 -1
- package/dist/claude/proxy.js +0 -733
- package/dist/constants.d.ts +0 -138
- package/dist/constants.js +0 -216
- package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/hooks/auto-update-checker/cache.js +0 -70
- package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/hooks/auto-update-checker/checker.js +0 -233
- package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/hooks/auto-update-checker/constants.js +0 -22
- package/dist/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/hooks/auto-update-checker/index.js +0 -121
- package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/hooks/auto-update-checker/logging.js +0 -8
- package/dist/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/hooks/auto-update-checker/types.js +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
- package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
- package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
- package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
- package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
- package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
- package/dist/opencode/plugin.d.ts +0 -29
- package/dist/opencode/plugin.js +0 -2954
- package/dist/plugin/accounts.d.ts +0 -173
- package/dist/plugin/accounts.js +0 -966
- package/dist/plugin/auth.d.ts +0 -20
- package/dist/plugin/auth.js +0 -44
- package/dist/plugin/cache/index.d.ts +0 -4
- package/dist/plugin/cache/index.js +0 -4
- package/dist/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/plugin/cache/signature-cache.js +0 -347
- package/dist/plugin/cache.d.ts +0 -43
- package/dist/plugin/cache.js +0 -180
- package/dist/plugin/cli.d.ts +0 -26
- package/dist/plugin/cli.js +0 -126
- package/dist/plugin/config/index.d.ts +0 -15
- package/dist/plugin/config/index.js +0 -15
- package/dist/plugin/config/loader.d.ts +0 -38
- package/dist/plugin/config/loader.js +0 -150
- package/dist/plugin/config/models.d.ts +0 -26
- package/dist/plugin/config/models.js +0 -95
- package/dist/plugin/config/schema.d.ts +0 -144
- package/dist/plugin/config/schema.js +0 -458
- package/dist/plugin/config/updater.d.ts +0 -76
- package/dist/plugin/config/updater.js +0 -205
- package/dist/plugin/core/streaming/index.d.ts +0 -2
- package/dist/plugin/core/streaming/index.js +0 -2
- package/dist/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/plugin/core/streaming/transformer.js +0 -301
- package/dist/plugin/core/streaming/types.d.ts +0 -28
- package/dist/plugin/core/streaming/types.js +0 -1
- package/dist/plugin/debug.d.ts +0 -93
- package/dist/plugin/debug.js +0 -375
- package/dist/plugin/errors.d.ts +0 -27
- package/dist/plugin/errors.js +0 -41
- package/dist/plugin/fingerprint.d.ts +0 -69
- package/dist/plugin/fingerprint.js +0 -137
- package/dist/plugin/image-saver.d.ts +0 -24
- package/dist/plugin/image-saver.js +0 -78
- package/dist/plugin/logger.d.ts +0 -35
- package/dist/plugin/logger.js +0 -67
- package/dist/plugin/logging-utils.d.ts +0 -22
- package/dist/plugin/logging-utils.js +0 -91
- package/dist/plugin/project.d.ts +0 -32
- package/dist/plugin/project.js +0 -229
- package/dist/plugin/quota.d.ts +0 -34
- package/dist/plugin/quota.js +0 -261
- package/dist/plugin/recovery/constants.d.ts +0 -21
- package/dist/plugin/recovery/constants.js +0 -42
- package/dist/plugin/recovery/index.d.ts +0 -11
- package/dist/plugin/recovery/index.js +0 -11
- package/dist/plugin/recovery/storage.d.ts +0 -23
- package/dist/plugin/recovery/storage.js +0 -340
- package/dist/plugin/recovery/types.d.ts +0 -115
- package/dist/plugin/recovery/types.js +0 -6
- package/dist/plugin/recovery.d.ts +0 -60
- package/dist/plugin/recovery.js +0 -360
- package/dist/plugin/refresh-queue.d.ts +0 -99
- package/dist/plugin/refresh-queue.js +0 -235
- package/dist/plugin/request-helpers.d.ts +0 -281
- package/dist/plugin/request-helpers.js +0 -2200
- package/dist/plugin/request.d.ts +0 -110
- package/dist/plugin/request.js +0 -1489
- package/dist/plugin/rotation.d.ts +0 -182
- package/dist/plugin/rotation.js +0 -364
- package/dist/plugin/search.d.ts +0 -31
- package/dist/plugin/search.js +0 -185
- package/dist/plugin/server.d.ts +0 -22
- package/dist/plugin/server.js +0 -306
- package/dist/plugin/storage.d.ts +0 -136
- package/dist/plugin/storage.js +0 -599
- package/dist/plugin/stores/signature-store.d.ts +0 -4
- package/dist/plugin/stores/signature-store.js +0 -24
- package/dist/plugin/thinking-recovery.d.ts +0 -89
- package/dist/plugin/thinking-recovery.js +0 -289
- package/dist/plugin/token.d.ts +0 -18
- package/dist/plugin/token.js +0 -127
- package/dist/plugin/transform/claude.d.ts +0 -79
- package/dist/plugin/transform/claude.js +0 -256
- package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/plugin/transform/gemini.d.ts +0 -132
- package/dist/plugin/transform/gemini.js +0 -659
- package/dist/plugin/transform/index.d.ts +0 -14
- package/dist/plugin/transform/index.js +0 -9
- package/dist/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/plugin/transform/model-resolver.js +0 -320
- package/dist/plugin/transform/types.d.ts +0 -110
- package/dist/plugin/transform/types.js +0 -1
- package/dist/plugin/types.d.ts +0 -95
- package/dist/plugin/types.js +0 -1
- package/dist/plugin/ui/ansi.d.ts +0 -31
- package/dist/plugin/ui/ansi.js +0 -45
- package/dist/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/plugin/ui/auth-menu.js +0 -199
- package/dist/plugin/ui/confirm.d.ts +0 -1
- package/dist/plugin/ui/confirm.js +0 -14
- package/dist/plugin/ui/select.d.ts +0 -22
- package/dist/plugin/ui/select.js +0 -243
- package/dist/plugin/version.d.ts +0 -18
- package/dist/plugin/version.js +0 -79
- package/dist/src/antigravity/oauth.d.ts +0 -30
- package/dist/src/antigravity/oauth.js +0 -170
- package/dist/src/constants.d.ts +0 -138
- package/dist/src/constants.js +0 -216
- package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/cache.js +0 -70
- package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/src/hooks/auto-update-checker/checker.js +0 -233
- package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/src/hooks/auto-update-checker/constants.js +0 -22
- package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/src/hooks/auto-update-checker/index.js +0 -121
- package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/logging.js +0 -8
- package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/src/hooks/auto-update-checker/types.js +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -5
- package/dist/src/plugin/accounts.d.ts +0 -173
- package/dist/src/plugin/accounts.js +0 -966
- package/dist/src/plugin/auth.d.ts +0 -20
- package/dist/src/plugin/auth.js +0 -44
- package/dist/src/plugin/cache/index.d.ts +0 -4
- package/dist/src/plugin/cache/index.js +0 -4
- package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/src/plugin/cache/signature-cache.js +0 -347
- package/dist/src/plugin/cache.d.ts +0 -43
- package/dist/src/plugin/cache.js +0 -180
- package/dist/src/plugin/cli.d.ts +0 -26
- package/dist/src/plugin/cli.js +0 -126
- package/dist/src/plugin/config/index.d.ts +0 -15
- package/dist/src/plugin/config/index.js +0 -15
- package/dist/src/plugin/config/loader.d.ts +0 -38
- package/dist/src/plugin/config/loader.js +0 -150
- package/dist/src/plugin/config/models.d.ts +0 -26
- package/dist/src/plugin/config/models.js +0 -95
- package/dist/src/plugin/config/schema.d.ts +0 -144
- package/dist/src/plugin/config/schema.js +0 -458
- package/dist/src/plugin/config/updater.d.ts +0 -76
- package/dist/src/plugin/config/updater.js +0 -205
- package/dist/src/plugin/core/streaming/index.d.ts +0 -2
- package/dist/src/plugin/core/streaming/index.js +0 -2
- package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/src/plugin/core/streaming/transformer.js +0 -301
- package/dist/src/plugin/core/streaming/types.d.ts +0 -28
- package/dist/src/plugin/core/streaming/types.js +0 -1
- package/dist/src/plugin/debug.d.ts +0 -93
- package/dist/src/plugin/debug.js +0 -375
- package/dist/src/plugin/errors.d.ts +0 -27
- package/dist/src/plugin/errors.js +0 -41
- package/dist/src/plugin/fingerprint.d.ts +0 -69
- package/dist/src/plugin/fingerprint.js +0 -137
- package/dist/src/plugin/image-saver.d.ts +0 -24
- package/dist/src/plugin/image-saver.js +0 -78
- package/dist/src/plugin/logger.d.ts +0 -35
- package/dist/src/plugin/logger.js +0 -67
- package/dist/src/plugin/logging-utils.d.ts +0 -22
- package/dist/src/plugin/logging-utils.js +0 -91
- package/dist/src/plugin/project.d.ts +0 -32
- package/dist/src/plugin/project.js +0 -229
- package/dist/src/plugin/quota.d.ts +0 -34
- package/dist/src/plugin/quota.js +0 -261
- package/dist/src/plugin/recovery/constants.d.ts +0 -21
- package/dist/src/plugin/recovery/constants.js +0 -42
- package/dist/src/plugin/recovery/index.d.ts +0 -11
- package/dist/src/plugin/recovery/index.js +0 -11
- package/dist/src/plugin/recovery/storage.d.ts +0 -23
- package/dist/src/plugin/recovery/storage.js +0 -340
- package/dist/src/plugin/recovery/types.d.ts +0 -115
- package/dist/src/plugin/recovery/types.js +0 -6
- package/dist/src/plugin/recovery.d.ts +0 -60
- package/dist/src/plugin/recovery.js +0 -360
- package/dist/src/plugin/refresh-queue.d.ts +0 -99
- package/dist/src/plugin/refresh-queue.js +0 -235
- package/dist/src/plugin/request-helpers.d.ts +0 -281
- package/dist/src/plugin/request-helpers.js +0 -2200
- package/dist/src/plugin/request.d.ts +0 -110
- package/dist/src/plugin/request.js +0 -1489
- package/dist/src/plugin/rotation.d.ts +0 -182
- package/dist/src/plugin/rotation.js +0 -364
- package/dist/src/plugin/search.d.ts +0 -31
- package/dist/src/plugin/search.js +0 -185
- package/dist/src/plugin/server.d.ts +0 -22
- package/dist/src/plugin/server.js +0 -306
- package/dist/src/plugin/storage.d.ts +0 -136
- package/dist/src/plugin/storage.js +0 -599
- package/dist/src/plugin/stores/signature-store.d.ts +0 -4
- package/dist/src/plugin/stores/signature-store.js +0 -24
- package/dist/src/plugin/thinking-recovery.d.ts +0 -89
- package/dist/src/plugin/thinking-recovery.js +0 -289
- package/dist/src/plugin/token.d.ts +0 -18
- package/dist/src/plugin/token.js +0 -127
- package/dist/src/plugin/transform/claude.d.ts +0 -79
- package/dist/src/plugin/transform/claude.js +0 -256
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/src/plugin/transform/gemini.d.ts +0 -132
- package/dist/src/plugin/transform/gemini.js +0 -659
- package/dist/src/plugin/transform/index.d.ts +0 -14
- package/dist/src/plugin/transform/index.js +0 -9
- package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/src/plugin/transform/model-resolver.js +0 -320
- package/dist/src/plugin/transform/types.d.ts +0 -110
- package/dist/src/plugin/transform/types.js +0 -1
- package/dist/src/plugin/types.d.ts +0 -95
- package/dist/src/plugin/types.js +0 -1
- package/dist/src/plugin/ui/ansi.d.ts +0 -31
- package/dist/src/plugin/ui/ansi.js +0 -45
- package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/src/plugin/ui/auth-menu.js +0 -199
- package/dist/src/plugin/ui/confirm.d.ts +0 -1
- package/dist/src/plugin/ui/confirm.js +0 -14
- package/dist/src/plugin/ui/select.d.ts +0 -22
- package/dist/src/plugin/ui/select.js +0 -243
- package/dist/src/plugin/version.d.ts +0 -18
- package/dist/src/plugin/version.js +0 -79
package/dist/src/plugin/quota.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { ANTIGRAVITY_ENDPOINT_PROD, getAntigravityHeaders, ANTIGRAVITY_PROVIDER_ID, } from "../constants";
|
|
2
|
-
import { accessTokenExpired, formatRefreshParts, parseRefreshParts } from "./auth";
|
|
3
|
-
import { logQuotaFetch, logQuotaStatus } from "./debug";
|
|
4
|
-
import { ensureProjectContext } from "./project";
|
|
5
|
-
import { refreshAccessToken } from "./token";
|
|
6
|
-
import { getModelFamily } from "./transform/model-resolver";
|
|
7
|
-
const FETCH_TIMEOUT_MS = 10000;
|
|
8
|
-
function buildAuthFromAccount(account) {
|
|
9
|
-
return {
|
|
10
|
-
type: "oauth",
|
|
11
|
-
refresh: formatRefreshParts({
|
|
12
|
-
refreshToken: account.refreshToken,
|
|
13
|
-
projectId: account.projectId,
|
|
14
|
-
managedProjectId: account.managedProjectId,
|
|
15
|
-
}),
|
|
16
|
-
access: undefined,
|
|
17
|
-
expires: undefined,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function normalizeRemainingFraction(value) {
|
|
21
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
24
|
-
if (value < 0)
|
|
25
|
-
return 0;
|
|
26
|
-
if (value > 1)
|
|
27
|
-
return 1;
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
function parseResetTime(resetTime) {
|
|
31
|
-
if (!resetTime)
|
|
32
|
-
return null;
|
|
33
|
-
const timestamp = Date.parse(resetTime);
|
|
34
|
-
if (!Number.isFinite(timestamp)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
return timestamp;
|
|
38
|
-
}
|
|
39
|
-
function classifyQuotaGroup(modelName, displayName) {
|
|
40
|
-
const combined = `${modelName} ${displayName ?? ""}`.toLowerCase();
|
|
41
|
-
if (combined.includes("claude")) {
|
|
42
|
-
return "claude";
|
|
43
|
-
}
|
|
44
|
-
const isGemini3 = combined.includes("gemini-3") || combined.includes("gemini 3");
|
|
45
|
-
if (!isGemini3) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const family = getModelFamily(modelName);
|
|
49
|
-
return family === "gemini-flash" ? "gemini-flash" : "gemini-pro";
|
|
50
|
-
}
|
|
51
|
-
function aggregateQuota(models) {
|
|
52
|
-
const groups = {};
|
|
53
|
-
if (!models) {
|
|
54
|
-
return { groups, modelCount: 0 };
|
|
55
|
-
}
|
|
56
|
-
let totalCount = 0;
|
|
57
|
-
for (const [modelName, entry] of Object.entries(models)) {
|
|
58
|
-
const group = classifyQuotaGroup(modelName, entry.displayName ?? entry.modelName);
|
|
59
|
-
if (!group) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const quotaInfo = entry.quotaInfo;
|
|
63
|
-
const remainingFraction = quotaInfo
|
|
64
|
-
? normalizeRemainingFraction(quotaInfo.remainingFraction)
|
|
65
|
-
: undefined;
|
|
66
|
-
const resetTime = quotaInfo?.resetTime;
|
|
67
|
-
const resetTimestamp = parseResetTime(resetTime);
|
|
68
|
-
totalCount += 1;
|
|
69
|
-
const existing = groups[group];
|
|
70
|
-
const nextCount = (existing?.modelCount ?? 0) + 1;
|
|
71
|
-
const nextRemaining = remainingFraction === undefined
|
|
72
|
-
? existing?.remainingFraction
|
|
73
|
-
: existing?.remainingFraction === undefined
|
|
74
|
-
? remainingFraction
|
|
75
|
-
: Math.min(existing.remainingFraction, remainingFraction);
|
|
76
|
-
let nextResetTime = existing?.resetTime;
|
|
77
|
-
if (resetTimestamp !== null) {
|
|
78
|
-
if (!existing?.resetTime) {
|
|
79
|
-
nextResetTime = resetTime;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const existingTimestamp = parseResetTime(existing.resetTime);
|
|
83
|
-
if (existingTimestamp === null || resetTimestamp < existingTimestamp) {
|
|
84
|
-
nextResetTime = resetTime;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
groups[group] = {
|
|
89
|
-
remainingFraction: nextRemaining,
|
|
90
|
-
resetTime: nextResetTime,
|
|
91
|
-
modelCount: nextCount,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return { groups, modelCount: totalCount };
|
|
95
|
-
}
|
|
96
|
-
async function fetchWithTimeout(url, options, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
97
|
-
const controller = new AbortController();
|
|
98
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
99
|
-
try {
|
|
100
|
-
return await fetch(url, { ...options, signal: controller.signal });
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
clearTimeout(timeout);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async function fetchAvailableModels(accessToken, projectId) {
|
|
107
|
-
const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
|
|
108
|
-
const quotaUserAgent = getAntigravityHeaders()["User-Agent"] || "antigravity/windows/amd64";
|
|
109
|
-
const errors = [];
|
|
110
|
-
const body = projectId ? { project: projectId } : {};
|
|
111
|
-
const response = await fetchWithTimeout(`${endpoint}/v1internal:fetchAvailableModels`, {
|
|
112
|
-
method: "POST",
|
|
113
|
-
headers: {
|
|
114
|
-
Authorization: `Bearer ${accessToken}`,
|
|
115
|
-
"Content-Type": "application/json",
|
|
116
|
-
"User-Agent": quotaUserAgent,
|
|
117
|
-
},
|
|
118
|
-
body: JSON.stringify(body),
|
|
119
|
-
});
|
|
120
|
-
if (response.ok) {
|
|
121
|
-
return (await response.json());
|
|
122
|
-
}
|
|
123
|
-
const message = await response.text().catch(() => "");
|
|
124
|
-
const snippet = message.trim().slice(0, 200);
|
|
125
|
-
errors.push(`fetchAvailableModels ${response.status} at ${endpoint}${snippet ? `: ${snippet}` : ""}`);
|
|
126
|
-
throw new Error(errors.join("; ") || "fetchAvailableModels failed");
|
|
127
|
-
}
|
|
128
|
-
async function fetchGeminiCliQuota(accessToken, projectId) {
|
|
129
|
-
const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
|
|
130
|
-
const platform = process.platform || "darwin";
|
|
131
|
-
const arch = process.arch || "arm64";
|
|
132
|
-
const geminiCliUserAgent = `GeminiCLI/1.0.0/gemini-2.5-pro (${platform}; ${arch})`;
|
|
133
|
-
const body = projectId ? { project: projectId } : {};
|
|
134
|
-
try {
|
|
135
|
-
const response = await fetchWithTimeout(`${endpoint}/v1internal:retrieveUserQuota`, {
|
|
136
|
-
method: "POST",
|
|
137
|
-
headers: {
|
|
138
|
-
Authorization: `Bearer ${accessToken}`,
|
|
139
|
-
"Content-Type": "application/json",
|
|
140
|
-
"User-Agent": geminiCliUserAgent,
|
|
141
|
-
},
|
|
142
|
-
body: JSON.stringify(body),
|
|
143
|
-
});
|
|
144
|
-
if (response.ok) {
|
|
145
|
-
const data = (await response.json());
|
|
146
|
-
return data;
|
|
147
|
-
}
|
|
148
|
-
return { buckets: [] };
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return { buckets: [] };
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function aggregateGeminiCliQuota(response) {
|
|
155
|
-
const models = [];
|
|
156
|
-
if (!response.buckets || response.buckets.length === 0) {
|
|
157
|
-
return { models };
|
|
158
|
-
}
|
|
159
|
-
for (const bucket of response.buckets) {
|
|
160
|
-
if (!bucket.modelId) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const modelId = bucket.modelId;
|
|
164
|
-
const isRelevantModel = modelId.startsWith("gemini-3-") ||
|
|
165
|
-
modelId === "gemini-2.5-pro";
|
|
166
|
-
if (!isRelevantModel) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
models.push({
|
|
170
|
-
modelId: bucket.modelId,
|
|
171
|
-
remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
|
|
172
|
-
resetTime: bucket.resetTime,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
models.sort((a, b) => a.modelId.localeCompare(b.modelId));
|
|
176
|
-
return { models };
|
|
177
|
-
}
|
|
178
|
-
function applyAccountUpdates(account, auth) {
|
|
179
|
-
const parts = parseRefreshParts(auth.refresh);
|
|
180
|
-
if (!parts.refreshToken) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
const updated = {
|
|
184
|
-
...account,
|
|
185
|
-
refreshToken: parts.refreshToken,
|
|
186
|
-
projectId: parts.projectId ?? account.projectId,
|
|
187
|
-
managedProjectId: parts.managedProjectId ?? account.managedProjectId,
|
|
188
|
-
};
|
|
189
|
-
const changed = updated.refreshToken !== account.refreshToken ||
|
|
190
|
-
updated.projectId !== account.projectId ||
|
|
191
|
-
updated.managedProjectId !== account.managedProjectId;
|
|
192
|
-
return changed ? updated : undefined;
|
|
193
|
-
}
|
|
194
|
-
export async function checkAccountsQuota(accounts, client, providerId = ANTIGRAVITY_PROVIDER_ID) {
|
|
195
|
-
const results = [];
|
|
196
|
-
logQuotaFetch("start", accounts.length);
|
|
197
|
-
for (const [index, account] of accounts.entries()) {
|
|
198
|
-
const disabled = account.enabled === false;
|
|
199
|
-
let auth = buildAuthFromAccount(account);
|
|
200
|
-
try {
|
|
201
|
-
if (accessTokenExpired(auth)) {
|
|
202
|
-
const refreshed = await refreshAccessToken(auth, client, providerId);
|
|
203
|
-
if (!refreshed) {
|
|
204
|
-
throw new Error("Token refresh failed");
|
|
205
|
-
}
|
|
206
|
-
auth = refreshed;
|
|
207
|
-
}
|
|
208
|
-
const projectContext = await ensureProjectContext(auth);
|
|
209
|
-
auth = projectContext.auth;
|
|
210
|
-
const updatedAccount = applyAccountUpdates(account, auth);
|
|
211
|
-
let quotaResult;
|
|
212
|
-
let geminiCliQuotaResult;
|
|
213
|
-
const [antigravityResponse, geminiCliResponse] = await Promise.all([
|
|
214
|
-
fetchAvailableModels(auth.access ?? "", projectContext.effectiveProjectId)
|
|
215
|
-
.catch((error) => ({ models: undefined })),
|
|
216
|
-
fetchGeminiCliQuota(auth.access ?? "", projectContext.effectiveProjectId),
|
|
217
|
-
]);
|
|
218
|
-
if (antigravityResponse.models === undefined) {
|
|
219
|
-
quotaResult = {
|
|
220
|
-
groups: {},
|
|
221
|
-
modelCount: 0,
|
|
222
|
-
error: "Failed to fetch Antigravity quota",
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
quotaResult = aggregateQuota(antigravityResponse.models);
|
|
227
|
-
}
|
|
228
|
-
geminiCliQuotaResult = aggregateGeminiCliQuota(geminiCliResponse);
|
|
229
|
-
if (geminiCliResponse.buckets === undefined || geminiCliResponse.buckets.length === 0) {
|
|
230
|
-
geminiCliQuotaResult.error = geminiCliQuotaResult.models.length === 0
|
|
231
|
-
? "No Gemini CLI quota available"
|
|
232
|
-
: undefined;
|
|
233
|
-
}
|
|
234
|
-
results.push({
|
|
235
|
-
index,
|
|
236
|
-
email: account.email,
|
|
237
|
-
status: "ok",
|
|
238
|
-
disabled,
|
|
239
|
-
quota: quotaResult,
|
|
240
|
-
geminiCliQuota: geminiCliQuotaResult,
|
|
241
|
-
updatedAccount,
|
|
242
|
-
});
|
|
243
|
-
for (const [family, groupQuota] of Object.entries(quotaResult.groups)) {
|
|
244
|
-
const remainingPercent = (groupQuota.remainingFraction ?? 0) * 100;
|
|
245
|
-
logQuotaStatus(account.email, index, remainingPercent, family);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
results.push({
|
|
250
|
-
index,
|
|
251
|
-
email: account.email,
|
|
252
|
-
status: "error",
|
|
253
|
-
disabled,
|
|
254
|
-
error: error instanceof Error ? error.message : String(error),
|
|
255
|
-
});
|
|
256
|
-
logQuotaFetch("error", undefined, `account=${account.email ?? index} error=${error instanceof Error ? error.message : String(error)}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
logQuotaFetch("complete", accounts.length, `ok=${results.filter(r => r.status === "ok").length} errors=${results.filter(r => r.status === "error").length}`);
|
|
260
|
-
return results;
|
|
261
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for session recovery storage paths.
|
|
3
|
-
*
|
|
4
|
-
* Based on oh-my-opencode/src/hooks/session-recovery/constants.ts
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Get the XDG config directory for Antigravity config.
|
|
8
|
-
* Falls back to ~/.config on Linux/Mac, or APPDATA on Windows.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getXdgConfig(): string;
|
|
11
|
-
/**
|
|
12
|
-
* Get the Antigravity config directory.
|
|
13
|
-
* Default: ~/.config/opencode/antigravity.json
|
|
14
|
-
*/
|
|
15
|
-
export declare function getAntigravityConfigDir(): string;
|
|
16
|
-
export declare const OPENCODE_STORAGE: string;
|
|
17
|
-
export declare const MESSAGE_STORAGE: string;
|
|
18
|
-
export declare const PART_STORAGE: string;
|
|
19
|
-
export declare const THINKING_TYPES: Set<string>;
|
|
20
|
-
export declare const META_TYPES: Set<string>;
|
|
21
|
-
export declare const CONTENT_TYPES: Set<string>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for session recovery storage paths.
|
|
3
|
-
*
|
|
4
|
-
* Based on oh-my-opencode/src/hooks/session-recovery/constants.ts
|
|
5
|
-
*/
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { homedir } from "node:os";
|
|
8
|
-
/**
|
|
9
|
-
* Get the XDG data directory for OpenCode storage.
|
|
10
|
-
* Falls back to ~/.local/share on Linux/Mac, or APPDATA on Windows.
|
|
11
|
-
*/
|
|
12
|
-
function getXdgData() {
|
|
13
|
-
const platform = process.platform;
|
|
14
|
-
if (platform === "win32") {
|
|
15
|
-
return process.env.APPDATA || join(homedir(), "AppData", "Roaming");
|
|
16
|
-
}
|
|
17
|
-
return process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Get the XDG config directory for Antigravity config.
|
|
21
|
-
* Falls back to ~/.config on Linux/Mac, or APPDATA on Windows.
|
|
22
|
-
*/
|
|
23
|
-
export function getXdgConfig() {
|
|
24
|
-
const platform = process.platform;
|
|
25
|
-
if (platform === "win32") {
|
|
26
|
-
return process.env.APPDATA || join(homedir(), "AppData", "Roaming");
|
|
27
|
-
}
|
|
28
|
-
return process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Get the Antigravity config directory.
|
|
32
|
-
* Default: ~/.config/opencode/antigravity.json
|
|
33
|
-
*/
|
|
34
|
-
export function getAntigravityConfigDir() {
|
|
35
|
-
return join(getXdgConfig(), "opencode");
|
|
36
|
-
}
|
|
37
|
-
export const OPENCODE_STORAGE = join(getXdgData(), "opencode", "storage");
|
|
38
|
-
export const MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message");
|
|
39
|
-
export const PART_STORAGE = join(OPENCODE_STORAGE, "part");
|
|
40
|
-
export const THINKING_TYPES = new Set(["thinking", "redacted_thinking", "reasoning"]);
|
|
41
|
-
export const META_TYPES = new Set(["step-start", "step-finish"]);
|
|
42
|
-
export const CONTENT_TYPES = new Set(["text", "tool", "tool_use", "tool_result"]);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session recovery module for opencode-antigravity-auth.
|
|
3
|
-
*
|
|
4
|
-
* Provides recovery from:
|
|
5
|
-
* - tool_result_missing: Interrupted tool executions
|
|
6
|
-
* - thinking_block_order: Corrupted thinking blocks
|
|
7
|
-
* - thinking_disabled_violation: Thinking in non-thinking model
|
|
8
|
-
*/
|
|
9
|
-
export * from "./types";
|
|
10
|
-
export * from "./constants";
|
|
11
|
-
export * from "./storage";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session recovery module for opencode-antigravity-auth.
|
|
3
|
-
*
|
|
4
|
-
* Provides recovery from:
|
|
5
|
-
* - tool_result_missing: Interrupted tool executions
|
|
6
|
-
* - thinking_block_order: Corrupted thinking blocks
|
|
7
|
-
* - thinking_disabled_violation: Thinking in non-thinking model
|
|
8
|
-
*/
|
|
9
|
-
export * from "./types";
|
|
10
|
-
export * from "./constants";
|
|
11
|
-
export * from "./storage";
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage utilities for reading OpenCode's session data.
|
|
3
|
-
*
|
|
4
|
-
* Based on oh-my-opencode/src/hooks/session-recovery/storage.ts
|
|
5
|
-
*/
|
|
6
|
-
import type { StoredMessageMeta, StoredPart } from "./types";
|
|
7
|
-
export declare function generatePartId(): string;
|
|
8
|
-
export declare function getMessageDir(sessionID: string): string;
|
|
9
|
-
export declare function readMessages(sessionID: string): StoredMessageMeta[];
|
|
10
|
-
export declare function readParts(messageID: string): StoredPart[];
|
|
11
|
-
export declare function hasContent(part: StoredPart): boolean;
|
|
12
|
-
export declare function messageHasContent(messageID: string): boolean;
|
|
13
|
-
export declare function injectTextPart(sessionID: string, messageID: string, text: string): boolean;
|
|
14
|
-
export declare function findMessagesWithThinkingBlocks(sessionID: string): string[];
|
|
15
|
-
export declare function findMessagesWithThinkingOnly(sessionID: string): string[];
|
|
16
|
-
export declare function findMessagesWithOrphanThinking(sessionID: string): string[];
|
|
17
|
-
export declare function prependThinkingPart(sessionID: string, messageID: string): boolean;
|
|
18
|
-
export declare function stripThinkingParts(messageID: string): boolean;
|
|
19
|
-
export declare function findEmptyMessages(sessionID: string): string[];
|
|
20
|
-
export declare function findEmptyMessageByIndex(sessionID: string, targetIndex: number): string | null;
|
|
21
|
-
export declare function findMessageByIndexNeedingThinking(sessionID: string, targetIndex: number): string | null;
|
|
22
|
-
export declare function replaceEmptyTextParts(messageID: string, replacementText: string): boolean;
|
|
23
|
-
export declare function findMessagesWithEmptyTextParts(sessionID: string): string[];
|