@pikecode/api-key-manager 2.2.3 → 2.2.4

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/CHANGELOG.md CHANGED
@@ -2,7 +2,22 @@
2
2
 
3
3
  记录项目的功能、修复和兼容性变化。以下历史条目依据 Git 提交补录,不代表已核实 npm 发布状态。
4
4
 
5
- ## 未发布(当前目标版本 2.2.3)
5
+ ## 未发布(当前目标版本 2.2.4)
6
+
7
+ ### 修复
8
+
9
+ - 历史分支确认区分同一供应商配置、不同供应商配置和来源无法确认,避免每次重复显示固定的跨供应商提醒。
10
+ - 第三方新对话使用独立模型供应商标识记录来源,名称、端点或认证变化后视为不同配置;不修改原历史。旧 `akm` 历史及官方 `openai` 账号无法精确区分时明确提示未知,不猜测归属。
11
+ - 官方登录仍使用原生 `openai` 标识;所有历史分支保留确认,默认不继续。
12
+ - 历史列表和确认页将内部来源标识映射为可读供应商名称,无法匹配时明确标为来源未确认,不猜测官方账号。
13
+ - 确认页选择“否”返回原列表,保留项目分组、已加载批次和选中项;ESC 取消启动。
14
+
15
+ ### 验证
16
+
17
+ - 61 个测试套件、643 项测试、Lint 和覆盖率门槛通过,覆盖来源分支文案及独立模型供应商启动参数。原生 Codex 0.166.0 app-server 离线分支验证通过:目标标识写入新历史,原文件未变化。使用临时目录和模拟历史,未执行真实模型请求。
18
+
19
+ ## 2.2.3
20
+
6
21
 
7
22
  ### 修复
8
23
 
package/README.md CHANGED
@@ -602,3 +602,5 @@ MIT License
602
602
  - [NPM](https://www.npmjs.com/package/@pikecode/api-key-manager)
603
603
  - [GitHub](https://github.com/pikecode/api-key-manager)
604
604
  - [Issues](https://github.com/pikecode/api-key-manager/issues)
605
+
606
+ 历史恢复的确认文案会区分来源:同一第三方配置只提示创建新分支;不同配置提示上下文将发送给当前供应商;无法确定来源时明确提示未知。新建第三方对话会记录独立的模型供应商标识,旧历史不会被改写。多个官方账号仍共享原生 `openai` 标识,因此无法仅凭历史元数据判断账号是否相同。供应商名称、端点或认证改变后视为不同配置。所有情况仍需确认创建分支,默认选择“否”:返回历史列表并保留分组、已加载批次和选中项;确认页按 ESC 取消启动。历史来源可匹配现有配置时显示供应商名称,旧第三方、官方账号及已变更或删除的配置显示相应的来源未确认说明,不直接展示内部摘要标识。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikecode/api-key-manager",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "A CLI tool for managing and switching multiple API provider configurations",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,8 +1,10 @@
1
1
  const fs = require('fs-extra');
2
+ const { codexProviderIdentity, historyConfirmation } = require('./codex-provider-identity');
2
3
  const path = require('path');
3
4
  const { BaseCommand } = require('../commands/BaseCommand');
4
5
  const { compactTerminalText, escapeTerminalText, listPageSize } = require('./terminal-format');
5
6
  const { resolveCodexHome } = require('./codex-files');
7
+ const { configManager } = require('../config');
6
8
 
7
9
  async function listCodexHistory(root = resolveCodexHome()) {
8
10
  const history = [];
@@ -70,6 +72,15 @@ async function selectCodexHistory(config, args) {
70
72
  throw error;
71
73
  }
72
74
  if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error('恢复历史需要交互终端,请交互选择历史或使用 --no-args 新建会话');
75
+ await configManager.ensureLoaded();
76
+ const providerNames = new Map();
77
+ for (const provider of [...configManager.listProviders().filter(item => item.ideName === 'codex'), config]) {
78
+ const identity = codexProviderIdentity(provider);
79
+ // openai 标识无法区分账号,不能映射为某一个官方配置名称。
80
+ if (identity !== 'openai') providerNames.set(identity, provider.displayName || provider.name);
81
+ }
82
+ const providerLabel = identity => providerNames.get(identity) ||
83
+ (identity === 'openai' ? 'OpenAI(账号未确认)' : identity === 'akm' ? '第三方(来源未确认)' : '未知来源');
73
84
  const currentDirectory = await normalizeDirectory(process.cwd());
74
85
  const directories = new Map();
75
86
  const local = [];
@@ -89,7 +100,7 @@ async function selectCodexHistory(config, args) {
89
100
  const items = showOther ? other : local;
90
101
  const visible = items.slice(0, limits[group]);
91
102
  const choices = visible.map(item => ({
92
- name: compactTerminalText(`${item.id.slice(0, 8)} | ${new Date(item.modifiedAt).toLocaleString()} | ${path.basename(item.cwd) || '未知项目'} | ${item.provider}`),
103
+ name: compactTerminalText(`${item.id.slice(0, 8)} | ${new Date(item.modifiedAt).toLocaleString()} | ${path.basename(item.cwd) || '未知项目'} | ${providerLabel(item.provider)}`),
93
104
  value: item.id
94
105
  }));
95
106
  if (items.length > visible.length) choices.push({ name: `加载更多(已显示 ${visible.length}/${items.length})`, value: 'more' });
@@ -110,18 +121,21 @@ async function selectCodexHistory(config, args) {
110
121
  }
111
122
  if (sessionId === 'other') { showOther = true; continue; }
112
123
  if (sessionId === 'back') { showOther = false; continue; }
113
- break;
124
+ if (sessionId === 'new') return args.filter(arg => arg !== 'resume');
125
+ if (!sessionId) return null;
126
+ const selected = history.find(item => item.id === sessionId);
127
+ const details = `ID: ${selected.id}\n目录: ${escapeTerminalText(selected.cwd)}\n原供应商: ${escapeTerminalText(providerLabel(selected.provider))}\n创建时间: ${escapeTerminalText(selected.timestamp)}\n最近使用: ${new Date(selected.modifiedAt).toLocaleString()}`;
128
+ const { confirmed } = await navigation.promptWithESCAndDefault({
129
+ type: 'confirm', name: 'confirmed', default: false,
130
+ message: `${details}\n当前供应商:「${escapeTerminalText(config.displayName || config.name)}」。${historyConfirmation(selected.provider, config)}(否:返回列表;ESC:取消启动)`
131
+ }, '', null, { confirmed: null });
132
+ if (confirmed === null) return null;
133
+ if (!confirmed) {
134
+ defaultId = sessionId;
135
+ continue;
136
+ }
137
+ return ['fork', sessionId, ...args.filter(arg => arg !== 'resume')];
114
138
  }
115
- if (sessionId === 'new') return args.filter(arg => arg !== 'resume');
116
- if (!sessionId) return null;
117
- const selected = history.find(item => item.id === sessionId);
118
- const details = `ID: ${selected.id}\n目录: ${escapeTerminalText(selected.cwd)}\n原供应商: ${escapeTerminalText(selected.provider)}\n创建时间: ${escapeTerminalText(selected.timestamp)}\n最近使用: ${new Date(selected.modifiedAt).toLocaleString()}`;
119
- const { confirmed } = await navigation.promptWithESCAndDefault({
120
- type: 'confirm', name: 'confirmed', default: false,
121
- message: `${details}\n将以供应商「${escapeTerminalText(config.displayName || config.name)}」处理所选历史上下文并创建新对话;若原供应商不同,历史内容会发送给新供应商。是否继续?`
122
- }, '', null, { confirmed: false });
123
- if (!confirmed) return null;
124
- return ['fork', sessionId, ...args.filter(arg => arg !== 'resume')];
125
139
  } finally {
126
140
  navigation.destroy();
127
141
  }
@@ -1,4 +1,5 @@
1
1
  const spawn = require('cross-spawn');
2
+ const { codexProviderIdentity } = require('./codex-provider-identity');
2
3
  const { sanitizeEnvValue, clearTerminal } = require('./env-utils');
3
4
  const { prepareCodexRuntime } = require('./codex-runtime');
4
5
  const { selectCodexHistory } = require('./codex-history');
@@ -88,9 +89,17 @@ async function executeCodexWithEnv(config, launchArgs = [], launchOptions = {})
88
89
  const args = [...subcommands, ...options,
89
90
  '-c', 'cli_auth_credentials_store="file"',
90
91
  '-c', `sqlite_home=${JSON.stringify(runtime.home)}`,
91
- '-c', `model_provider="${authMode === 'chatgpt_login' || !config.baseUrl ? 'openai' : 'akm'}"`
92
+ '-c', `model_provider="${codexProviderIdentity(config)}"`
92
93
  ];
93
94
 
95
+ const providerKey = codexProviderIdentity(config);
96
+ if (providerKey !== 'openai') {
97
+ // 独立标识写入原生会话元数据,多窗口无需猜测历史文件的归属。
98
+ for (const [field, value] of Object.entries({ name: providerKey, base_url: config.baseUrl, wire_api: 'responses', requires_openai_auth: true })) {
99
+ args.push('-c', `model_providers.${providerKey}.${field}=${JSON.stringify(value)}`);
100
+ }
101
+ }
102
+
94
103
  clearTerminal();
95
104
 
96
105
  if (authMode === 'chatgpt_login') {
@@ -0,0 +1,25 @@
1
+ const crypto = require('crypto');
2
+
3
+ function codexProviderIdentity(config) {
4
+ if (config.authMode === 'chatgpt_login' || !config.baseUrl) return 'openai';
5
+ // 认证或端点变化后视为不同来源,不保存明文密钥。
6
+ const digest = crypto.createHash('sha256').update(JSON.stringify([
7
+ config.name, config.baseUrl, config.authMode || 'api_key', config.authToken || ''
8
+ ])).digest('hex');
9
+ return `akm_${digest}`;
10
+ }
11
+
12
+ function historyConfirmation(provider, config) {
13
+ const target = codexProviderIdentity(config);
14
+ if (/^akm_[a-f0-9]{64}$/.test(provider) && provider === target) {
15
+ return '所选历史来自当前供应商配置,将创建新对话分支,原对话保留。是否继续?';
16
+ }
17
+ if ((/^akm_[a-f0-9]{64}$/.test(provider) && provider !== target) ||
18
+ (provider === 'akm' && target === 'openai') ||
19
+ (provider === 'openai' && target !== 'openai')) {
20
+ return '所选历史来自其他供应商配置,恢复所需的历史内容将发送给当前供应商,并创建新对话分支。是否继续?';
21
+ }
22
+ return '无法确认所选历史是否来自当前供应商或账号。继续后,恢复所需的历史内容将由当前供应商处理,并创建新对话分支。是否继续?';
23
+ }
24
+
25
+ module.exports = { codexProviderIdentity, historyConfirmation };