@pikecode/api-key-manager 2.1.7 → 2.1.8
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/package.json +1 -1
- package/src/utils/codex-files.js +11 -9
package/package.json
CHANGED
package/src/utils/codex-files.js
CHANGED
|
@@ -603,26 +603,28 @@ async function clearCodexAkmConfig(options = {}) {
|
|
|
603
603
|
const { configTomlPath, authJsonPath } = buildCodexPaths(codexHome);
|
|
604
604
|
const sessionKey = normalizeSessionKey(options.sessionKey);
|
|
605
605
|
const forceRelogin = options.forceRelogin === true;
|
|
606
|
+
const cachedAuthPath = forceRelogin ? null : await findChatGptLoginAuthSource(codexHome, sessionKey);
|
|
606
607
|
|
|
607
608
|
// 备份当前配置
|
|
608
609
|
await backupCodexFiles(codexHome);
|
|
609
610
|
if (forceRelogin) {
|
|
610
611
|
await clearCachedChatGptLoginAuth(codexHome, sessionKey);
|
|
611
|
-
} else {
|
|
612
|
+
} else if (!sessionKey) {
|
|
612
613
|
await cacheCurrentChatGptLoginAuth(codexHome, authJsonPath, sessionKey);
|
|
613
614
|
}
|
|
614
615
|
|
|
615
616
|
// 只移除 API Key 认证文件,避免破坏 Codex 官方网页登录态。
|
|
616
617
|
const shouldRemoveAuthJson = forceRelogin
|
|
617
618
|
? await shouldRemoveAuthJsonForRelogin(authJsonPath)
|
|
618
|
-
:
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
619
|
+
: sessionKey
|
|
620
|
+
? await shouldRemoveAuthJsonForRelogin(authJsonPath)
|
|
621
|
+
: await shouldRemoveAuthJsonForChatGptLogin(authJsonPath);
|
|
622
|
+
const shouldRestoreCachedAuth =
|
|
623
|
+
Boolean(cachedAuthPath) && (!(await fs.pathExists(authJsonPath)) || shouldRemoveAuthJson);
|
|
624
|
+
|
|
625
|
+
if (shouldRemoveAuthJson || shouldRestoreCachedAuth) {
|
|
626
|
+
if (shouldRestoreCachedAuth) {
|
|
627
|
+
await fs.copy(cachedAuthPath, authJsonPath);
|
|
626
628
|
await setSecurePermissions(authJsonPath);
|
|
627
629
|
await cacheCurrentChatGptLoginAuth(codexHome, authJsonPath, sessionKey);
|
|
628
630
|
} else {
|