@yitom/acp-client 0.1.5 → 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 +682 -18
- package/dist/index.js +688 -47
- package/dist/runtimes/agy/quota.d.ts +8 -0
- package/dist/runtimes/opencode/quota.d.ts +1 -1
- package/dist/sidecar.cjs +656 -18
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
1
4
|
// src/contracts/index.ts
|
|
2
5
|
function isCancelled(error) {
|
|
3
6
|
return error.code === "CANCELLED";
|
|
@@ -159,7 +162,7 @@ function findBuiltinAcpRuntime(id) {
|
|
|
159
162
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
160
163
|
}
|
|
161
164
|
// src/version.ts
|
|
162
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
165
|
+
var ACP_CLIENT_VERSION = "0.1.7";
|
|
163
166
|
// src/session/available-commands.ts
|
|
164
167
|
function normalizeCommand(raw) {
|
|
165
168
|
if (!raw || typeof raw !== "object")
|
|
@@ -411,6 +414,8 @@ import {
|
|
|
411
414
|
// src/runtimes/codex/quota.ts
|
|
412
415
|
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
413
416
|
import { join as join2 } from "node:path";
|
|
417
|
+
import { spawn } from "node:child_process";
|
|
418
|
+
import readline from "node:readline";
|
|
414
419
|
|
|
415
420
|
// src/runtimes/codex/codex-auth-preflight.ts
|
|
416
421
|
import { existsSync } from "node:fs";
|
|
@@ -460,6 +465,102 @@ function decodeJwtPayload(token) {
|
|
|
460
465
|
return null;
|
|
461
466
|
}
|
|
462
467
|
}
|
|
468
|
+
var cachedDynamicResult = null;
|
|
469
|
+
async function queryCodexAppServer(timeoutMs = 1e4) {
|
|
470
|
+
if (cachedDynamicResult && Date.now() - cachedDynamicResult.time < 120000) {
|
|
471
|
+
return cachedDynamicResult.res;
|
|
472
|
+
}
|
|
473
|
+
return new Promise((resolve) => {
|
|
474
|
+
let timer = null;
|
|
475
|
+
let proc = null;
|
|
476
|
+
let finished = false;
|
|
477
|
+
const cleanup = (res) => {
|
|
478
|
+
if (finished)
|
|
479
|
+
return;
|
|
480
|
+
finished = true;
|
|
481
|
+
if (timer)
|
|
482
|
+
clearTimeout(timer);
|
|
483
|
+
if (proc) {
|
|
484
|
+
try {
|
|
485
|
+
proc.kill();
|
|
486
|
+
} catch {}
|
|
487
|
+
}
|
|
488
|
+
if (res) {
|
|
489
|
+
cachedDynamicResult = { res, time: Date.now() };
|
|
490
|
+
}
|
|
491
|
+
resolve(res);
|
|
492
|
+
};
|
|
493
|
+
timer = setTimeout(() => cleanup(null), timeoutMs);
|
|
494
|
+
try {
|
|
495
|
+
const cmd = process.platform === "win32" ? "codex" : existsSync2("/mnt/c/Users") ? "codex.exe" : "codex";
|
|
496
|
+
proc = spawn(cmd, ["app-server"], {
|
|
497
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
498
|
+
shell: process.platform === "win32",
|
|
499
|
+
windowsHide: true
|
|
500
|
+
});
|
|
501
|
+
if (!proc.stdin || !proc.stdout) {
|
|
502
|
+
return cleanup(null);
|
|
503
|
+
}
|
|
504
|
+
const rl = readline.createInterface({ input: proc.stdout });
|
|
505
|
+
let reqSeq = 1;
|
|
506
|
+
const pending = new Map;
|
|
507
|
+
const result = {};
|
|
508
|
+
rl.on("line", (line) => {
|
|
509
|
+
try {
|
|
510
|
+
const data = JSON.parse(line.trim());
|
|
511
|
+
if (data && typeof data.id === "number" && pending.has(data.id)) {
|
|
512
|
+
const cb = pending.get(data.id);
|
|
513
|
+
pending.delete(data.id);
|
|
514
|
+
cb(data.result);
|
|
515
|
+
}
|
|
516
|
+
} catch {}
|
|
517
|
+
});
|
|
518
|
+
proc.on("error", () => cleanup(null));
|
|
519
|
+
proc.on("exit", () => cleanup(Object.keys(result).length > 0 ? result : null));
|
|
520
|
+
const send = (method, params) => {
|
|
521
|
+
const id = reqSeq++;
|
|
522
|
+
const msg = JSON.stringify({ jsonrpc: "2.0", id, method, params }) + `
|
|
523
|
+
`;
|
|
524
|
+
proc.stdin.write(msg);
|
|
525
|
+
return new Promise((res) => {
|
|
526
|
+
pending.set(id, res);
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
(async () => {
|
|
530
|
+
try {
|
|
531
|
+
await send("initialize", {
|
|
532
|
+
clientInfo: { name: "acp-client", version: "0.1.6" }
|
|
533
|
+
});
|
|
534
|
+
const acc = await send("account/read", { refreshToken: false });
|
|
535
|
+
if (acc?.account) {
|
|
536
|
+
result.account = acc.account;
|
|
537
|
+
}
|
|
538
|
+
const limits = await send("account/rateLimits/read");
|
|
539
|
+
if (limits?.rateLimits) {
|
|
540
|
+
result.rateLimits = limits.rateLimits;
|
|
541
|
+
}
|
|
542
|
+
cleanup(result);
|
|
543
|
+
} catch {
|
|
544
|
+
cleanup(null);
|
|
545
|
+
}
|
|
546
|
+
})();
|
|
547
|
+
} catch {
|
|
548
|
+
cleanup(null);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
function formatEpochTime(epochSeconds) {
|
|
553
|
+
if (!epochSeconds)
|
|
554
|
+
return;
|
|
555
|
+
try {
|
|
556
|
+
const d = new Date(epochSeconds * 1000);
|
|
557
|
+
const hours = String(d.getHours()).padStart(2, "0");
|
|
558
|
+
const mins = String(d.getMinutes()).padStart(2, "0");
|
|
559
|
+
return `${hours}:${mins}`;
|
|
560
|
+
} catch {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
463
564
|
async function probeCodexQuota(options) {
|
|
464
565
|
const codexHome = resolveCodexHome();
|
|
465
566
|
const authPath = join2(codexHome, "auth.json");
|
|
@@ -493,6 +594,14 @@ async function probeCodexQuota(options) {
|
|
|
493
594
|
isLoggedIn = true;
|
|
494
595
|
accountPlan = "API Key (Env)";
|
|
495
596
|
}
|
|
597
|
+
const dynamic = await queryCodexAppServer(1e4);
|
|
598
|
+
if (dynamic) {
|
|
599
|
+
isLoggedIn = true;
|
|
600
|
+
if (dynamic.account?.email)
|
|
601
|
+
accountEmail = dynamic.account.email;
|
|
602
|
+
if (dynamic.account?.planType)
|
|
603
|
+
accountPlan = `ChatGPT ${dynamic.account.planType}`;
|
|
604
|
+
}
|
|
496
605
|
if (!isLoggedIn) {
|
|
497
606
|
return {
|
|
498
607
|
runtimeId: "codex-acp",
|
|
@@ -502,14 +611,49 @@ async function probeCodexQuota(options) {
|
|
|
502
611
|
updatedAt: Date.now()
|
|
503
612
|
};
|
|
504
613
|
}
|
|
614
|
+
let primaryWindow;
|
|
615
|
+
let secondaryWindow;
|
|
616
|
+
let credits;
|
|
617
|
+
if (dynamic?.rateLimits) {
|
|
618
|
+
const rl = dynamic.rateLimits;
|
|
619
|
+
if (rl.primary) {
|
|
620
|
+
const used = rl.primary.usedPercent ?? 0;
|
|
621
|
+
primaryWindow = {
|
|
622
|
+
label: "5h limit",
|
|
623
|
+
percentLeft: Math.max(0, Math.min(100, Math.round(100 - used))),
|
|
624
|
+
usedPercent: used,
|
|
625
|
+
windowDurationMins: rl.primary.windowDurationMins || 300,
|
|
626
|
+
resetsAt: formatEpochTime(rl.primary.resetsAt) || (rl.primary.resetsAt ? String(rl.primary.resetsAt) : undefined)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
if (rl.secondary) {
|
|
630
|
+
const used = rl.secondary.usedPercent ?? 0;
|
|
631
|
+
secondaryWindow = {
|
|
632
|
+
label: "Weekly limit",
|
|
633
|
+
percentLeft: Math.max(0, Math.min(100, Math.round(100 - used))),
|
|
634
|
+
usedPercent: used,
|
|
635
|
+
windowDurationMins: rl.secondary.windowDurationMins || 10080,
|
|
636
|
+
resetsAt: formatEpochTime(rl.secondary.resetsAt) || (rl.secondary.resetsAt ? String(rl.secondary.resetsAt) : undefined)
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
if (rl.credits) {
|
|
640
|
+
credits = {
|
|
641
|
+
balance: rl.credits.balance,
|
|
642
|
+
unlimited: rl.credits.unlimited
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
505
646
|
return {
|
|
506
647
|
runtimeId: "codex-acp",
|
|
507
648
|
provider: "OpenAI / Codex",
|
|
508
649
|
account: {
|
|
509
650
|
email: accountEmail,
|
|
510
651
|
plan: accountPlan,
|
|
511
|
-
type: "chatgpt"
|
|
652
|
+
type: dynamic?.account?.type || "chatgpt"
|
|
512
653
|
},
|
|
654
|
+
primaryWindow,
|
|
655
|
+
secondaryWindow,
|
|
656
|
+
credits,
|
|
513
657
|
status: "ok",
|
|
514
658
|
updatedAt: Date.now()
|
|
515
659
|
};
|
|
@@ -685,6 +829,30 @@ var codexAdapter = {
|
|
|
685
829
|
import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
|
|
686
830
|
import { homedir as homedir3 } from "node:os";
|
|
687
831
|
import { join as join6 } from "node:path";
|
|
832
|
+
import { execFile } from "node:child_process";
|
|
833
|
+
var cachedClaudeAuth = null;
|
|
834
|
+
async function queryClaudeAuthStatus(timeoutMs = 1200) {
|
|
835
|
+
if (cachedClaudeAuth && Date.now() - cachedClaudeAuth.time < 30000) {
|
|
836
|
+
return cachedClaudeAuth.res;
|
|
837
|
+
}
|
|
838
|
+
return new Promise((resolve) => {
|
|
839
|
+
try {
|
|
840
|
+
execFile("claude", ["auth", "status", "--json"], { timeout: timeoutMs, windowsHide: true, shell: process.platform === "win32" }, (err, stdout) => {
|
|
841
|
+
if (!stdout)
|
|
842
|
+
return resolve(null);
|
|
843
|
+
try {
|
|
844
|
+
const data = JSON.parse(stdout.trim());
|
|
845
|
+
cachedClaudeAuth = { res: data, time: Date.now() };
|
|
846
|
+
resolve(data);
|
|
847
|
+
} catch {
|
|
848
|
+
resolve(null);
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
} catch {
|
|
852
|
+
resolve(null);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
}
|
|
688
856
|
async function probeClaudeQuota(options) {
|
|
689
857
|
const claudeHome = resolveClaudeHome();
|
|
690
858
|
const claudeJsonPath = join6(homedir3(), ".claude.json");
|
|
@@ -717,6 +885,17 @@ async function probeClaudeQuota(options) {
|
|
|
717
885
|
isLoggedIn = true;
|
|
718
886
|
plan = "API Key (Env)";
|
|
719
887
|
}
|
|
888
|
+
const dynamic = await queryClaudeAuthStatus(1200);
|
|
889
|
+
if (dynamic) {
|
|
890
|
+
if (dynamic.loggedIn)
|
|
891
|
+
isLoggedIn = true;
|
|
892
|
+
if (dynamic.email)
|
|
893
|
+
accountEmail = dynamic.email;
|
|
894
|
+
if (dynamic.subscriptionType)
|
|
895
|
+
plan = dynamic.subscriptionType;
|
|
896
|
+
else if (dynamic.plan)
|
|
897
|
+
plan = dynamic.plan;
|
|
898
|
+
}
|
|
720
899
|
if (isBanned) {
|
|
721
900
|
return {
|
|
722
901
|
runtimeId: "claude",
|
|
@@ -740,7 +919,8 @@ async function probeClaudeQuota(options) {
|
|
|
740
919
|
provider: "Anthropic / Claude Code",
|
|
741
920
|
account: {
|
|
742
921
|
email: accountEmail,
|
|
743
|
-
plan
|
|
922
|
+
plan,
|
|
923
|
+
type: dynamic?.authMethod || "oauth"
|
|
744
924
|
},
|
|
745
925
|
status: "ok",
|
|
746
926
|
updatedAt: Date.now()
|
|
@@ -846,6 +1026,9 @@ var copilotAdapter = {
|
|
|
846
1026
|
|
|
847
1027
|
// src/runtimes/opencode/quota.ts
|
|
848
1028
|
import { existsSync as existsSync8, readFileSync as readFileSync4 } from "node:fs";
|
|
1029
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1030
|
+
import * as os from "node:os";
|
|
1031
|
+
import * as path from "node:path";
|
|
849
1032
|
function resolveOpencodeAuthPath() {
|
|
850
1033
|
const candidates = resolveOpencodeAuthCandidates();
|
|
851
1034
|
for (const c of candidates) {
|
|
@@ -854,10 +1037,204 @@ function resolveOpencodeAuthPath() {
|
|
|
854
1037
|
}
|
|
855
1038
|
return candidates[0] ?? null;
|
|
856
1039
|
}
|
|
1040
|
+
var cachedStats = null;
|
|
1041
|
+
async function queryOpencodeStats(timeoutMs = 1200) {
|
|
1042
|
+
if (cachedStats && Date.now() - cachedStats.time < 30000) {
|
|
1043
|
+
return cachedStats.res;
|
|
1044
|
+
}
|
|
1045
|
+
return new Promise((resolve) => {
|
|
1046
|
+
try {
|
|
1047
|
+
execFile2("opencode", ["stats", "--standalone", "--cost", "--json"], { timeout: timeoutMs, windowsHide: true }, (err, stdout) => {
|
|
1048
|
+
if (!stdout)
|
|
1049
|
+
return resolve(null);
|
|
1050
|
+
try {
|
|
1051
|
+
const data = JSON.parse(stdout.trim());
|
|
1052
|
+
cachedStats = { res: data, time: Date.now() };
|
|
1053
|
+
resolve(data);
|
|
1054
|
+
} catch {
|
|
1055
|
+
resolve(null);
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
} catch {
|
|
1059
|
+
resolve(null);
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
async function queryOpencodeAuthList(timeoutMs = 1200) {
|
|
1064
|
+
return new Promise((resolve) => {
|
|
1065
|
+
try {
|
|
1066
|
+
execFile2("opencode", ["auth", "list"], { timeout: timeoutMs, windowsHide: true }, (err, stdout) => {
|
|
1067
|
+
if (!stdout)
|
|
1068
|
+
return resolve([]);
|
|
1069
|
+
const lines = stdout.split(`
|
|
1070
|
+
`).map((l) => l.trim()).filter((l) => l.includes("stored"));
|
|
1071
|
+
resolve(lines);
|
|
1072
|
+
});
|
|
1073
|
+
} catch {
|
|
1074
|
+
resolve([]);
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
function readLocalOpencodeCredentials() {
|
|
1079
|
+
const home = os.homedir();
|
|
1080
|
+
const dbPaths = [
|
|
1081
|
+
path.join(home, ".local", "share", "opencode", "opencode.db"),
|
|
1082
|
+
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "opencode", "opencode.db") : null,
|
|
1083
|
+
path.join(home, ".config", "opencode", "opencode.db")
|
|
1084
|
+
].filter(Boolean);
|
|
1085
|
+
for (const dbPath of dbPaths) {
|
|
1086
|
+
if (!existsSync8(dbPath))
|
|
1087
|
+
continue;
|
|
1088
|
+
try {
|
|
1089
|
+
let rows = [];
|
|
1090
|
+
if (typeof process.versions?.bun !== "undefined") {
|
|
1091
|
+
const { Database } = __require("bun:sqlite");
|
|
1092
|
+
const db = new Database(dbPath, { readonly: true });
|
|
1093
|
+
rows = db.query("SELECT integration_id, value FROM credential").all();
|
|
1094
|
+
db.close();
|
|
1095
|
+
} else {
|
|
1096
|
+
const { DatabaseSync } = __require("node:sqlite");
|
|
1097
|
+
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
1098
|
+
rows = db.prepare("SELECT integration_id, value FROM credential").all();
|
|
1099
|
+
db.close();
|
|
1100
|
+
}
|
|
1101
|
+
const opencodeCred = rows.find((r) => r.integration_id === "opencode");
|
|
1102
|
+
if (opencodeCred?.value) {
|
|
1103
|
+
const parsed = JSON.parse(opencodeCred.value);
|
|
1104
|
+
const meta = parsed.metadata || {};
|
|
1105
|
+
return {
|
|
1106
|
+
email: meta.email || undefined,
|
|
1107
|
+
name: meta.email ? meta.email.split("@")[0] : meta.orgName || undefined,
|
|
1108
|
+
token: parsed.access || undefined,
|
|
1109
|
+
orgId: meta.orgID || undefined,
|
|
1110
|
+
accountId: meta.accountID || undefined
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
} catch {
|
|
1114
|
+
try {
|
|
1115
|
+
const buf = readFileSync4(dbPath, "utf8");
|
|
1116
|
+
const emailMatch = buf.match(/"email"\s*:\s*"([^"]+)"/);
|
|
1117
|
+
const tokenMatch = buf.match(/"access"\s*:\s*"(st_[a-zA-Z0-9_\\-]+)"/);
|
|
1118
|
+
const orgMatch = buf.match(/"orgID"\s*:\s*"(wrk_[a-zA-Z0-9_\\-]+)"/);
|
|
1119
|
+
const accMatch = buf.match(/"accountID"\s*:\s*"(acc_[a-zA-Z0-9_\\-]+)"/);
|
|
1120
|
+
if (emailMatch || tokenMatch) {
|
|
1121
|
+
return {
|
|
1122
|
+
email: emailMatch?.[1],
|
|
1123
|
+
name: emailMatch?.[1]?.split("@")[0],
|
|
1124
|
+
token: tokenMatch?.[1],
|
|
1125
|
+
orgId: orgMatch?.[1],
|
|
1126
|
+
accountId: accMatch?.[1]
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
} catch {}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return {};
|
|
1133
|
+
}
|
|
1134
|
+
async function probeOpencodeGoOnlineQuota(creds, runtimeId = "opencode") {
|
|
1135
|
+
if (!creds.token || !creds.orgId)
|
|
1136
|
+
return null;
|
|
1137
|
+
try {
|
|
1138
|
+
const res = await fetch("https://opencode.ai/console/api/go/status", {
|
|
1139
|
+
headers: {
|
|
1140
|
+
Authorization: `Bearer ${creds.token}`,
|
|
1141
|
+
"x-opencode-org-id": creds.orgId,
|
|
1142
|
+
"x-opencode-account-id": creds.accountId || ""
|
|
1143
|
+
},
|
|
1144
|
+
signal: AbortSignal.timeout(3500)
|
|
1145
|
+
});
|
|
1146
|
+
if (!res.ok)
|
|
1147
|
+
return null;
|
|
1148
|
+
const data = await res.json();
|
|
1149
|
+
const meters = data?.access?.meters;
|
|
1150
|
+
if (!meters)
|
|
1151
|
+
return null;
|
|
1152
|
+
const formatReset = (isoStr) => {
|
|
1153
|
+
if (!isoStr)
|
|
1154
|
+
return;
|
|
1155
|
+
const diffMs = new Date(isoStr).getTime() - Date.now();
|
|
1156
|
+
if (diffMs <= 0)
|
|
1157
|
+
return "已重置";
|
|
1158
|
+
const totalMins = Math.floor(diffMs / 60000);
|
|
1159
|
+
const hours = Math.floor(totalMins / 60);
|
|
1160
|
+
const days = Math.floor(hours / 24);
|
|
1161
|
+
if (days > 0) {
|
|
1162
|
+
const remH = hours % 24;
|
|
1163
|
+
return `Resets in ${days}d ${remH}h`;
|
|
1164
|
+
}
|
|
1165
|
+
const remM = totalMins % 60;
|
|
1166
|
+
return `Resets in ${hours}h ${remM}m`;
|
|
1167
|
+
};
|
|
1168
|
+
const calcWindow = (m, label, durMins) => {
|
|
1169
|
+
if (!m || !m.limitMicroCents)
|
|
1170
|
+
return;
|
|
1171
|
+
const limit = Number(m.limitMicroCents);
|
|
1172
|
+
const used = Number(m.usedMicroCents || 0);
|
|
1173
|
+
const usedPercent = limit > 0 ? Math.round(used / limit * 100) : 0;
|
|
1174
|
+
const percentLeft = Math.max(0, 100 - usedPercent);
|
|
1175
|
+
return {
|
|
1176
|
+
label,
|
|
1177
|
+
usedPercent,
|
|
1178
|
+
percentLeft,
|
|
1179
|
+
windowDurationMins: durMins,
|
|
1180
|
+
resetsAt: formatReset(m.resetsAt)
|
|
1181
|
+
};
|
|
1182
|
+
};
|
|
1183
|
+
const rolling = calcWindow(meters.fiveHour, "Rolling", 300);
|
|
1184
|
+
const weekly = calcWindow(meters.week, "Weekly", 10080);
|
|
1185
|
+
const monthly = calcWindow(meters.month, "Monthly", 43200);
|
|
1186
|
+
let creditBalance = "$0.00";
|
|
1187
|
+
try {
|
|
1188
|
+
const bRes = await fetch("https://opencode.ai/console/api/billing/status", {
|
|
1189
|
+
headers: {
|
|
1190
|
+
Authorization: `Bearer ${creds.token}`,
|
|
1191
|
+
"x-opencode-org-id": creds.orgId,
|
|
1192
|
+
"x-opencode-account-id": creds.accountId || ""
|
|
1193
|
+
},
|
|
1194
|
+
signal: AbortSignal.timeout(2000)
|
|
1195
|
+
});
|
|
1196
|
+
if (bRes.ok) {
|
|
1197
|
+
const bData = await bRes.json();
|
|
1198
|
+
const availMicro = Number(bData.availableMicroCents || 0);
|
|
1199
|
+
creditBalance = `$${(availMicro / 1e8).toFixed(2)}`;
|
|
1200
|
+
}
|
|
1201
|
+
} catch {}
|
|
1202
|
+
const quota = {
|
|
1203
|
+
runtimeId,
|
|
1204
|
+
provider: "OpenCode",
|
|
1205
|
+
account: {
|
|
1206
|
+
email: creds.email,
|
|
1207
|
+
name: creds.name || "OpenCode User",
|
|
1208
|
+
plan: "OpenCode Go",
|
|
1209
|
+
type: "opencode"
|
|
1210
|
+
},
|
|
1211
|
+
primaryWindow: rolling,
|
|
1212
|
+
secondaryWindow: weekly,
|
|
1213
|
+
extraWindows: monthly ? [monthly] : undefined,
|
|
1214
|
+
credits: {
|
|
1215
|
+
balance: creditBalance,
|
|
1216
|
+
currency: "USD",
|
|
1217
|
+
unlimited: false
|
|
1218
|
+
},
|
|
1219
|
+
status: "ok",
|
|
1220
|
+
updatedAt: Date.now()
|
|
1221
|
+
};
|
|
1222
|
+
return quota;
|
|
1223
|
+
} catch {
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
857
1227
|
async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
1228
|
+
const dbCreds = readLocalOpencodeCredentials();
|
|
1229
|
+
if (dbCreds.token) {
|
|
1230
|
+
const goQuota = await probeOpencodeGoOnlineQuota(dbCreds, runtimeId);
|
|
1231
|
+
if (goQuota)
|
|
1232
|
+
return goQuota;
|
|
1233
|
+
}
|
|
858
1234
|
const authPath = resolveOpencodeAuthPath();
|
|
859
|
-
let isLoggedIn =
|
|
860
|
-
let accountEmail;
|
|
1235
|
+
let isLoggedIn = Boolean(dbCreds.token || dbCreds.email);
|
|
1236
|
+
let accountEmail = dbCreds.email;
|
|
1237
|
+
let accountName = dbCreds.name;
|
|
861
1238
|
let plan = "OpenCode Community";
|
|
862
1239
|
if (authPath && existsSync8(authPath)) {
|
|
863
1240
|
try {
|
|
@@ -874,22 +1251,47 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
874
1251
|
}
|
|
875
1252
|
} catch {}
|
|
876
1253
|
}
|
|
1254
|
+
const [stats, authList] = await Promise.all([
|
|
1255
|
+
queryOpencodeStats(1200),
|
|
1256
|
+
queryOpencodeAuthList(1200)
|
|
1257
|
+
]);
|
|
1258
|
+
if (authList.length > 0) {
|
|
1259
|
+
isLoggedIn = true;
|
|
1260
|
+
const providers = authList.map((l) => l.split(/\s{2,}/)[0]).filter(Boolean);
|
|
1261
|
+
if (providers.some((p) => p.toLowerCase().includes("go"))) {
|
|
1262
|
+
plan = "OpenCode Go";
|
|
1263
|
+
} else if (providers.length > 0) {
|
|
1264
|
+
plan = `OpenCode (${providers.join(", ")})`;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (process.env.OPENCODE_API_KEY || process.env.OPENAI_API_KEY) {
|
|
1268
|
+
isLoggedIn = true;
|
|
1269
|
+
}
|
|
877
1270
|
if (!isLoggedIn) {
|
|
878
1271
|
return {
|
|
879
1272
|
runtimeId,
|
|
880
1273
|
provider: "OpenCode",
|
|
881
1274
|
status: "unauthorized",
|
|
882
|
-
message: "
|
|
1275
|
+
message: "未登录 OpenCode 或未配置 Provider (No stored credentials)",
|
|
883
1276
|
updatedAt: Date.now()
|
|
884
1277
|
};
|
|
885
1278
|
}
|
|
1279
|
+
let credits;
|
|
1280
|
+
if (stats && typeof stats.cost === "number") {
|
|
1281
|
+
credits = {
|
|
1282
|
+
balance: stats.cost > 0 ? `$${stats.cost.toFixed(2)} spent` : "$0.00"
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
886
1285
|
return {
|
|
887
1286
|
runtimeId,
|
|
888
1287
|
provider: "OpenCode",
|
|
889
1288
|
account: {
|
|
890
1289
|
email: accountEmail,
|
|
891
|
-
|
|
1290
|
+
name: accountName,
|
|
1291
|
+
plan,
|
|
1292
|
+
type: "provider_oauth"
|
|
892
1293
|
},
|
|
1294
|
+
credits,
|
|
893
1295
|
status: "ok",
|
|
894
1296
|
updatedAt: Date.now()
|
|
895
1297
|
};
|
|
@@ -897,15 +1299,15 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
897
1299
|
|
|
898
1300
|
// src/runtimes/opencode/index.ts
|
|
899
1301
|
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
|
|
900
|
-
import { homedir as
|
|
901
|
-
import { dirname, join as
|
|
1302
|
+
import { homedir as homedir8 } from "node:os";
|
|
1303
|
+
import { dirname, join as join11 } from "node:path";
|
|
902
1304
|
function pickEnv(env, key) {
|
|
903
1305
|
return env?.[key]?.trim() ?? "";
|
|
904
1306
|
}
|
|
905
1307
|
function resolveOpencodeAuthCandidates(overrides) {
|
|
906
1308
|
const platform = overrides?.platform ?? process.platform;
|
|
907
1309
|
const env = overrides?.env ?? process.env;
|
|
908
|
-
const home = overrides?.home ??
|
|
1310
|
+
const home = overrides?.home ?? homedir8();
|
|
909
1311
|
const seen = new Set;
|
|
910
1312
|
const out = [];
|
|
911
1313
|
const push = (p) => {
|
|
@@ -916,21 +1318,21 @@ function resolveOpencodeAuthCandidates(overrides) {
|
|
|
916
1318
|
};
|
|
917
1319
|
const xdg = pickEnv(env, "XDG_DATA_HOME");
|
|
918
1320
|
if (xdg)
|
|
919
|
-
push(
|
|
1321
|
+
push(join11(xdg, "opencode", "auth.json"));
|
|
920
1322
|
if (platform === "win32") {
|
|
921
|
-
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ?
|
|
1323
|
+
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? join11(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
|
|
922
1324
|
if (localAppData)
|
|
923
|
-
push(
|
|
1325
|
+
push(join11(localAppData, "opencode", "auth.json"));
|
|
924
1326
|
const userProfile = pickEnv(env, "USERPROFILE") || home;
|
|
925
1327
|
if (userProfile)
|
|
926
|
-
push(
|
|
1328
|
+
push(join11(userProfile, ".local", "share", "opencode", "auth.json"));
|
|
927
1329
|
} else if (home) {
|
|
928
|
-
push(
|
|
1330
|
+
push(join11(home, ".local", "share", "opencode", "auth.json"));
|
|
929
1331
|
}
|
|
930
1332
|
return out;
|
|
931
1333
|
}
|
|
932
1334
|
function resolveOpencodeAuthFile() {
|
|
933
|
-
return resolveOpencodeAuthCandidates()[0] ??
|
|
1335
|
+
return resolveOpencodeAuthCandidates()[0] ?? join11(homedir8(), ".local", "share", "opencode", "auth.json");
|
|
934
1336
|
}
|
|
935
1337
|
function isValidOpencodeAuthFile(authFile) {
|
|
936
1338
|
try {
|
|
@@ -1027,14 +1429,14 @@ async function probeCursorQuota() {
|
|
|
1027
1429
|
// src/runtimes/cursor/index.ts
|
|
1028
1430
|
import { spawnSync } from "node:child_process";
|
|
1029
1431
|
import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
|
|
1030
|
-
import { homedir as
|
|
1031
|
-
import { delimiter, dirname as dirname2, join as
|
|
1432
|
+
import { homedir as homedir9 } from "node:os";
|
|
1433
|
+
import { delimiter, dirname as dirname2, join as join12 } from "node:path";
|
|
1032
1434
|
function cursorLocalAppData(env) {
|
|
1033
1435
|
const local = env.LOCALAPPDATA?.trim();
|
|
1034
1436
|
if (local)
|
|
1035
1437
|
return local;
|
|
1036
1438
|
const profile = env.USERPROFILE?.trim();
|
|
1037
|
-
return profile ?
|
|
1439
|
+
return profile ? join12(profile, "AppData", "Local") : "";
|
|
1038
1440
|
}
|
|
1039
1441
|
function isOnPath(command, env, platform) {
|
|
1040
1442
|
const pathValue = env.PATH ?? env.Path ?? "";
|
|
@@ -1046,7 +1448,7 @@ function isOnPath(command, env, platform) {
|
|
|
1046
1448
|
if (!trimmed)
|
|
1047
1449
|
continue;
|
|
1048
1450
|
try {
|
|
1049
|
-
if (existsSync10(
|
|
1451
|
+
if (existsSync10(join12(trimmed, command)))
|
|
1050
1452
|
return true;
|
|
1051
1453
|
} catch {}
|
|
1052
1454
|
}
|
|
@@ -1055,15 +1457,15 @@ function isOnPath(command, env, platform) {
|
|
|
1055
1457
|
function resolveDirectCursorCommand(platform, env, home) {
|
|
1056
1458
|
if (platform === "win32") {
|
|
1057
1459
|
const localAppData = cursorLocalAppData(env);
|
|
1058
|
-
return localAppData ?
|
|
1460
|
+
return localAppData ? join12(localAppData, "cursor-agent", "agent.cmd") : "";
|
|
1059
1461
|
}
|
|
1060
|
-
return home ?
|
|
1462
|
+
return home ? join12(home, ".local", "bin", "agent") : "";
|
|
1061
1463
|
}
|
|
1062
1464
|
function resolveCursorCommand(overrides) {
|
|
1063
1465
|
const args = ["acp"];
|
|
1064
1466
|
const platform = overrides?.platform ?? process.platform;
|
|
1065
1467
|
const env = overrides?.env ?? process.env;
|
|
1066
|
-
const home = overrides?.home ??
|
|
1468
|
+
const home = overrides?.home ?? homedir9();
|
|
1067
1469
|
if (platform === "win32") {
|
|
1068
1470
|
const directCmd = resolveDirectCursorCommand(platform, env, home);
|
|
1069
1471
|
if (directCmd && existsSync10(directCmd)) {
|
|
@@ -1081,7 +1483,7 @@ function resolveCursorSpawnCommand(overrides) {
|
|
|
1081
1483
|
const args = ["acp"];
|
|
1082
1484
|
const platform = overrides?.platform ?? process.platform;
|
|
1083
1485
|
const env = overrides?.env ?? process.env;
|
|
1084
|
-
const home = overrides?.home ??
|
|
1486
|
+
const home = overrides?.home ?? homedir9();
|
|
1085
1487
|
const binary = platform === "win32" ? "agent.cmd" : "agent";
|
|
1086
1488
|
const direct = resolveDirectCursorCommand(platform, env, home);
|
|
1087
1489
|
try {
|
|
@@ -1107,12 +1509,12 @@ function cursorRoamingAppData(env, home) {
|
|
|
1107
1509
|
if (roaming)
|
|
1108
1510
|
return roaming;
|
|
1109
1511
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
1110
|
-
return profile ?
|
|
1512
|
+
return profile ? join12(profile, "AppData", "Roaming") : "";
|
|
1111
1513
|
}
|
|
1112
1514
|
function resolveCursorAuthCandidates(overrides) {
|
|
1113
1515
|
const platform = overrides?.platform ?? process.platform;
|
|
1114
1516
|
const env = overrides?.env ?? process.env;
|
|
1115
|
-
const home = overrides?.home ??
|
|
1517
|
+
const home = overrides?.home ?? homedir9();
|
|
1116
1518
|
const seen = new Set;
|
|
1117
1519
|
const out = [];
|
|
1118
1520
|
const push = (p) => {
|
|
@@ -1123,16 +1525,16 @@ function resolveCursorAuthCandidates(overrides) {
|
|
|
1123
1525
|
};
|
|
1124
1526
|
const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
|
|
1125
1527
|
if (xdg)
|
|
1126
|
-
push(
|
|
1528
|
+
push(join12(xdg, "cursor", "auth.json"));
|
|
1127
1529
|
if (platform === "win32") {
|
|
1128
1530
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
1129
1531
|
if (profile)
|
|
1130
|
-
push(
|
|
1532
|
+
push(join12(profile, ".config", "cursor", "auth.json"));
|
|
1131
1533
|
const roaming = cursorRoamingAppData(env, home);
|
|
1132
1534
|
if (roaming)
|
|
1133
|
-
push(
|
|
1535
|
+
push(join12(roaming, "Cursor", "User", "globalStorage", "storage.json"));
|
|
1134
1536
|
} else if (home) {
|
|
1135
|
-
push(
|
|
1537
|
+
push(join12(home, ".config", "cursor", "auth.json"));
|
|
1136
1538
|
}
|
|
1137
1539
|
return out;
|
|
1138
1540
|
}
|
|
@@ -1181,7 +1583,7 @@ function isValidCursorCandidate(authFile) {
|
|
|
1181
1583
|
}
|
|
1182
1584
|
function probeCursorAuth(overrides) {
|
|
1183
1585
|
const env = overrides?.env ?? process.env;
|
|
1184
|
-
const home = overrides?.home ??
|
|
1586
|
+
const home = overrides?.home ?? homedir9();
|
|
1185
1587
|
const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
|
|
1186
1588
|
const candidates = resolveCursorAuthCandidates(overrides);
|
|
1187
1589
|
let firstExisting = null;
|
|
@@ -1201,7 +1603,7 @@ function probeCursorAuth(overrides) {
|
|
|
1201
1603
|
if (isValidCursorCandidate(candidate))
|
|
1202
1604
|
validFile = candidate;
|
|
1203
1605
|
}
|
|
1204
|
-
const fallback = home ?
|
|
1606
|
+
const fallback = home ? join12(home, ".config", "cursor", "auth.json") : "";
|
|
1205
1607
|
const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
|
|
1206
1608
|
const authDir = authFile ? dirname2(authFile) : "";
|
|
1207
1609
|
let hasCodexHome = false;
|
|
@@ -1341,23 +1743,242 @@ var deepseekAdapter = {
|
|
|
1341
1743
|
};
|
|
1342
1744
|
|
|
1343
1745
|
// src/runtimes/agy/quota.ts
|
|
1344
|
-
import { existsSync as existsSync11 } from "node:fs";
|
|
1345
|
-
import { join as
|
|
1746
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7, readdirSync, statSync } from "node:fs";
|
|
1747
|
+
import { join as join13 } from "node:path";
|
|
1748
|
+
import { execFileSync } from "node:child_process";
|
|
1749
|
+
import * as os2 from "node:os";
|
|
1346
1750
|
function resolveGeminiHome2() {
|
|
1347
1751
|
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
1348
|
-
return
|
|
1752
|
+
return join13(home, ".gemini");
|
|
1753
|
+
}
|
|
1754
|
+
function resolveAntigravityAccount() {
|
|
1755
|
+
if (process.env.GOOGLE_ACCOUNT?.trim()) {
|
|
1756
|
+
const email = process.env.GOOGLE_ACCOUNT.trim();
|
|
1757
|
+
return { email, name: email.split("@")[0] };
|
|
1758
|
+
}
|
|
1759
|
+
if (process.env.ANTIGRAVITY_ACCOUNT?.trim()) {
|
|
1760
|
+
const email = process.env.ANTIGRAVITY_ACCOUNT.trim();
|
|
1761
|
+
return { email, name: email.split("@")[0] };
|
|
1762
|
+
}
|
|
1763
|
+
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
1764
|
+
const candidates = [
|
|
1765
|
+
process.env.APPDATA ? join13(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
|
|
1766
|
+
join13(home, ".config", "Antigravity", "app_storage.json"),
|
|
1767
|
+
join13(home, "Library", "Application Support", "Antigravity", "app_storage.json")
|
|
1768
|
+
].filter(Boolean);
|
|
1769
|
+
for (const file of candidates) {
|
|
1770
|
+
try {
|
|
1771
|
+
if (existsSync11(file)) {
|
|
1772
|
+
const raw = readFileSync7(file, "utf8");
|
|
1773
|
+
const json = JSON.parse(raw);
|
|
1774
|
+
const username = json["jetski.onboarding.lastLoginUsername"];
|
|
1775
|
+
if (username && typeof username === "string" && username.trim()) {
|
|
1776
|
+
const u = username.trim();
|
|
1777
|
+
return {
|
|
1778
|
+
email: u,
|
|
1779
|
+
name: u.includes("@") ? u.split("@")[0] : u
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
} catch {}
|
|
1784
|
+
}
|
|
1785
|
+
const osUser = process.env.USERNAME || process.env.USER;
|
|
1786
|
+
if (osUser?.trim()) {
|
|
1787
|
+
return { name: osUser.trim() };
|
|
1788
|
+
}
|
|
1789
|
+
return {};
|
|
1790
|
+
}
|
|
1791
|
+
function resolveAntigravityLanguageServer() {
|
|
1792
|
+
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
1793
|
+
const appData = process.env.APPDATA || (process.platform === "win32" ? join13(home, "AppData", "Roaming") : "");
|
|
1794
|
+
const baseDirs = [
|
|
1795
|
+
appData ? join13(appData, "Antigravity IDE", "logs") : null,
|
|
1796
|
+
appData ? join13(appData, "Antigravity", "logs") : null,
|
|
1797
|
+
join13(home, ".config", "Antigravity IDE", "logs"),
|
|
1798
|
+
join13(home, ".config", "Antigravity", "logs"),
|
|
1799
|
+
join13(home, "Library", "Application Support", "Antigravity IDE", "logs"),
|
|
1800
|
+
join13(home, "Library", "Application Support", "Antigravity", "logs")
|
|
1801
|
+
].filter(Boolean);
|
|
1802
|
+
for (const base of baseDirs) {
|
|
1803
|
+
try {
|
|
1804
|
+
if (!existsSync11(base))
|
|
1805
|
+
continue;
|
|
1806
|
+
const sessionDirs = readdirSync(base).map((d) => {
|
|
1807
|
+
try {
|
|
1808
|
+
return { name: d, time: statSync(join13(base, d)).mtimeMs };
|
|
1809
|
+
} catch {
|
|
1810
|
+
return null;
|
|
1811
|
+
}
|
|
1812
|
+
}).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
|
|
1813
|
+
for (const s of sessionDirs) {
|
|
1814
|
+
const logFile = join13(base, s.name, "ls-main.log");
|
|
1815
|
+
if (existsSync11(logFile)) {
|
|
1816
|
+
const content = readFileSync7(logFile, "utf8");
|
|
1817
|
+
const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
1818
|
+
const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
|
|
1819
|
+
if (csrfMatch && portMatch) {
|
|
1820
|
+
return {
|
|
1821
|
+
port: parseInt(portMatch[1], 10),
|
|
1822
|
+
csrfToken: csrfMatch[1]
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
} catch {}
|
|
1828
|
+
}
|
|
1829
|
+
try {
|
|
1830
|
+
let out = "";
|
|
1831
|
+
if (process.platform === "win32") {
|
|
1832
|
+
out = execFileSync("powershell", [
|
|
1833
|
+
"-NoProfile",
|
|
1834
|
+
"-Command",
|
|
1835
|
+
`Get-CimInstance Win32_Process -Filter "Name like '%language_server%'" | Select-Object -ExpandProperty CommandLine`
|
|
1836
|
+
], { encoding: "utf8", timeout: 4000, windowsHide: true });
|
|
1837
|
+
} else {
|
|
1838
|
+
out = execFileSync("ps", ["aux"], { encoding: "utf8", timeout: 4000 });
|
|
1839
|
+
}
|
|
1840
|
+
const lines = out.split(/\r?\n/);
|
|
1841
|
+
for (const l of lines) {
|
|
1842
|
+
const portMatch = l.match(/--https_server_port\s+(\d+)/);
|
|
1843
|
+
const csrfMatch = l.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
1844
|
+
if (portMatch && csrfMatch) {
|
|
1845
|
+
return { port: parseInt(portMatch[1], 10), csrfToken: csrfMatch[1] };
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
} catch {}
|
|
1849
|
+
return null;
|
|
1349
1850
|
}
|
|
1350
1851
|
async function probeAgyQuota(options) {
|
|
1852
|
+
const acc = resolveAntigravityAccount();
|
|
1853
|
+
const lsInfo = resolveAntigravityLanguageServer();
|
|
1854
|
+
if (lsInfo) {
|
|
1855
|
+
try {
|
|
1856
|
+
let data = null;
|
|
1857
|
+
const prevReject = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
1858
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
1859
|
+
try {
|
|
1860
|
+
const res = await fetch(`https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`, {
|
|
1861
|
+
method: "POST",
|
|
1862
|
+
headers: {
|
|
1863
|
+
"Content-Type": "application/json",
|
|
1864
|
+
"x-codeium-csrf-token": lsInfo.csrfToken
|
|
1865
|
+
},
|
|
1866
|
+
body: JSON.stringify({}),
|
|
1867
|
+
signal: AbortSignal.timeout(4000),
|
|
1868
|
+
tls: { rejectUnauthorized: false }
|
|
1869
|
+
});
|
|
1870
|
+
if (res.ok) {
|
|
1871
|
+
data = await res.json();
|
|
1872
|
+
}
|
|
1873
|
+
} catch {
|
|
1874
|
+
try {
|
|
1875
|
+
const raw = execFileSync(process.platform === "win32" ? "curl.exe" : "curl", [
|
|
1876
|
+
"-k",
|
|
1877
|
+
"-s",
|
|
1878
|
+
"-X",
|
|
1879
|
+
"POST",
|
|
1880
|
+
"-H",
|
|
1881
|
+
"Content-Type: application/json",
|
|
1882
|
+
"-H",
|
|
1883
|
+
`x-codeium-csrf-token: ${lsInfo.csrfToken}`,
|
|
1884
|
+
"-d",
|
|
1885
|
+
"{}",
|
|
1886
|
+
`https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`
|
|
1887
|
+
], { encoding: "utf8", timeout: 4000 });
|
|
1888
|
+
data = JSON.parse(raw);
|
|
1889
|
+
} catch {}
|
|
1890
|
+
} finally {
|
|
1891
|
+
if (prevReject !== undefined) {
|
|
1892
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = prevReject;
|
|
1893
|
+
} else {
|
|
1894
|
+
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
if (data?.response?.groups) {
|
|
1898
|
+
const groups = data.response.groups;
|
|
1899
|
+
const formatReset = (isoStr, fallbackDesc) => {
|
|
1900
|
+
if (fallbackDesc && fallbackDesc.includes("it will fully refresh in ")) {
|
|
1901
|
+
const m = fallbackDesc.match(/it will fully refresh in (.+?)\.?$/);
|
|
1902
|
+
if (m?.[1])
|
|
1903
|
+
return `Resets in ${m[1].trim()}`;
|
|
1904
|
+
}
|
|
1905
|
+
if (!isoStr)
|
|
1906
|
+
return;
|
|
1907
|
+
const diffMs = new Date(isoStr).getTime() - Date.now();
|
|
1908
|
+
if (diffMs <= 0)
|
|
1909
|
+
return "已重置";
|
|
1910
|
+
const totalMins = Math.floor(diffMs / 60000);
|
|
1911
|
+
const hours = Math.floor(totalMins / 60);
|
|
1912
|
+
const days = Math.floor(hours / 24);
|
|
1913
|
+
if (days > 0)
|
|
1914
|
+
return `Resets in ${days}d ${hours % 24}h`;
|
|
1915
|
+
return `Resets in ${hours}h ${totalMins % 60}m`;
|
|
1916
|
+
};
|
|
1917
|
+
const toWindow = (b, groupName, label, durMins) => {
|
|
1918
|
+
if (!b)
|
|
1919
|
+
return;
|
|
1920
|
+
const frac = typeof b.remainingFraction === "number" ? b.remainingFraction : 1;
|
|
1921
|
+
const percentLeft = Math.max(0, Math.min(100, Math.round(frac * 100)));
|
|
1922
|
+
const usedPercent = 100 - percentLeft;
|
|
1923
|
+
return {
|
|
1924
|
+
label,
|
|
1925
|
+
group: groupName,
|
|
1926
|
+
percentLeft,
|
|
1927
|
+
usedPercent,
|
|
1928
|
+
windowDurationMins: durMins,
|
|
1929
|
+
resetsAt: formatReset(b.resetTime, b.description)
|
|
1930
|
+
};
|
|
1931
|
+
};
|
|
1932
|
+
const geminiGroup = groups.find((g) => g.displayName?.toLowerCase().includes("gemini"));
|
|
1933
|
+
const thirdPartyGroup = groups.find((g) => g.displayName?.toLowerCase().includes("claude") || g.displayName?.toLowerCase().includes("gpt"));
|
|
1934
|
+
const gemini5h = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
|
|
1935
|
+
const geminiWeekly = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
|
|
1936
|
+
const tp5h = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
|
|
1937
|
+
const tpWeekly = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
|
|
1938
|
+
const primaryWindow = toWindow(gemini5h, "Gemini Models", "5-Hour limit", 300) || {
|
|
1939
|
+
label: "5-Hour limit",
|
|
1940
|
+
group: "Gemini Models",
|
|
1941
|
+
percentLeft: 100,
|
|
1942
|
+
usedPercent: 0,
|
|
1943
|
+
windowDurationMins: 300
|
|
1944
|
+
};
|
|
1945
|
+
const secondaryWindow = toWindow(geminiWeekly, "Gemini Models", "Weekly limit", 10080);
|
|
1946
|
+
const extraWindows = [
|
|
1947
|
+
toWindow(tp5h, "Claude and GPT models", "5-Hour limit", 300),
|
|
1948
|
+
toWindow(tpWeekly, "Claude and GPT models", "Weekly limit", 10080)
|
|
1949
|
+
].filter(Boolean);
|
|
1950
|
+
return {
|
|
1951
|
+
runtimeId: "agy",
|
|
1952
|
+
provider: "Google Antigravity",
|
|
1953
|
+
account: {
|
|
1954
|
+
email: acc.email,
|
|
1955
|
+
name: acc.name || "Google Developer",
|
|
1956
|
+
plan: "Google AI Pro",
|
|
1957
|
+
type: "gemini"
|
|
1958
|
+
},
|
|
1959
|
+
primaryWindow,
|
|
1960
|
+
secondaryWindow,
|
|
1961
|
+
extraWindows: extraWindows.length > 0 ? extraWindows : undefined,
|
|
1962
|
+
credits: {
|
|
1963
|
+
unlimited: true,
|
|
1964
|
+
balance: "unlimited"
|
|
1965
|
+
},
|
|
1966
|
+
status: "ok",
|
|
1967
|
+
updatedAt: Date.now()
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
} catch {}
|
|
1971
|
+
}
|
|
1351
1972
|
const geminiHome = resolveGeminiHome2();
|
|
1352
|
-
const hasAgyDir = existsSync11(
|
|
1973
|
+
const hasAgyDir = existsSync11(join13(geminiHome, "antigravity")) || existsSync11(join13(geminiHome, "antigravity-cli"));
|
|
1353
1974
|
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
1354
|
-
const isAvailable = hasAgyDir || hasApiKey;
|
|
1975
|
+
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
1355
1976
|
if (!isAvailable) {
|
|
1356
1977
|
return {
|
|
1357
1978
|
runtimeId: "agy",
|
|
1358
1979
|
provider: "Google Antigravity",
|
|
1359
1980
|
status: "unauthorized",
|
|
1360
|
-
message: "
|
|
1981
|
+
message: "未检测到 Antigravity 登录凭据",
|
|
1361
1982
|
updatedAt: Date.now()
|
|
1362
1983
|
};
|
|
1363
1984
|
}
|
|
@@ -1365,21 +1986,41 @@ async function probeAgyQuota(options) {
|
|
|
1365
1986
|
runtimeId: "agy",
|
|
1366
1987
|
provider: "Google Antigravity",
|
|
1367
1988
|
account: {
|
|
1368
|
-
|
|
1989
|
+
email: acc.email,
|
|
1990
|
+
name: acc.name || "Google Developer",
|
|
1991
|
+
plan: "Google AI Pro",
|
|
1369
1992
|
type: "gemini"
|
|
1370
1993
|
},
|
|
1371
1994
|
primaryWindow: {
|
|
1372
1995
|
label: "5-Hour limit",
|
|
1996
|
+
group: "Gemini Models",
|
|
1373
1997
|
percentLeft: 100,
|
|
1374
1998
|
usedPercent: 0,
|
|
1375
1999
|
windowDurationMins: 300
|
|
1376
2000
|
},
|
|
1377
2001
|
secondaryWindow: {
|
|
1378
2002
|
label: "Weekly limit",
|
|
2003
|
+
group: "Gemini Models",
|
|
1379
2004
|
percentLeft: 100,
|
|
1380
2005
|
usedPercent: 0,
|
|
1381
2006
|
windowDurationMins: 10080
|
|
1382
2007
|
},
|
|
2008
|
+
extraWindows: [
|
|
2009
|
+
{
|
|
2010
|
+
label: "5-Hour limit",
|
|
2011
|
+
group: "Claude and GPT models",
|
|
2012
|
+
percentLeft: 100,
|
|
2013
|
+
usedPercent: 0,
|
|
2014
|
+
windowDurationMins: 300
|
|
2015
|
+
},
|
|
2016
|
+
{
|
|
2017
|
+
label: "Weekly limit",
|
|
2018
|
+
group: "Claude and GPT models",
|
|
2019
|
+
percentLeft: 100,
|
|
2020
|
+
usedPercent: 0,
|
|
2021
|
+
windowDurationMins: 10080
|
|
2022
|
+
}
|
|
2023
|
+
],
|
|
1383
2024
|
credits: {
|
|
1384
2025
|
unlimited: true,
|
|
1385
2026
|
balance: "unlimited"
|
|
@@ -1440,7 +2081,7 @@ function getAcpRuntimeAdapter(runtimeId) {
|
|
|
1440
2081
|
}
|
|
1441
2082
|
|
|
1442
2083
|
// src/process/process-manager.ts
|
|
1443
|
-
import { spawn, spawnSync as spawnSync2 } from "node:child_process";
|
|
2084
|
+
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
1444
2085
|
var active = new Map;
|
|
1445
2086
|
var ACP_EARLY_EXIT_WINDOW_MS = 3000;
|
|
1446
2087
|
var ACP_EARLY_EXIT_STDERR_TAIL_LINES = 20;
|
|
@@ -1495,7 +2136,7 @@ function spawnAcpProcess(options) {
|
|
|
1495
2136
|
} else {
|
|
1496
2137
|
delete env.NO_BROWSER;
|
|
1497
2138
|
}
|
|
1498
|
-
const child =
|
|
2139
|
+
const child = spawn2(file, options.runtime.args, {
|
|
1499
2140
|
cwd: options.cwd,
|
|
1500
2141
|
env,
|
|
1501
2142
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -2218,7 +2859,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
2218
2859
|
}
|
|
2219
2860
|
|
|
2220
2861
|
// src/client/acp-terminal.ts
|
|
2221
|
-
import { spawn as
|
|
2862
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
2222
2863
|
import { randomUUID } from "node:crypto";
|
|
2223
2864
|
|
|
2224
2865
|
// src/transport/terminal-output-buffer.ts
|
|
@@ -2271,7 +2912,7 @@ class AcpTerminalManager {
|
|
|
2271
2912
|
throw new Error("terminal/create 需要 command");
|
|
2272
2913
|
const cwd = resolveCwd(params.cwd, params.workspaceRoot);
|
|
2273
2914
|
const outputByteLimit = typeof params.outputByteLimit === "number" && params.outputByteLimit > 0 ? params.outputByteLimit : DEFAULT_OUTPUT_BYTE_LIMIT;
|
|
2274
|
-
const child =
|
|
2915
|
+
const child = spawn3(command, params.args ?? [], {
|
|
2275
2916
|
cwd,
|
|
2276
2917
|
env: buildEnv(params.env),
|
|
2277
2918
|
windowsHide: true,
|
|
@@ -2367,7 +3008,7 @@ class AcpTerminalManager {
|
|
|
2367
3008
|
return;
|
|
2368
3009
|
if (process.platform === "win32") {
|
|
2369
3010
|
try {
|
|
2370
|
-
|
|
3011
|
+
spawn3("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
2371
3012
|
windowsHide: true,
|
|
2372
3013
|
stdio: "ignore"
|
|
2373
3014
|
});
|
|
@@ -2404,7 +3045,7 @@ class AcpTerminalManager {
|
|
|
2404
3045
|
// src/client/acp-proxy-service.ts
|
|
2405
3046
|
import { mkdir as mkdir4, readFile as readFile3, writeFile as writeFile4 } from "node:fs/promises";
|
|
2406
3047
|
import { existsSync as existsSync12 } from "node:fs";
|
|
2407
|
-
import { join as
|
|
3048
|
+
import { join as join14 } from "node:path";
|
|
2408
3049
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
2409
3050
|
enabled: false,
|
|
2410
3051
|
host: "127.0.0.1",
|
|
@@ -2413,7 +3054,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
2413
3054
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
2414
3055
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
2415
3056
|
function proxyFilePath(dir) {
|
|
2416
|
-
return
|
|
3057
|
+
return join14(dir, "agent", "proxy.json");
|
|
2417
3058
|
}
|
|
2418
3059
|
function validate2(settings) {
|
|
2419
3060
|
if (!settings.host.trim())
|
|
@@ -2447,7 +3088,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
|
|
|
2447
3088
|
host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
|
|
2448
3089
|
port: payload.port
|
|
2449
3090
|
};
|
|
2450
|
-
await mkdir4(
|
|
3091
|
+
await mkdir4(join14(dir, "agent"), { recursive: true });
|
|
2451
3092
|
await writeFile4(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
|
|
2452
3093
|
return ok(stored);
|
|
2453
3094
|
}
|