opencode-usage 0.5.13 → 0.5.15
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/commander-ui/assets/index-00dEyfmq.js +20 -0
- package/dist/commander-ui/dist/assets/index-00dEyfmq.js +20 -0
- package/dist/commander-ui/dist/index.html +1 -1
- package/dist/commander-ui/index.html +1 -1
- package/dist/index.js +76 -16
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/dist/commander-ui/assets/index-BkXCdfeo.js +0 -20
- package/dist/commander-ui/dist/assets/index-BkXCdfeo.js +0 -20
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
if (d) document.documentElement.classList.add("dark");
|
|
15
15
|
})();
|
|
16
16
|
</script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-00dEyfmq.js"></script>
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/index-DP6urYMR.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
if (d) document.documentElement.classList.add("dark");
|
|
15
15
|
})();
|
|
16
16
|
</script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-00dEyfmq.js"></script>
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/index-DP6urYMR.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -248,7 +248,7 @@ __export(exports_plugin_adapters, {
|
|
|
248
248
|
import { homedir as homedir6, tmpdir } from "os";
|
|
249
249
|
import { join as join8, dirname as dirname2 } from "path";
|
|
250
250
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
251
|
-
async function
|
|
251
|
+
async function writeCodexStoreToAll(content) {
|
|
252
252
|
await Promise.all(CODEX_STORE_PATHS.map(async (p) => {
|
|
253
253
|
try {
|
|
254
254
|
await mkdir2(dirname2(p), { recursive: true });
|
|
@@ -257,6 +257,39 @@ async function syncCodexStoreToAll(content) {
|
|
|
257
257
|
}
|
|
258
258
|
}));
|
|
259
259
|
}
|
|
260
|
+
async function mergeAndSyncCodexStores() {
|
|
261
|
+
const stores = [];
|
|
262
|
+
for (const p of CODEX_STORE_PATHS) {
|
|
263
|
+
try {
|
|
264
|
+
stores.push(JSON.parse(await Bun.file(p).text()));
|
|
265
|
+
} catch {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (stores.length === 0)
|
|
270
|
+
return;
|
|
271
|
+
const merged = JSON.parse(JSON.stringify(stores[0]));
|
|
272
|
+
const mergedAccounts = merged.accounts ?? {};
|
|
273
|
+
for (const data of stores.slice(1)) {
|
|
274
|
+
const accounts = data.accounts ?? {};
|
|
275
|
+
for (const [alias, account] of Object.entries(accounts)) {
|
|
276
|
+
const existing = mergedAccounts[alias];
|
|
277
|
+
if (!existing) {
|
|
278
|
+
mergedAccounts[alias] = account;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const existingExpiry = typeof existing.expiresAt === "number" ? existing.expiresAt : 0;
|
|
282
|
+
const newExpiry = typeof account.expiresAt === "number" ? account.expiresAt : 0;
|
|
283
|
+
if (newExpiry > existingExpiry) {
|
|
284
|
+
mergedAccounts[alias] = account;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
merged.accounts = mergedAccounts;
|
|
289
|
+
const content = JSON.stringify(merged, null, 2);
|
|
290
|
+
console.log(`[syncCodexStores] merged ${stores.length} stores, ${Object.keys(mergedAccounts).length} accounts`);
|
|
291
|
+
await writeCodexStoreToAll(content);
|
|
292
|
+
}
|
|
260
293
|
async function readCodexStore() {
|
|
261
294
|
for (const p of CODEX_STORE_PATHS) {
|
|
262
295
|
try {
|
|
@@ -408,7 +441,7 @@ async function tryImportFromCodexCli(alias, account, storePath) {
|
|
|
408
441
|
freshAcct.authInvalid = false;
|
|
409
442
|
const content = JSON.stringify(freshStore, null, 2);
|
|
410
443
|
await Bun.write(storePath, content);
|
|
411
|
-
await
|
|
444
|
+
await mergeAndSyncCodexStores();
|
|
412
445
|
const daysLeft = ((cli.expiresAt - Date.now()) / (24 * 60 * 60 * 1000)).toFixed(1);
|
|
413
446
|
console.log(`[proactiveRefresh] ${alias}: imported from CLI, expiry in ${daysLeft}d`);
|
|
414
447
|
return true;
|
|
@@ -454,7 +487,7 @@ async function refreshSingleCodexToken(alias, account, storePath) {
|
|
|
454
487
|
}
|
|
455
488
|
const content = JSON.stringify(freshStore, null, 2);
|
|
456
489
|
await Bun.write(storePath, content);
|
|
457
|
-
await
|
|
490
|
+
await mergeAndSyncCodexStores();
|
|
458
491
|
const daysLeft = ((expiresAt - Date.now()) / (24 * 60 * 60 * 1000)).toFixed(1);
|
|
459
492
|
console.log(`[proactiveRefresh] ${alias}: refreshed in ${Date.now() - t0}ms, new expiry in ${daysLeft}d`);
|
|
460
493
|
return true;
|
|
@@ -853,9 +886,7 @@ var init_plugin_adapters = __esm(() => {
|
|
|
853
886
|
}
|
|
854
887
|
}
|
|
855
888
|
ctx.log("info", "Direct refresh failed \u2014 trying plugin CLI\u2026");
|
|
856
|
-
|
|
857
|
-
if (primary)
|
|
858
|
-
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
889
|
+
await mergeAndSyncCodexStores();
|
|
859
890
|
try {
|
|
860
891
|
const result = await spawnPluginCli("oc-codex-multi-account", [
|
|
861
892
|
"ping",
|
|
@@ -927,9 +958,7 @@ var init_plugin_adapters = __esm(() => {
|
|
|
927
958
|
async run(ctx, input) {
|
|
928
959
|
const cliCmd = reauthCliCommand(input.provider);
|
|
929
960
|
if (input.provider === "codex") {
|
|
930
|
-
|
|
931
|
-
if (primary)
|
|
932
|
-
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
961
|
+
await mergeAndSyncCodexStores();
|
|
933
962
|
}
|
|
934
963
|
ctx.log("info", `Generating auth URL for ${input.alias}\u2026`);
|
|
935
964
|
const result = await spawnPluginCli(cliCmd, ["reauth", input.alias]);
|
|
@@ -970,9 +999,7 @@ var init_plugin_adapters = __esm(() => {
|
|
|
970
999
|
async run(ctx, input) {
|
|
971
1000
|
const cliCmd = reauthCliCommand(input.provider);
|
|
972
1001
|
if (input.provider === "codex") {
|
|
973
|
-
|
|
974
|
-
if (primary)
|
|
975
|
-
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
1002
|
+
await mergeAndSyncCodexStores();
|
|
976
1003
|
}
|
|
977
1004
|
ctx.log("info", `Completing re-auth for ${input.alias}\u2026`);
|
|
978
1005
|
const result = await spawnPluginCli(cliCmd, [
|
|
@@ -986,9 +1013,7 @@ var init_plugin_adapters = __esm(() => {
|
|
|
986
1013
|
const status = String(result.status ?? "error");
|
|
987
1014
|
ctx.log("info", `Result: ${status}`);
|
|
988
1015
|
if (status === "ok" && input.provider === "codex") {
|
|
989
|
-
|
|
990
|
-
if (fresh)
|
|
991
|
-
await syncCodexStoreToAll(JSON.stringify(fresh.store, null, 2));
|
|
1016
|
+
await mergeAndSyncCodexStores();
|
|
992
1017
|
}
|
|
993
1018
|
return {
|
|
994
1019
|
status,
|
|
@@ -30896,6 +30921,35 @@ async function queryUsage(opts) {
|
|
|
30896
30921
|
worker.postMessage(opts);
|
|
30897
30922
|
});
|
|
30898
30923
|
}
|
|
30924
|
+
function pingAllAccounts() {
|
|
30925
|
+
for (const { provider, source } of PING_PROVIDERS) {
|
|
30926
|
+
try {
|
|
30927
|
+
const data = readConfig(source);
|
|
30928
|
+
let aliases;
|
|
30929
|
+
if (provider === "antigravity") {
|
|
30930
|
+
const accounts = Array.isArray(data.accounts) ? data.accounts : [];
|
|
30931
|
+
aliases = accounts.map((a) => typeof a.email === "string" ? a.email : "").filter(Boolean);
|
|
30932
|
+
} else if (provider === "anthropic") {
|
|
30933
|
+
const usage = data.usage && typeof data.usage === "object" ? data.usage : {};
|
|
30934
|
+
aliases = Object.keys(usage);
|
|
30935
|
+
} else {
|
|
30936
|
+
const accounts = data.accounts && typeof data.accounts === "object" ? data.accounts : {};
|
|
30937
|
+
aliases = Object.keys(accounts);
|
|
30938
|
+
}
|
|
30939
|
+
for (const alias of aliases) {
|
|
30940
|
+
try {
|
|
30941
|
+
runCommand("accounts.ping", { provider, alias });
|
|
30942
|
+
} catch (err) {
|
|
30943
|
+
console.log(`[startup-ping] ${provider}/${alias}: failed to queue \u2014 ${err instanceof Error ? err.message : String(err)}`);
|
|
30944
|
+
}
|
|
30945
|
+
}
|
|
30946
|
+
if (aliases.length > 0) {
|
|
30947
|
+
console.log(`[startup-ping] queued ${aliases.length} ping(s) for ${provider}`);
|
|
30948
|
+
}
|
|
30949
|
+
} catch {
|
|
30950
|
+
}
|
|
30951
|
+
}
|
|
30952
|
+
}
|
|
30899
30953
|
async function runCommanderServer(args) {
|
|
30900
30954
|
if (!isBun7) {
|
|
30901
30955
|
console.error("Commander mode requires Bun runtime.");
|
|
@@ -31104,6 +31158,7 @@ async function runCommanderServer(args) {
|
|
|
31104
31158
|
console.log(`Commander ready at ${serverUrl}`);
|
|
31105
31159
|
proactiveRefreshCodexTokens().catch(() => {
|
|
31106
31160
|
});
|
|
31161
|
+
pingAllAccounts();
|
|
31107
31162
|
if (isBun7 && !process.env.NO_OPEN) {
|
|
31108
31163
|
const cmd = process.platform === "win32" ? ["cmd", "/c", "start", serverUrl] : process.platform === "darwin" ? ["open", serverUrl] : ["xdg-open", serverUrl];
|
|
31109
31164
|
Bun.spawn(cmd, { stdio: ["ignore", "ignore", "ignore"] });
|
|
@@ -31139,6 +31194,11 @@ var UI_DIST = await (async () => {
|
|
|
31139
31194
|
})();
|
|
31140
31195
|
var usageWorkerPath = join10(__dirname2, "services", "usage-worker.ts");
|
|
31141
31196
|
var canUseWorker = await Bun.file(usageWorkerPath).exists();
|
|
31197
|
+
var PING_PROVIDERS = [
|
|
31198
|
+
{ provider: "anthropic", source: "anthropic-multi-account-state" },
|
|
31199
|
+
{ provider: "codex", source: "codex-multi-account-accounts" },
|
|
31200
|
+
{ provider: "antigravity", source: "antigravity-accounts" }
|
|
31201
|
+
];
|
|
31142
31202
|
// src/index.ts
|
|
31143
31203
|
function clearScreen() {
|
|
31144
31204
|
process.stdout.write("\x1B[2J\x1B[H");
|
|
@@ -31249,4 +31309,4 @@ async function main2() {
|
|
|
31249
31309
|
var WATCH_INTERVAL_MS = 5 * 60 * 1000;
|
|
31250
31310
|
main2().catch(console.error);
|
|
31251
31311
|
|
|
31252
|
-
//# debugId=
|
|
31312
|
+
//# debugId=D70ECC3BE99AA5F764756E2164756E21
|