@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikecode/api-key-manager",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "A CLI tool for managing and switching multiple API provider configurations",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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
- : await shouldRemoveAuthJsonForChatGptLogin(authJsonPath);
619
-
620
- if (shouldRemoveAuthJson) {
621
- const authSourcePath = forceRelogin
622
- ? null
623
- : await findChatGptLoginAuthSource(codexHome, sessionKey);
624
- if (authSourcePath) {
625
- await fs.copy(authSourcePath, authJsonPath);
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 {