@yitom/acp-client 0.1.6 → 0.1.7
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/contracts/quota.d.ts +2 -0
- package/dist/index.cjs +419 -18
- package/dist/index.js +448 -44
- package/dist/runtimes/agy/quota.d.ts +8 -0
- package/dist/runtimes/opencode/quota.d.ts +1 -1
- package/dist/sidecar.cjs +419 -18
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
export interface AcpQuotaLimitWindow {
|
|
11
11
|
/** 限制窗口标识或名称,如 '5h limit', 'Weekly limit', 'Monthly limit' */
|
|
12
12
|
label: string;
|
|
13
|
+
/** 分组标识,如 'Gemini Models', 'Claude and GPT models' */
|
|
14
|
+
group?: string;
|
|
13
15
|
/** 剩余百分比 (0 - 100) */
|
|
14
16
|
percentLeft: number;
|
|
15
17
|
/** 已用百分比 (0 - 100) */
|
package/dist/index.cjs
CHANGED
|
@@ -363,7 +363,7 @@ function findBuiltinAcpRuntime(id) {
|
|
|
363
363
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
364
364
|
}
|
|
365
365
|
// src/version.ts
|
|
366
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
366
|
+
var ACP_CLIENT_VERSION = "0.1.7";
|
|
367
367
|
// src/session/available-commands.ts
|
|
368
368
|
function normalizeCommand(raw) {
|
|
369
369
|
if (!raw || typeof raw !== "object")
|
|
@@ -665,8 +665,8 @@ function decodeJwtPayload(token) {
|
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
var cachedDynamicResult = null;
|
|
668
|
-
async function queryCodexAppServer(timeoutMs =
|
|
669
|
-
if (cachedDynamicResult && Date.now() - cachedDynamicResult.time <
|
|
668
|
+
async function queryCodexAppServer(timeoutMs = 1e4) {
|
|
669
|
+
if (cachedDynamicResult && Date.now() - cachedDynamicResult.time < 120000) {
|
|
670
670
|
return cachedDynamicResult.res;
|
|
671
671
|
}
|
|
672
672
|
return new Promise((resolve) => {
|
|
@@ -691,7 +691,8 @@ async function queryCodexAppServer(timeoutMs = 4000) {
|
|
|
691
691
|
};
|
|
692
692
|
timer = setTimeout(() => cleanup(null), timeoutMs);
|
|
693
693
|
try {
|
|
694
|
-
|
|
694
|
+
const cmd = process.platform === "win32" ? "codex" : import_node_fs2.existsSync("/mnt/c/Users") ? "codex.exe" : "codex";
|
|
695
|
+
proc = import_node_child_process.spawn(cmd, ["app-server"], {
|
|
695
696
|
stdio: ["pipe", "pipe", "pipe"],
|
|
696
697
|
shell: process.platform === "win32",
|
|
697
698
|
windowsHide: true
|
|
@@ -792,7 +793,7 @@ async function probeCodexQuota(options) {
|
|
|
792
793
|
isLoggedIn = true;
|
|
793
794
|
accountPlan = "API Key (Env)";
|
|
794
795
|
}
|
|
795
|
-
const dynamic = await queryCodexAppServer(
|
|
796
|
+
const dynamic = await queryCodexAppServer(1e4);
|
|
796
797
|
if (dynamic) {
|
|
797
798
|
isLoggedIn = true;
|
|
798
799
|
if (dynamic.account?.email)
|
|
@@ -1225,6 +1226,8 @@ var copilotAdapter = {
|
|
|
1225
1226
|
// src/runtimes/opencode/quota.ts
|
|
1226
1227
|
var import_node_fs8 = require("node:fs");
|
|
1227
1228
|
var import_node_child_process3 = require("node:child_process");
|
|
1229
|
+
var os = __toESM(require("node:os"), 1);
|
|
1230
|
+
var path = __toESM(require("node:path"), 1);
|
|
1228
1231
|
function resolveOpencodeAuthPath() {
|
|
1229
1232
|
const candidates = resolveOpencodeAuthCandidates();
|
|
1230
1233
|
for (const c of candidates) {
|
|
@@ -1271,10 +1274,166 @@ async function queryOpencodeAuthList(timeoutMs = 1200) {
|
|
|
1271
1274
|
}
|
|
1272
1275
|
});
|
|
1273
1276
|
}
|
|
1277
|
+
function readLocalOpencodeCredentials() {
|
|
1278
|
+
const home = os.homedir();
|
|
1279
|
+
const dbPaths = [
|
|
1280
|
+
path.join(home, ".local", "share", "opencode", "opencode.db"),
|
|
1281
|
+
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "opencode", "opencode.db") : null,
|
|
1282
|
+
path.join(home, ".config", "opencode", "opencode.db")
|
|
1283
|
+
].filter(Boolean);
|
|
1284
|
+
for (const dbPath of dbPaths) {
|
|
1285
|
+
if (!import_node_fs8.existsSync(dbPath))
|
|
1286
|
+
continue;
|
|
1287
|
+
try {
|
|
1288
|
+
let rows = [];
|
|
1289
|
+
if (typeof process.versions?.bun !== "undefined") {
|
|
1290
|
+
const { Database } = require("bun:sqlite");
|
|
1291
|
+
const db = new Database(dbPath, { readonly: true });
|
|
1292
|
+
rows = db.query("SELECT integration_id, value FROM credential").all();
|
|
1293
|
+
db.close();
|
|
1294
|
+
} else {
|
|
1295
|
+
const { DatabaseSync } = require("node:sqlite");
|
|
1296
|
+
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
1297
|
+
rows = db.prepare("SELECT integration_id, value FROM credential").all();
|
|
1298
|
+
db.close();
|
|
1299
|
+
}
|
|
1300
|
+
const opencodeCred = rows.find((r) => r.integration_id === "opencode");
|
|
1301
|
+
if (opencodeCred?.value) {
|
|
1302
|
+
const parsed = JSON.parse(opencodeCred.value);
|
|
1303
|
+
const meta = parsed.metadata || {};
|
|
1304
|
+
return {
|
|
1305
|
+
email: meta.email || undefined,
|
|
1306
|
+
name: meta.email ? meta.email.split("@")[0] : meta.orgName || undefined,
|
|
1307
|
+
token: parsed.access || undefined,
|
|
1308
|
+
orgId: meta.orgID || undefined,
|
|
1309
|
+
accountId: meta.accountID || undefined
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
} catch {
|
|
1313
|
+
try {
|
|
1314
|
+
const buf = import_node_fs8.readFileSync(dbPath, "utf8");
|
|
1315
|
+
const emailMatch = buf.match(/"email"\s*:\s*"([^"]+)"/);
|
|
1316
|
+
const tokenMatch = buf.match(/"access"\s*:\s*"(st_[a-zA-Z0-9_\\-]+)"/);
|
|
1317
|
+
const orgMatch = buf.match(/"orgID"\s*:\s*"(wrk_[a-zA-Z0-9_\\-]+)"/);
|
|
1318
|
+
const accMatch = buf.match(/"accountID"\s*:\s*"(acc_[a-zA-Z0-9_\\-]+)"/);
|
|
1319
|
+
if (emailMatch || tokenMatch) {
|
|
1320
|
+
return {
|
|
1321
|
+
email: emailMatch?.[1],
|
|
1322
|
+
name: emailMatch?.[1]?.split("@")[0],
|
|
1323
|
+
token: tokenMatch?.[1],
|
|
1324
|
+
orgId: orgMatch?.[1],
|
|
1325
|
+
accountId: accMatch?.[1]
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
} catch {}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
return {};
|
|
1332
|
+
}
|
|
1333
|
+
async function probeOpencodeGoOnlineQuota(creds, runtimeId = "opencode") {
|
|
1334
|
+
if (!creds.token || !creds.orgId)
|
|
1335
|
+
return null;
|
|
1336
|
+
try {
|
|
1337
|
+
const res = await fetch("https://opencode.ai/console/api/go/status", {
|
|
1338
|
+
headers: {
|
|
1339
|
+
Authorization: `Bearer ${creds.token}`,
|
|
1340
|
+
"x-opencode-org-id": creds.orgId,
|
|
1341
|
+
"x-opencode-account-id": creds.accountId || ""
|
|
1342
|
+
},
|
|
1343
|
+
signal: AbortSignal.timeout(3500)
|
|
1344
|
+
});
|
|
1345
|
+
if (!res.ok)
|
|
1346
|
+
return null;
|
|
1347
|
+
const data = await res.json();
|
|
1348
|
+
const meters = data?.access?.meters;
|
|
1349
|
+
if (!meters)
|
|
1350
|
+
return null;
|
|
1351
|
+
const formatReset = (isoStr) => {
|
|
1352
|
+
if (!isoStr)
|
|
1353
|
+
return;
|
|
1354
|
+
const diffMs = new Date(isoStr).getTime() - Date.now();
|
|
1355
|
+
if (diffMs <= 0)
|
|
1356
|
+
return "已重置";
|
|
1357
|
+
const totalMins = Math.floor(diffMs / 60000);
|
|
1358
|
+
const hours = Math.floor(totalMins / 60);
|
|
1359
|
+
const days = Math.floor(hours / 24);
|
|
1360
|
+
if (days > 0) {
|
|
1361
|
+
const remH = hours % 24;
|
|
1362
|
+
return `Resets in ${days}d ${remH}h`;
|
|
1363
|
+
}
|
|
1364
|
+
const remM = totalMins % 60;
|
|
1365
|
+
return `Resets in ${hours}h ${remM}m`;
|
|
1366
|
+
};
|
|
1367
|
+
const calcWindow = (m, label, durMins) => {
|
|
1368
|
+
if (!m || !m.limitMicroCents)
|
|
1369
|
+
return;
|
|
1370
|
+
const limit = Number(m.limitMicroCents);
|
|
1371
|
+
const used = Number(m.usedMicroCents || 0);
|
|
1372
|
+
const usedPercent = limit > 0 ? Math.round(used / limit * 100) : 0;
|
|
1373
|
+
const percentLeft = Math.max(0, 100 - usedPercent);
|
|
1374
|
+
return {
|
|
1375
|
+
label,
|
|
1376
|
+
usedPercent,
|
|
1377
|
+
percentLeft,
|
|
1378
|
+
windowDurationMins: durMins,
|
|
1379
|
+
resetsAt: formatReset(m.resetsAt)
|
|
1380
|
+
};
|
|
1381
|
+
};
|
|
1382
|
+
const rolling = calcWindow(meters.fiveHour, "Rolling", 300);
|
|
1383
|
+
const weekly = calcWindow(meters.week, "Weekly", 10080);
|
|
1384
|
+
const monthly = calcWindow(meters.month, "Monthly", 43200);
|
|
1385
|
+
let creditBalance = "$0.00";
|
|
1386
|
+
try {
|
|
1387
|
+
const bRes = await fetch("https://opencode.ai/console/api/billing/status", {
|
|
1388
|
+
headers: {
|
|
1389
|
+
Authorization: `Bearer ${creds.token}`,
|
|
1390
|
+
"x-opencode-org-id": creds.orgId,
|
|
1391
|
+
"x-opencode-account-id": creds.accountId || ""
|
|
1392
|
+
},
|
|
1393
|
+
signal: AbortSignal.timeout(2000)
|
|
1394
|
+
});
|
|
1395
|
+
if (bRes.ok) {
|
|
1396
|
+
const bData = await bRes.json();
|
|
1397
|
+
const availMicro = Number(bData.availableMicroCents || 0);
|
|
1398
|
+
creditBalance = `$${(availMicro / 1e8).toFixed(2)}`;
|
|
1399
|
+
}
|
|
1400
|
+
} catch {}
|
|
1401
|
+
const quota = {
|
|
1402
|
+
runtimeId,
|
|
1403
|
+
provider: "OpenCode",
|
|
1404
|
+
account: {
|
|
1405
|
+
email: creds.email,
|
|
1406
|
+
name: creds.name || "OpenCode User",
|
|
1407
|
+
plan: "OpenCode Go",
|
|
1408
|
+
type: "opencode"
|
|
1409
|
+
},
|
|
1410
|
+
primaryWindow: rolling,
|
|
1411
|
+
secondaryWindow: weekly,
|
|
1412
|
+
extraWindows: monthly ? [monthly] : undefined,
|
|
1413
|
+
credits: {
|
|
1414
|
+
balance: creditBalance,
|
|
1415
|
+
currency: "USD",
|
|
1416
|
+
unlimited: false
|
|
1417
|
+
},
|
|
1418
|
+
status: "ok",
|
|
1419
|
+
updatedAt: Date.now()
|
|
1420
|
+
};
|
|
1421
|
+
return quota;
|
|
1422
|
+
} catch {
|
|
1423
|
+
return null;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1274
1426
|
async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
1427
|
+
const dbCreds = readLocalOpencodeCredentials();
|
|
1428
|
+
if (dbCreds.token) {
|
|
1429
|
+
const goQuota = await probeOpencodeGoOnlineQuota(dbCreds, runtimeId);
|
|
1430
|
+
if (goQuota)
|
|
1431
|
+
return goQuota;
|
|
1432
|
+
}
|
|
1275
1433
|
const authPath = resolveOpencodeAuthPath();
|
|
1276
|
-
let isLoggedIn =
|
|
1277
|
-
let accountEmail;
|
|
1434
|
+
let isLoggedIn = Boolean(dbCreds.token || dbCreds.email);
|
|
1435
|
+
let accountEmail = dbCreds.email;
|
|
1436
|
+
let accountName = dbCreds.name;
|
|
1278
1437
|
let plan = "OpenCode Community";
|
|
1279
1438
|
if (authPath && import_node_fs8.existsSync(authPath)) {
|
|
1280
1439
|
try {
|
|
@@ -1298,7 +1457,9 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
1298
1457
|
if (authList.length > 0) {
|
|
1299
1458
|
isLoggedIn = true;
|
|
1300
1459
|
const providers = authList.map((l) => l.split(/\s{2,}/)[0]).filter(Boolean);
|
|
1301
|
-
if (providers.
|
|
1460
|
+
if (providers.some((p) => p.toLowerCase().includes("go"))) {
|
|
1461
|
+
plan = "OpenCode Go";
|
|
1462
|
+
} else if (providers.length > 0) {
|
|
1302
1463
|
plan = `OpenCode (${providers.join(", ")})`;
|
|
1303
1464
|
}
|
|
1304
1465
|
}
|
|
@@ -1317,7 +1478,7 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
1317
1478
|
let credits;
|
|
1318
1479
|
if (stats && typeof stats.cost === "number") {
|
|
1319
1480
|
credits = {
|
|
1320
|
-
balance: stats.cost > 0 ? `$${stats.cost.toFixed(2)} spent` : "0.00"
|
|
1481
|
+
balance: stats.cost > 0 ? `$${stats.cost.toFixed(2)} spent` : "$0.00"
|
|
1321
1482
|
};
|
|
1322
1483
|
}
|
|
1323
1484
|
return {
|
|
@@ -1325,6 +1486,7 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
1325
1486
|
provider: "OpenCode",
|
|
1326
1487
|
account: {
|
|
1327
1488
|
email: accountEmail,
|
|
1489
|
+
name: accountName,
|
|
1328
1490
|
plan,
|
|
1329
1491
|
type: "provider_oauth"
|
|
1330
1492
|
},
|
|
@@ -1782,21 +1944,240 @@ var deepseekAdapter = {
|
|
|
1782
1944
|
// src/runtimes/agy/quota.ts
|
|
1783
1945
|
var import_node_fs11 = require("node:fs");
|
|
1784
1946
|
var import_node_path12 = require("node:path");
|
|
1947
|
+
var import_node_child_process5 = require("node:child_process");
|
|
1948
|
+
var os2 = __toESM(require("node:os"), 1);
|
|
1785
1949
|
function resolveGeminiHome2() {
|
|
1786
1950
|
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
1787
1951
|
return import_node_path12.join(home, ".gemini");
|
|
1788
1952
|
}
|
|
1953
|
+
function resolveAntigravityAccount() {
|
|
1954
|
+
if (process.env.GOOGLE_ACCOUNT?.trim()) {
|
|
1955
|
+
const email = process.env.GOOGLE_ACCOUNT.trim();
|
|
1956
|
+
return { email, name: email.split("@")[0] };
|
|
1957
|
+
}
|
|
1958
|
+
if (process.env.ANTIGRAVITY_ACCOUNT?.trim()) {
|
|
1959
|
+
const email = process.env.ANTIGRAVITY_ACCOUNT.trim();
|
|
1960
|
+
return { email, name: email.split("@")[0] };
|
|
1961
|
+
}
|
|
1962
|
+
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
1963
|
+
const candidates = [
|
|
1964
|
+
process.env.APPDATA ? import_node_path12.join(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
|
|
1965
|
+
import_node_path12.join(home, ".config", "Antigravity", "app_storage.json"),
|
|
1966
|
+
import_node_path12.join(home, "Library", "Application Support", "Antigravity", "app_storage.json")
|
|
1967
|
+
].filter(Boolean);
|
|
1968
|
+
for (const file of candidates) {
|
|
1969
|
+
try {
|
|
1970
|
+
if (import_node_fs11.existsSync(file)) {
|
|
1971
|
+
const raw = import_node_fs11.readFileSync(file, "utf8");
|
|
1972
|
+
const json = JSON.parse(raw);
|
|
1973
|
+
const username = json["jetski.onboarding.lastLoginUsername"];
|
|
1974
|
+
if (username && typeof username === "string" && username.trim()) {
|
|
1975
|
+
const u = username.trim();
|
|
1976
|
+
return {
|
|
1977
|
+
email: u,
|
|
1978
|
+
name: u.includes("@") ? u.split("@")[0] : u
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
} catch {}
|
|
1983
|
+
}
|
|
1984
|
+
const osUser = process.env.USERNAME || process.env.USER;
|
|
1985
|
+
if (osUser?.trim()) {
|
|
1986
|
+
return { name: osUser.trim() };
|
|
1987
|
+
}
|
|
1988
|
+
return {};
|
|
1989
|
+
}
|
|
1990
|
+
function resolveAntigravityLanguageServer() {
|
|
1991
|
+
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
1992
|
+
const appData = process.env.APPDATA || (process.platform === "win32" ? import_node_path12.join(home, "AppData", "Roaming") : "");
|
|
1993
|
+
const baseDirs = [
|
|
1994
|
+
appData ? import_node_path12.join(appData, "Antigravity IDE", "logs") : null,
|
|
1995
|
+
appData ? import_node_path12.join(appData, "Antigravity", "logs") : null,
|
|
1996
|
+
import_node_path12.join(home, ".config", "Antigravity IDE", "logs"),
|
|
1997
|
+
import_node_path12.join(home, ".config", "Antigravity", "logs"),
|
|
1998
|
+
import_node_path12.join(home, "Library", "Application Support", "Antigravity IDE", "logs"),
|
|
1999
|
+
import_node_path12.join(home, "Library", "Application Support", "Antigravity", "logs")
|
|
2000
|
+
].filter(Boolean);
|
|
2001
|
+
for (const base of baseDirs) {
|
|
2002
|
+
try {
|
|
2003
|
+
if (!import_node_fs11.existsSync(base))
|
|
2004
|
+
continue;
|
|
2005
|
+
const sessionDirs = import_node_fs11.readdirSync(base).map((d) => {
|
|
2006
|
+
try {
|
|
2007
|
+
return { name: d, time: import_node_fs11.statSync(import_node_path12.join(base, d)).mtimeMs };
|
|
2008
|
+
} catch {
|
|
2009
|
+
return null;
|
|
2010
|
+
}
|
|
2011
|
+
}).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
|
|
2012
|
+
for (const s of sessionDirs) {
|
|
2013
|
+
const logFile = import_node_path12.join(base, s.name, "ls-main.log");
|
|
2014
|
+
if (import_node_fs11.existsSync(logFile)) {
|
|
2015
|
+
const content = import_node_fs11.readFileSync(logFile, "utf8");
|
|
2016
|
+
const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
2017
|
+
const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
|
|
2018
|
+
if (csrfMatch && portMatch) {
|
|
2019
|
+
return {
|
|
2020
|
+
port: parseInt(portMatch[1], 10),
|
|
2021
|
+
csrfToken: csrfMatch[1]
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
} catch {}
|
|
2027
|
+
}
|
|
2028
|
+
try {
|
|
2029
|
+
let out = "";
|
|
2030
|
+
if (process.platform === "win32") {
|
|
2031
|
+
out = import_node_child_process5.execFileSync("powershell", [
|
|
2032
|
+
"-NoProfile",
|
|
2033
|
+
"-Command",
|
|
2034
|
+
`Get-CimInstance Win32_Process -Filter "Name like '%language_server%'" | Select-Object -ExpandProperty CommandLine`
|
|
2035
|
+
], { encoding: "utf8", timeout: 4000, windowsHide: true });
|
|
2036
|
+
} else {
|
|
2037
|
+
out = import_node_child_process5.execFileSync("ps", ["aux"], { encoding: "utf8", timeout: 4000 });
|
|
2038
|
+
}
|
|
2039
|
+
const lines = out.split(/\r?\n/);
|
|
2040
|
+
for (const l of lines) {
|
|
2041
|
+
const portMatch = l.match(/--https_server_port\s+(\d+)/);
|
|
2042
|
+
const csrfMatch = l.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
2043
|
+
if (portMatch && csrfMatch) {
|
|
2044
|
+
return { port: parseInt(portMatch[1], 10), csrfToken: csrfMatch[1] };
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
} catch {}
|
|
2048
|
+
return null;
|
|
2049
|
+
}
|
|
1789
2050
|
async function probeAgyQuota(options) {
|
|
2051
|
+
const acc = resolveAntigravityAccount();
|
|
2052
|
+
const lsInfo = resolveAntigravityLanguageServer();
|
|
2053
|
+
if (lsInfo) {
|
|
2054
|
+
try {
|
|
2055
|
+
let data = null;
|
|
2056
|
+
const prevReject = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
2057
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
2058
|
+
try {
|
|
2059
|
+
const res = await fetch(`https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`, {
|
|
2060
|
+
method: "POST",
|
|
2061
|
+
headers: {
|
|
2062
|
+
"Content-Type": "application/json",
|
|
2063
|
+
"x-codeium-csrf-token": lsInfo.csrfToken
|
|
2064
|
+
},
|
|
2065
|
+
body: JSON.stringify({}),
|
|
2066
|
+
signal: AbortSignal.timeout(4000),
|
|
2067
|
+
tls: { rejectUnauthorized: false }
|
|
2068
|
+
});
|
|
2069
|
+
if (res.ok) {
|
|
2070
|
+
data = await res.json();
|
|
2071
|
+
}
|
|
2072
|
+
} catch {
|
|
2073
|
+
try {
|
|
2074
|
+
const raw = import_node_child_process5.execFileSync(process.platform === "win32" ? "curl.exe" : "curl", [
|
|
2075
|
+
"-k",
|
|
2076
|
+
"-s",
|
|
2077
|
+
"-X",
|
|
2078
|
+
"POST",
|
|
2079
|
+
"-H",
|
|
2080
|
+
"Content-Type: application/json",
|
|
2081
|
+
"-H",
|
|
2082
|
+
`x-codeium-csrf-token: ${lsInfo.csrfToken}`,
|
|
2083
|
+
"-d",
|
|
2084
|
+
"{}",
|
|
2085
|
+
`https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`
|
|
2086
|
+
], { encoding: "utf8", timeout: 4000 });
|
|
2087
|
+
data = JSON.parse(raw);
|
|
2088
|
+
} catch {}
|
|
2089
|
+
} finally {
|
|
2090
|
+
if (prevReject !== undefined) {
|
|
2091
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = prevReject;
|
|
2092
|
+
} else {
|
|
2093
|
+
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
if (data?.response?.groups) {
|
|
2097
|
+
const groups = data.response.groups;
|
|
2098
|
+
const formatReset = (isoStr, fallbackDesc) => {
|
|
2099
|
+
if (fallbackDesc && fallbackDesc.includes("it will fully refresh in ")) {
|
|
2100
|
+
const m = fallbackDesc.match(/it will fully refresh in (.+?)\.?$/);
|
|
2101
|
+
if (m?.[1])
|
|
2102
|
+
return `Resets in ${m[1].trim()}`;
|
|
2103
|
+
}
|
|
2104
|
+
if (!isoStr)
|
|
2105
|
+
return;
|
|
2106
|
+
const diffMs = new Date(isoStr).getTime() - Date.now();
|
|
2107
|
+
if (diffMs <= 0)
|
|
2108
|
+
return "已重置";
|
|
2109
|
+
const totalMins = Math.floor(diffMs / 60000);
|
|
2110
|
+
const hours = Math.floor(totalMins / 60);
|
|
2111
|
+
const days = Math.floor(hours / 24);
|
|
2112
|
+
if (days > 0)
|
|
2113
|
+
return `Resets in ${days}d ${hours % 24}h`;
|
|
2114
|
+
return `Resets in ${hours}h ${totalMins % 60}m`;
|
|
2115
|
+
};
|
|
2116
|
+
const toWindow = (b, groupName, label, durMins) => {
|
|
2117
|
+
if (!b)
|
|
2118
|
+
return;
|
|
2119
|
+
const frac = typeof b.remainingFraction === "number" ? b.remainingFraction : 1;
|
|
2120
|
+
const percentLeft = Math.max(0, Math.min(100, Math.round(frac * 100)));
|
|
2121
|
+
const usedPercent = 100 - percentLeft;
|
|
2122
|
+
return {
|
|
2123
|
+
label,
|
|
2124
|
+
group: groupName,
|
|
2125
|
+
percentLeft,
|
|
2126
|
+
usedPercent,
|
|
2127
|
+
windowDurationMins: durMins,
|
|
2128
|
+
resetsAt: formatReset(b.resetTime, b.description)
|
|
2129
|
+
};
|
|
2130
|
+
};
|
|
2131
|
+
const geminiGroup = groups.find((g) => g.displayName?.toLowerCase().includes("gemini"));
|
|
2132
|
+
const thirdPartyGroup = groups.find((g) => g.displayName?.toLowerCase().includes("claude") || g.displayName?.toLowerCase().includes("gpt"));
|
|
2133
|
+
const gemini5h = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
|
|
2134
|
+
const geminiWeekly = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
|
|
2135
|
+
const tp5h = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
|
|
2136
|
+
const tpWeekly = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
|
|
2137
|
+
const primaryWindow = toWindow(gemini5h, "Gemini Models", "5-Hour limit", 300) || {
|
|
2138
|
+
label: "5-Hour limit",
|
|
2139
|
+
group: "Gemini Models",
|
|
2140
|
+
percentLeft: 100,
|
|
2141
|
+
usedPercent: 0,
|
|
2142
|
+
windowDurationMins: 300
|
|
2143
|
+
};
|
|
2144
|
+
const secondaryWindow = toWindow(geminiWeekly, "Gemini Models", "Weekly limit", 10080);
|
|
2145
|
+
const extraWindows = [
|
|
2146
|
+
toWindow(tp5h, "Claude and GPT models", "5-Hour limit", 300),
|
|
2147
|
+
toWindow(tpWeekly, "Claude and GPT models", "Weekly limit", 10080)
|
|
2148
|
+
].filter(Boolean);
|
|
2149
|
+
return {
|
|
2150
|
+
runtimeId: "agy",
|
|
2151
|
+
provider: "Google Antigravity",
|
|
2152
|
+
account: {
|
|
2153
|
+
email: acc.email,
|
|
2154
|
+
name: acc.name || "Google Developer",
|
|
2155
|
+
plan: "Google AI Pro",
|
|
2156
|
+
type: "gemini"
|
|
2157
|
+
},
|
|
2158
|
+
primaryWindow,
|
|
2159
|
+
secondaryWindow,
|
|
2160
|
+
extraWindows: extraWindows.length > 0 ? extraWindows : undefined,
|
|
2161
|
+
credits: {
|
|
2162
|
+
unlimited: true,
|
|
2163
|
+
balance: "unlimited"
|
|
2164
|
+
},
|
|
2165
|
+
status: "ok",
|
|
2166
|
+
updatedAt: Date.now()
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
} catch {}
|
|
2170
|
+
}
|
|
1790
2171
|
const geminiHome = resolveGeminiHome2();
|
|
1791
2172
|
const hasAgyDir = import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity")) || import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity-cli"));
|
|
1792
2173
|
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
1793
|
-
const isAvailable = hasAgyDir || hasApiKey;
|
|
2174
|
+
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
1794
2175
|
if (!isAvailable) {
|
|
1795
2176
|
return {
|
|
1796
2177
|
runtimeId: "agy",
|
|
1797
2178
|
provider: "Google Antigravity",
|
|
1798
2179
|
status: "unauthorized",
|
|
1799
|
-
message: "
|
|
2180
|
+
message: "未检测到 Antigravity 登录凭据",
|
|
1800
2181
|
updatedAt: Date.now()
|
|
1801
2182
|
};
|
|
1802
2183
|
}
|
|
@@ -1804,21 +2185,41 @@ async function probeAgyQuota(options) {
|
|
|
1804
2185
|
runtimeId: "agy",
|
|
1805
2186
|
provider: "Google Antigravity",
|
|
1806
2187
|
account: {
|
|
1807
|
-
|
|
2188
|
+
email: acc.email,
|
|
2189
|
+
name: acc.name || "Google Developer",
|
|
2190
|
+
plan: "Google AI Pro",
|
|
1808
2191
|
type: "gemini"
|
|
1809
2192
|
},
|
|
1810
2193
|
primaryWindow: {
|
|
1811
2194
|
label: "5-Hour limit",
|
|
2195
|
+
group: "Gemini Models",
|
|
1812
2196
|
percentLeft: 100,
|
|
1813
2197
|
usedPercent: 0,
|
|
1814
2198
|
windowDurationMins: 300
|
|
1815
2199
|
},
|
|
1816
2200
|
secondaryWindow: {
|
|
1817
2201
|
label: "Weekly limit",
|
|
2202
|
+
group: "Gemini Models",
|
|
1818
2203
|
percentLeft: 100,
|
|
1819
2204
|
usedPercent: 0,
|
|
1820
2205
|
windowDurationMins: 10080
|
|
1821
2206
|
},
|
|
2207
|
+
extraWindows: [
|
|
2208
|
+
{
|
|
2209
|
+
label: "5-Hour limit",
|
|
2210
|
+
group: "Claude and GPT models",
|
|
2211
|
+
percentLeft: 100,
|
|
2212
|
+
usedPercent: 0,
|
|
2213
|
+
windowDurationMins: 300
|
|
2214
|
+
},
|
|
2215
|
+
{
|
|
2216
|
+
label: "Weekly limit",
|
|
2217
|
+
group: "Claude and GPT models",
|
|
2218
|
+
percentLeft: 100,
|
|
2219
|
+
usedPercent: 0,
|
|
2220
|
+
windowDurationMins: 10080
|
|
2221
|
+
}
|
|
2222
|
+
],
|
|
1822
2223
|
credits: {
|
|
1823
2224
|
unlimited: true,
|
|
1824
2225
|
balance: "unlimited"
|
|
@@ -1879,7 +2280,7 @@ function getAcpRuntimeAdapter(runtimeId) {
|
|
|
1879
2280
|
}
|
|
1880
2281
|
|
|
1881
2282
|
// src/process/process-manager.ts
|
|
1882
|
-
var
|
|
2283
|
+
var import_node_child_process6 = require("node:child_process");
|
|
1883
2284
|
var active = new Map;
|
|
1884
2285
|
var ACP_EARLY_EXIT_WINDOW_MS = 3000;
|
|
1885
2286
|
var ACP_EARLY_EXIT_STDERR_TAIL_LINES = 20;
|
|
@@ -1891,7 +2292,7 @@ function killProcessTree(pid) {
|
|
|
1891
2292
|
if (process.platform !== "win32")
|
|
1892
2293
|
return;
|
|
1893
2294
|
try {
|
|
1894
|
-
|
|
2295
|
+
import_node_child_process6.spawnSync("taskkill", ["/F", "/T", "/PID", String(pid)], {
|
|
1895
2296
|
windowsHide: true,
|
|
1896
2297
|
timeout: 8000
|
|
1897
2298
|
});
|
|
@@ -1934,7 +2335,7 @@ function spawnAcpProcess(options) {
|
|
|
1934
2335
|
} else {
|
|
1935
2336
|
delete env.NO_BROWSER;
|
|
1936
2337
|
}
|
|
1937
|
-
const child =
|
|
2338
|
+
const child = import_node_child_process6.spawn(file, options.runtime.args, {
|
|
1938
2339
|
cwd: options.cwd,
|
|
1939
2340
|
env,
|
|
1940
2341
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -2654,7 +3055,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
2654
3055
|
}
|
|
2655
3056
|
|
|
2656
3057
|
// src/client/acp-terminal.ts
|
|
2657
|
-
var
|
|
3058
|
+
var import_node_child_process7 = require("node:child_process");
|
|
2658
3059
|
var import_node_crypto = require("node:crypto");
|
|
2659
3060
|
|
|
2660
3061
|
// src/transport/terminal-output-buffer.ts
|
|
@@ -2707,7 +3108,7 @@ class AcpTerminalManager {
|
|
|
2707
3108
|
throw new Error("terminal/create 需要 command");
|
|
2708
3109
|
const cwd = resolveCwd(params.cwd, params.workspaceRoot);
|
|
2709
3110
|
const outputByteLimit = typeof params.outputByteLimit === "number" && params.outputByteLimit > 0 ? params.outputByteLimit : DEFAULT_OUTPUT_BYTE_LIMIT;
|
|
2710
|
-
const child =
|
|
3111
|
+
const child = import_node_child_process7.spawn(command, params.args ?? [], {
|
|
2711
3112
|
cwd,
|
|
2712
3113
|
env: buildEnv(params.env),
|
|
2713
3114
|
windowsHide: true,
|
|
@@ -2803,7 +3204,7 @@ class AcpTerminalManager {
|
|
|
2803
3204
|
return;
|
|
2804
3205
|
if (process.platform === "win32") {
|
|
2805
3206
|
try {
|
|
2806
|
-
|
|
3207
|
+
import_node_child_process7.spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
2807
3208
|
windowsHide: true,
|
|
2808
3209
|
stdio: "ignore"
|
|
2809
3210
|
});
|