@pikecode/api-key-manager 2.1.7 → 2.1.9
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/README.md +40 -0
- package/package.json +1 -1
- package/src/utils/codex-files.js +11 -9
- package/src/utils/env-launcher.js +2 -1
package/README.md
CHANGED
|
@@ -344,6 +344,46 @@ API Key (OPENAI_API_KEY): sk-xxxxxxxx
|
|
|
344
344
|
akm openai-work --relogin
|
|
345
345
|
```
|
|
346
346
|
|
|
347
|
+
### Codex 官方多账号
|
|
348
|
+
|
|
349
|
+
每个官方账号都应创建一个独立的 Codex 官方网页登录供应商,供应商名称就是 Session 隔离键。
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
# 添加个人 OpenAI 官方账号
|
|
353
|
+
akm add --codex
|
|
354
|
+
# 认证方式选择: 官方网页登录
|
|
355
|
+
# 供应商名称填写: openai-personal
|
|
356
|
+
|
|
357
|
+
# 添加工作 OpenAI 官方账号
|
|
358
|
+
akm add --codex
|
|
359
|
+
# 认证方式选择: 官方网页登录
|
|
360
|
+
# 供应商名称填写: openai-work
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
首次启动某个官方供应商时,如果该供应商还没有自己的 Session,Codex 会打开浏览器授权;授权完成后 AKM 会按供应商名称缓存 Session。
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
# 首次启动个人账号,会绑定 openai-personal 的 Session
|
|
367
|
+
akm openai-personal
|
|
368
|
+
|
|
369
|
+
# 首次启动工作账号,会重新网页授权,不复用 openai-personal
|
|
370
|
+
akm openai-work
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
日常切换时直接使用供应商名称即可:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
akm openai-personal
|
|
377
|
+
akm openai-work
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
需要换号、Session 异常或希望重新网页登录时,使用 `--relogin` 清理当前供应商的 Session:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
akm openai-work --relogin
|
|
384
|
+
akm switch openai-work --relogin
|
|
385
|
+
```
|
|
386
|
+
|
|
347
387
|
### 多账号配置
|
|
348
388
|
|
|
349
389
|
```bash
|
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 {
|
|
@@ -80,12 +80,13 @@ async function executeWithEnv(config, launchArgs = []) {
|
|
|
80
80
|
// 检查是否是"没有可恢复会话"的错误
|
|
81
81
|
// 检查 stderr 中是否包含各种格式的错误消息
|
|
82
82
|
const errorOutput = stderrOutput.toLowerCase();
|
|
83
|
+
const isContinueLaunch = args.includes('--continue');
|
|
83
84
|
const isNoConversationError =
|
|
84
85
|
errorOutput.includes('no conversation found') ||
|
|
85
86
|
errorOutput.includes('no recoverable session') ||
|
|
86
87
|
errorOutput.includes('no deferred tool marker');
|
|
87
88
|
|
|
88
|
-
if (isNoConversationError) {
|
|
89
|
+
if (isNoConversationError || (isContinueLaunch && code === 1)) {
|
|
89
90
|
const error = new Error('没有可恢复的会话\n提示: 请选择不带 --continue 参数重新开始');
|
|
90
91
|
error.code = 'NO_CONVERSATION_FOUND';
|
|
91
92
|
reject(error);
|