opencode-usage 0.5.12 → 0.5.13
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/index.js +64 -56
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -246,7 +246,28 @@ __export(exports_plugin_adapters, {
|
|
|
246
246
|
proactiveRefreshCodexTokens: () => proactiveRefreshCodexTokens
|
|
247
247
|
});
|
|
248
248
|
import { homedir as homedir6, tmpdir } from "os";
|
|
249
|
-
import { join as join8 } from "path";
|
|
249
|
+
import { join as join8, dirname as dirname2 } from "path";
|
|
250
|
+
import { mkdir as mkdir2 } from "fs/promises";
|
|
251
|
+
async function syncCodexStoreToAll(content) {
|
|
252
|
+
await Promise.all(CODEX_STORE_PATHS.map(async (p) => {
|
|
253
|
+
try {
|
|
254
|
+
await mkdir2(dirname2(p), { recursive: true });
|
|
255
|
+
await Bun.write(p, content);
|
|
256
|
+
} catch {
|
|
257
|
+
}
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
async function readCodexStore() {
|
|
261
|
+
for (const p of CODEX_STORE_PATHS) {
|
|
262
|
+
try {
|
|
263
|
+
const store = JSON.parse(await Bun.file(p).text());
|
|
264
|
+
return { storePath: p, store };
|
|
265
|
+
} catch {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
250
271
|
function resolveSource2(provider) {
|
|
251
272
|
const source = PROVIDER_SOURCE[provider];
|
|
252
273
|
if (!source) {
|
|
@@ -256,22 +277,10 @@ function resolveSource2(provider) {
|
|
|
256
277
|
}
|
|
257
278
|
async function directCodexPing(alias) {
|
|
258
279
|
console.log(`[directCodexPing] pinging "${alias}"\u2026`);
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
join8(homedir6(), ".config", "opencode", "codex-multi-accounts.json"),
|
|
262
|
-
join8(homedir6(), ".config", "oc-codex-multi-account", "accounts.json")
|
|
263
|
-
];
|
|
264
|
-
let store = null;
|
|
265
|
-
for (const p of STORE_PATHS) {
|
|
266
|
-
try {
|
|
267
|
-
store = JSON.parse(await Bun.file(p).text());
|
|
268
|
-
break;
|
|
269
|
-
} catch {
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (!store)
|
|
280
|
+
const result = await readCodexStore();
|
|
281
|
+
if (!result)
|
|
274
282
|
return { status: "error", error: "No codex store found" };
|
|
283
|
+
const { store } = result;
|
|
275
284
|
console.log(`[directCodexPing] found account "${alias}", calling ChatGPT Codex API\u2026`);
|
|
276
285
|
const accounts = store.accounts ?? {};
|
|
277
286
|
const account = accounts[alias];
|
|
@@ -322,24 +331,10 @@ async function directCodexPing(alias) {
|
|
|
322
331
|
}
|
|
323
332
|
}
|
|
324
333
|
async function tryDirectCodexRefresh(alias) {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
join8(homedir6(), ".config", "opencode", "codex-multi-accounts.json"),
|
|
328
|
-
join8(homedir6(), ".config", "oc-codex-multi-account", "accounts.json")
|
|
329
|
-
];
|
|
330
|
-
let storePath = null;
|
|
331
|
-
let store = null;
|
|
332
|
-
for (const p of STORE_PATHS) {
|
|
333
|
-
try {
|
|
334
|
-
store = JSON.parse(await Bun.file(p).text());
|
|
335
|
-
storePath = p;
|
|
336
|
-
break;
|
|
337
|
-
} catch {
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (!store || !storePath)
|
|
334
|
+
const result = await readCodexStore();
|
|
335
|
+
if (!result)
|
|
342
336
|
return false;
|
|
337
|
+
const { storePath, store } = result;
|
|
343
338
|
const accounts = store.accounts ?? {};
|
|
344
339
|
const account = accounts[alias];
|
|
345
340
|
if (!account)
|
|
@@ -411,7 +406,9 @@ async function tryImportFromCodexCli(alias, account, storePath) {
|
|
|
411
406
|
freshAcct.expiresAt = cli.expiresAt;
|
|
412
407
|
freshAcct.lastRefresh = new Date().toISOString();
|
|
413
408
|
freshAcct.authInvalid = false;
|
|
414
|
-
|
|
409
|
+
const content = JSON.stringify(freshStore, null, 2);
|
|
410
|
+
await Bun.write(storePath, content);
|
|
411
|
+
await syncCodexStoreToAll(content);
|
|
415
412
|
const daysLeft = ((cli.expiresAt - Date.now()) / (24 * 60 * 60 * 1000)).toFixed(1);
|
|
416
413
|
console.log(`[proactiveRefresh] ${alias}: imported from CLI, expiry in ${daysLeft}d`);
|
|
417
414
|
return true;
|
|
@@ -455,7 +452,9 @@ async function refreshSingleCodexToken(alias, account, storePath) {
|
|
|
455
452
|
freshAcct.accountId = getAccountIdFromJwt(idClaims) ?? getAccountIdFromJwt(accessClaims) ?? freshAcct.accountId;
|
|
456
453
|
freshAcct.authInvalid = false;
|
|
457
454
|
}
|
|
458
|
-
|
|
455
|
+
const content = JSON.stringify(freshStore, null, 2);
|
|
456
|
+
await Bun.write(storePath, content);
|
|
457
|
+
await syncCodexStoreToAll(content);
|
|
459
458
|
const daysLeft = ((expiresAt - Date.now()) / (24 * 60 * 60 * 1000)).toFixed(1);
|
|
460
459
|
console.log(`[proactiveRefresh] ${alias}: refreshed in ${Date.now() - t0}ms, new expiry in ${daysLeft}d`);
|
|
461
460
|
return true;
|
|
@@ -475,24 +474,10 @@ async function proactiveRefreshCodexTokens() {
|
|
|
475
474
|
}
|
|
476
475
|
}
|
|
477
476
|
async function _proactiveRefreshCodexTokensInner() {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
join8(homedir6(), ".config", "opencode", "codex-multi-accounts.json"),
|
|
481
|
-
join8(homedir6(), ".config", "oc-codex-multi-account", "accounts.json")
|
|
482
|
-
];
|
|
483
|
-
let storePath = null;
|
|
484
|
-
let store = null;
|
|
485
|
-
for (const p of STORE_PATHS) {
|
|
486
|
-
try {
|
|
487
|
-
store = JSON.parse(await Bun.file(p).text());
|
|
488
|
-
storePath = p;
|
|
489
|
-
break;
|
|
490
|
-
} catch {
|
|
491
|
-
continue;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
if (!store || !storePath)
|
|
477
|
+
const result = await readCodexStore();
|
|
478
|
+
if (!result)
|
|
495
479
|
return;
|
|
480
|
+
const { storePath, store } = result;
|
|
496
481
|
const accounts = store.accounts ?? {};
|
|
497
482
|
const now = Date.now();
|
|
498
483
|
let refreshed = 0;
|
|
@@ -683,11 +668,16 @@ function reauthCliCommand(provider) {
|
|
|
683
668
|
throw new Error(`Re-auth not supported for provider: ${provider}`);
|
|
684
669
|
return cmd;
|
|
685
670
|
}
|
|
686
|
-
var isBun4, PROVIDER_SOURCE, CODEX_TOKEN_URL = "https://auth.openai.com/oauth/token", CODEX_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann", REFRESH_COOLDOWN_MS, CODEX_CLI_AUTH_PATH, _proactiveRefreshRunning = false, bunxQueue, REAUTH_PROVIDERS;
|
|
671
|
+
var isBun4, CODEX_STORE_PATHS, PROVIDER_SOURCE, CODEX_TOKEN_URL = "https://auth.openai.com/oauth/token", CODEX_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann", REFRESH_COOLDOWN_MS, CODEX_CLI_AUTH_PATH, _proactiveRefreshRunning = false, bunxQueue, REAUTH_PROVIDERS;
|
|
687
672
|
var init_plugin_adapters = __esm(() => {
|
|
688
673
|
init_command_runner();
|
|
689
674
|
init_config_service();
|
|
690
675
|
isBun4 = typeof globalThis.Bun !== "undefined";
|
|
676
|
+
CODEX_STORE_PATHS = [
|
|
677
|
+
join8(homedir6(), ".config", "opencode", "codex-multi-account-accounts.json"),
|
|
678
|
+
join8(homedir6(), ".config", "opencode", "codex-multi-accounts.json"),
|
|
679
|
+
join8(homedir6(), ".config", "oc-codex-multi-account", "accounts.json")
|
|
680
|
+
];
|
|
691
681
|
PROVIDER_SOURCE = {
|
|
692
682
|
anthropic: "anthropic-multi-account-state",
|
|
693
683
|
codex: "codex-multi-account-accounts",
|
|
@@ -863,6 +853,9 @@ var init_plugin_adapters = __esm(() => {
|
|
|
863
853
|
}
|
|
864
854
|
}
|
|
865
855
|
ctx.log("info", "Direct refresh failed \u2014 trying plugin CLI\u2026");
|
|
856
|
+
const primary = await readCodexStore();
|
|
857
|
+
if (primary)
|
|
858
|
+
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
866
859
|
try {
|
|
867
860
|
const result = await spawnPluginCli("oc-codex-multi-account", [
|
|
868
861
|
"ping",
|
|
@@ -933,6 +926,11 @@ var init_plugin_adapters = __esm(() => {
|
|
|
933
926
|
},
|
|
934
927
|
async run(ctx, input) {
|
|
935
928
|
const cliCmd = reauthCliCommand(input.provider);
|
|
929
|
+
if (input.provider === "codex") {
|
|
930
|
+
const primary = await readCodexStore();
|
|
931
|
+
if (primary)
|
|
932
|
+
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
933
|
+
}
|
|
936
934
|
ctx.log("info", `Generating auth URL for ${input.alias}\u2026`);
|
|
937
935
|
const result = await spawnPluginCli(cliCmd, ["reauth", input.alias]);
|
|
938
936
|
const url = String(result.url ?? "");
|
|
@@ -971,6 +969,11 @@ var init_plugin_adapters = __esm(() => {
|
|
|
971
969
|
},
|
|
972
970
|
async run(ctx, input) {
|
|
973
971
|
const cliCmd = reauthCliCommand(input.provider);
|
|
972
|
+
if (input.provider === "codex") {
|
|
973
|
+
const primary = await readCodexStore();
|
|
974
|
+
if (primary)
|
|
975
|
+
await syncCodexStoreToAll(JSON.stringify(primary.store, null, 2));
|
|
976
|
+
}
|
|
974
977
|
ctx.log("info", `Completing re-auth for ${input.alias}\u2026`);
|
|
975
978
|
const result = await spawnPluginCli(cliCmd, [
|
|
976
979
|
"reauth",
|
|
@@ -982,6 +985,11 @@ var init_plugin_adapters = __esm(() => {
|
|
|
982
985
|
]);
|
|
983
986
|
const status = String(result.status ?? "error");
|
|
984
987
|
ctx.log("info", `Result: ${status}`);
|
|
988
|
+
if (status === "ok" && input.provider === "codex") {
|
|
989
|
+
const fresh = await readCodexStore();
|
|
990
|
+
if (fresh)
|
|
991
|
+
await syncCodexStoreToAll(JSON.stringify(fresh.store, null, 2));
|
|
992
|
+
}
|
|
985
993
|
return {
|
|
986
994
|
status,
|
|
987
995
|
message: status === "ok" ? "Re-authenticated successfully" : String(result.error ?? "unknown error")
|
|
@@ -30491,7 +30499,7 @@ async function showConfig() {
|
|
|
30491
30499
|
var CODEX_AUTH_PATH2 = join6(homedir4(), ".codex", "auth.json");
|
|
30492
30500
|
|
|
30493
30501
|
// src/commander/server.ts
|
|
30494
|
-
import { join as join10, dirname as
|
|
30502
|
+
import { join as join10, dirname as dirname3 } from "path";
|
|
30495
30503
|
import { readFileSync as readFileSync2 } from "fs";
|
|
30496
30504
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
30497
30505
|
|
|
@@ -31103,7 +31111,7 @@ async function runCommanderServer(args) {
|
|
|
31103
31111
|
}
|
|
31104
31112
|
var isBun7 = typeof globalThis.Bun !== "undefined";
|
|
31105
31113
|
var DEFAULT_PORT = 4466;
|
|
31106
|
-
var __dirname2 =
|
|
31114
|
+
var __dirname2 = dirname3(fileURLToPath2(import.meta.url));
|
|
31107
31115
|
var PKG_VERSION = (() => {
|
|
31108
31116
|
for (const rel of [
|
|
31109
31117
|
join10(__dirname2, "..", "..", "package.json"),
|
|
@@ -31241,4 +31249,4 @@ async function main2() {
|
|
|
31241
31249
|
var WATCH_INTERVAL_MS = 5 * 60 * 1000;
|
|
31242
31250
|
main2().catch(console.error);
|
|
31243
31251
|
|
|
31244
|
-
//# debugId=
|
|
31252
|
+
//# debugId=12CA232C2B0D985864756E2164756E21
|