coding-tool-x 3.3.6 → 3.3.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/CHANGELOG.md +14 -0
- package/dist/web/assets/{Analytics-TtaduRqL.js → Analytics-DLpoDZ2M.js} +1 -1
- package/dist/web/assets/{ConfigTemplates-BP2lLBMN.js → ConfigTemplates-D_hRb55W.js} +1 -1
- package/dist/web/assets/Home-BMoFdAwy.css +1 -0
- package/dist/web/assets/Home-DNwp-0J-.js +1 -0
- package/dist/web/assets/{PluginManager-HmISlyMK.js → PluginManager-JXsyym1s.js} +1 -1
- package/dist/web/assets/{ProjectList-DoN8Hjbu.js → ProjectList-DZWSeb-q.js} +1 -1
- package/dist/web/assets/{SessionList-Da8BYzNi.js → SessionList-Cs624DR3.js} +1 -1
- package/dist/web/assets/{SkillManager-DqLAXh9o.js → SkillManager-bEliz7qz.js} +1 -1
- package/dist/web/assets/{WorkspaceManager-B_TxOgPW.js → WorkspaceManager-J3RecFGn.js} +1 -1
- package/dist/web/assets/{icons-B29onFfZ.js → icons-Cuc23WS7.js} +1 -1
- package/dist/web/assets/index-BXeSvAwU.js +2 -0
- package/dist/web/assets/index-DWAC3Tdv.css +1 -0
- package/dist/web/index.html +3 -3
- package/package.json +3 -2
- package/src/commands/daemon.js +44 -6
- package/src/commands/toggle-proxy.js +100 -5
- package/src/config/default.js +1 -1
- package/src/config/model-metadata.js +2 -2
- package/src/config/model-metadata.json +7 -2
- package/src/config/paths.js +102 -19
- package/src/server/api/channels.js +9 -0
- package/src/server/api/codex-channels.js +9 -0
- package/src/server/api/codex-proxy.js +22 -11
- package/src/server/api/gemini-proxy.js +22 -11
- package/src/server/api/mcp.js +26 -4
- package/src/server/api/oauth-credentials.js +163 -0
- package/src/server/api/opencode-proxy.js +22 -10
- package/src/server/api/plugins.js +3 -1
- package/src/server/api/proxy.js +39 -44
- package/src/server/api/skills.js +91 -13
- package/src/server/codex-proxy-server.js +1 -11
- package/src/server/index.js +26 -2
- package/src/server/services/channels.js +18 -22
- package/src/server/services/codex-channels.js +124 -175
- package/src/server/services/codex-config.js +2 -5
- package/src/server/services/codex-settings-manager.js +12 -348
- package/src/server/services/config-export-service.js +572 -117
- package/src/server/services/gemini-channels.js +11 -9
- package/src/server/services/mcp-client.js +70 -13
- package/src/server/services/mcp-service.js +74 -29
- package/src/server/services/model-detector.js +1 -0
- package/src/server/services/native-keychain.js +243 -0
- package/src/server/services/native-oauth-adapters.js +890 -0
- package/src/server/services/oauth-credentials-service.js +786 -0
- package/src/server/services/oauth-utils.js +49 -0
- package/src/server/services/opencode-channels.js +13 -9
- package/src/server/services/opencode-settings-manager.js +169 -16
- package/src/server/services/plugins-service.js +22 -1
- package/src/server/services/settings-manager.js +13 -0
- package/src/server/services/skill-service.js +712 -332
- package/src/utils/port-helper.js +87 -2
- package/dist/web/assets/Home-BsSioaaB.css +0 -1
- package/dist/web/assets/Home-CbbyopS-.js +0 -1
- package/dist/web/assets/index-By3mDEvx.js +0 -2
- package/dist/web/assets/index-CsWInMQV.css +0 -1
|
@@ -57,7 +57,9 @@ router.get('/', (req, res) => {
|
|
|
57
57
|
router.get('/market', async (req, res) => {
|
|
58
58
|
try {
|
|
59
59
|
const { platform, service } = getPluginsService(req);
|
|
60
|
-
const
|
|
60
|
+
const forceRefresh = req.query.refresh === '1';
|
|
61
|
+
if (forceRefresh) service._marketCache = null;
|
|
62
|
+
const plugins = await service.getMarketPlugins(forceRefresh);
|
|
61
63
|
|
|
62
64
|
res.json({
|
|
63
65
|
success: true,
|
package/src/server/api/proxy.js
CHANGED
|
@@ -4,6 +4,7 @@ const { startProxyServer, stopProxyServer, getProxyStatus } = require('../proxy-
|
|
|
4
4
|
const {
|
|
5
5
|
setProxyConfig,
|
|
6
6
|
restoreSettings,
|
|
7
|
+
deleteBackup,
|
|
7
8
|
isProxyConfig,
|
|
8
9
|
getCurrentProxyPort,
|
|
9
10
|
settingsExists,
|
|
@@ -11,6 +12,7 @@ const {
|
|
|
11
12
|
readSettings
|
|
12
13
|
} = require('../services/settings-manager');
|
|
13
14
|
const { getAllChannels } = require('../services/channels');
|
|
15
|
+
const { clearNativeOAuth } = require('../services/native-oauth-adapters');
|
|
14
16
|
const { clearAllLogs } = require('../websocket-server');
|
|
15
17
|
const { PATHS, NATIVE_PATHS, ensureStorageDirMigrated } = require('../../config/paths');
|
|
16
18
|
const fs = require('fs');
|
|
@@ -37,6 +39,24 @@ function selectLatestEnabledChannel(channels) {
|
|
|
37
39
|
}, enabledChannels[0]);
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
function resolveActiveChannel(channels, activeChannelId = null) {
|
|
43
|
+
if (!Array.isArray(channels) || channels.length === 0) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (activeChannelId) {
|
|
48
|
+
const matched = channels.find(channel => channel.id === activeChannelId);
|
|
49
|
+
if (matched) {
|
|
50
|
+
return matched;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return selectLatestEnabledChannel(channels)
|
|
55
|
+
|| channels.find(channel => channel.enabled !== false)
|
|
56
|
+
|| channels[0]
|
|
57
|
+
|| null;
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
// 保存激活渠道ID
|
|
41
61
|
function saveActiveChannelId(channelId) {
|
|
42
62
|
ensureStorageDirMigrated();
|
|
@@ -70,11 +90,14 @@ function findActiveChannelFromSettings() {
|
|
|
70
90
|
try {
|
|
71
91
|
const settings = readSettings();
|
|
72
92
|
const baseUrl = settings?.env?.ANTHROPIC_BASE_URL || '';
|
|
93
|
+
const { readNativeOAuth } = require('../services/native-oauth-adapters');
|
|
94
|
+
const nativeOAuth = readNativeOAuth('claude');
|
|
73
95
|
|
|
74
96
|
// 兼容多种 API Key 格式(与 channels.js 保持一致)
|
|
75
|
-
let apiKey = settings?.env?.ANTHROPIC_API_KEY ||
|
|
76
|
-
|
|
77
|
-
|
|
97
|
+
let apiKey = settings?.env?.ANTHROPIC_API_KEY || '';
|
|
98
|
+
if (!apiKey && !nativeOAuth) {
|
|
99
|
+
apiKey = settings?.env?.ANTHROPIC_AUTH_TOKEN || '';
|
|
100
|
+
}
|
|
78
101
|
|
|
79
102
|
// 如果 apiKey 仍为空,尝试从 apiKeyHelper 提取
|
|
80
103
|
if (!apiKey && settings?.apiKeyHelper) {
|
|
@@ -195,6 +218,7 @@ router.post('/start', async (req, res) => {
|
|
|
195
218
|
}
|
|
196
219
|
|
|
197
220
|
// 5. 设置代理配置(备份并修改 settings.json)
|
|
221
|
+
clearNativeOAuth('claude');
|
|
198
222
|
setProxyConfig(proxyResult.port);
|
|
199
223
|
|
|
200
224
|
const updatedStatus = getProxyStatus();
|
|
@@ -221,57 +245,28 @@ router.post('/start', async (req, res) => {
|
|
|
221
245
|
router.post('/stop', async (req, res) => {
|
|
222
246
|
try {
|
|
223
247
|
const channelsBeforeStop = getAllChannels();
|
|
224
|
-
const
|
|
248
|
+
const activeChannelId = loadActiveChannelId();
|
|
249
|
+
let restoredChannel = resolveActiveChannel(channelsBeforeStop, activeChannelId);
|
|
225
250
|
|
|
226
251
|
// 1. 停止代理服务器
|
|
227
252
|
const proxyResult = await stopProxyServer();
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
// 2. 恢复配置(优先从备份,否则选择权重最高的启用渠道)
|
|
231
|
-
let restoredChannel = null;
|
|
253
|
+
const hadBackup = hasBackup();
|
|
232
254
|
|
|
233
|
-
//
|
|
234
|
-
if (
|
|
255
|
+
// 2. 恢复配置(优先恢复当前活动渠道,避免覆盖动态切换期间的设置变更)
|
|
256
|
+
if (restoredChannel) {
|
|
257
|
+
if (hadBackup) {
|
|
258
|
+
deleteBackup();
|
|
259
|
+
console.log('✅ Discarded backup snapshot');
|
|
260
|
+
}
|
|
261
|
+
} else if (hadBackup) {
|
|
235
262
|
restoreSettings();
|
|
236
263
|
console.log('✅ Restored settings from backup');
|
|
237
|
-
|
|
238
|
-
// 尝试找到匹配的渠道
|
|
239
264
|
const channels = getAllChannels();
|
|
240
265
|
const currentSettings = require('../services/channels').getCurrentSettings();
|
|
241
266
|
if (currentSettings) {
|
|
242
267
|
restoredChannel = channels.find(ch =>
|
|
243
268
|
ch.baseUrl === currentSettings.baseUrl && ch.apiKey === currentSettings.apiKey
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
// Fallback: keep latest enabled channel when leaving dynamic switching mode
|
|
247
|
-
if (!restoredChannel && latestEnabledChannel) {
|
|
248
|
-
restoredChannel = channels.find(ch => ch.id === latestEnabledChannel.id) || latestEnabledChannel;
|
|
249
|
-
}
|
|
250
|
-
// Fallback: use previously active channel id
|
|
251
|
-
if (!restoredChannel && activeChannelId) {
|
|
252
|
-
restoredChannel = channels.find(ch => ch.id === activeChannelId);
|
|
253
|
-
}
|
|
254
|
-
// Fallback: use first enabled channel
|
|
255
|
-
if (!restoredChannel) {
|
|
256
|
-
restoredChannel = channels.find(ch => ch.enabled !== false) || channels[0];
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
// 没有备份,选择权重最高的启用渠道
|
|
260
|
-
const { getBestChannelForRestore, updateClaudeSettings } = require('../services/channels');
|
|
261
|
-
const channels = getAllChannels();
|
|
262
|
-
restoredChannel = latestEnabledChannel
|
|
263
|
-
? channels.find(ch => ch.id === latestEnabledChannel.id)
|
|
264
|
-
: null;
|
|
265
|
-
if (!restoredChannel && activeChannelId) {
|
|
266
|
-
restoredChannel = channels.find(ch => ch.id === activeChannelId);
|
|
267
|
-
}
|
|
268
|
-
if (!restoredChannel) {
|
|
269
|
-
restoredChannel = getBestChannelForRestore();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (restoredChannel) {
|
|
273
|
-
updateClaudeSettings(restoredChannel.baseUrl, restoredChannel.apiKey);
|
|
274
|
-
console.log(`✅ Restored settings to best channel: ${restoredChannel.name}`);
|
|
269
|
+
) || null;
|
|
275
270
|
}
|
|
276
271
|
}
|
|
277
272
|
|
|
@@ -283,7 +278,7 @@ router.post('/stop', async (req, res) => {
|
|
|
283
278
|
}
|
|
284
279
|
|
|
285
280
|
// 3. 删除备份文件和active-channel.json
|
|
286
|
-
if (
|
|
281
|
+
if (hadBackup && !restoredChannel) {
|
|
287
282
|
const backupPath = NATIVE_PATHS.claude.settingsBackup;
|
|
288
283
|
if (fs.existsSync(backupPath)) {
|
|
289
284
|
fs.unlinkSync(backupPath);
|
package/src/server/api/skills.js
CHANGED
|
@@ -25,6 +25,22 @@ function getSkillService(req) {
|
|
|
25
25
|
return { platform, service: skillServices.get(platform) };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function extractRepoPayload(source = {}) {
|
|
29
|
+
const repo = source.repo && typeof source.repo === 'object' ? source.repo : source;
|
|
30
|
+
return {
|
|
31
|
+
id: repo.id || source.repoId || '',
|
|
32
|
+
provider: repo.provider || source.provider || '',
|
|
33
|
+
host: repo.host || source.host || '',
|
|
34
|
+
owner: repo.owner || source.owner || '',
|
|
35
|
+
name: repo.name || source.name || '',
|
|
36
|
+
branch: repo.branch || source.branch || 'main',
|
|
37
|
+
directory: repo.directory || source.directory || '',
|
|
38
|
+
projectPath: repo.projectPath || source.projectPath || '',
|
|
39
|
+
localPath: repo.localPath || source.localPath || '',
|
|
40
|
+
repoUrl: repo.repoUrl || source.repoUrl || ''
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
/**
|
|
29
45
|
* 获取技能列表
|
|
30
46
|
* GET /api/skills
|
|
@@ -66,7 +82,9 @@ router.get('/detail/*', async (req, res) => {
|
|
|
66
82
|
});
|
|
67
83
|
}
|
|
68
84
|
|
|
69
|
-
const
|
|
85
|
+
const repoHint = extractRepoPayload(req.query || {});
|
|
86
|
+
const hasRepoHint = Object.values(repoHint).some(Boolean);
|
|
87
|
+
const result = await service.getSkillDetail(directory, hasRepoHint ? repoHint : null, req.query.fullDirectory || '');
|
|
70
88
|
res.json({
|
|
71
89
|
success: true,
|
|
72
90
|
platform,
|
|
@@ -106,7 +124,7 @@ router.get('/installed', (req, res) => {
|
|
|
106
124
|
/**
|
|
107
125
|
* 安装技能
|
|
108
126
|
* POST /api/skills/install
|
|
109
|
-
* Body: { directory, fullDirectory, repo
|
|
127
|
+
* Body: { directory, fullDirectory, repo }
|
|
110
128
|
* - directory: 本地安装目录(相对路径)
|
|
111
129
|
* - fullDirectory: 仓库中的完整路径(当指定了仓库子目录时使用)
|
|
112
130
|
*/
|
|
@@ -122,7 +140,7 @@ router.post('/install', async (req, res) => {
|
|
|
122
140
|
});
|
|
123
141
|
}
|
|
124
142
|
|
|
125
|
-
if (!repo
|
|
143
|
+
if (!repo) {
|
|
126
144
|
return res.status(400).json({
|
|
127
145
|
success: false,
|
|
128
146
|
message: 'Missing repo info'
|
|
@@ -131,11 +149,7 @@ router.post('/install', async (req, res) => {
|
|
|
131
149
|
|
|
132
150
|
const result = await service.installSkill(
|
|
133
151
|
directory,
|
|
134
|
-
{
|
|
135
|
-
owner: repo.owner,
|
|
136
|
-
name: repo.name,
|
|
137
|
-
branch: repo.branch || 'main'
|
|
138
|
-
},
|
|
152
|
+
extractRepoPayload({ repo }),
|
|
139
153
|
fullDirectory || null // 传递 fullDirectory 用于从仓库子目录下载
|
|
140
154
|
);
|
|
141
155
|
|
|
@@ -153,6 +167,28 @@ router.post('/install', async (req, res) => {
|
|
|
153
167
|
}
|
|
154
168
|
});
|
|
155
169
|
|
|
170
|
+
/**
|
|
171
|
+
* 安装本地 cc-tool 托管的技能
|
|
172
|
+
* POST /api/skills/install-local
|
|
173
|
+
* Body: { directory }
|
|
174
|
+
*/
|
|
175
|
+
router.post('/install-local', (req, res) => {
|
|
176
|
+
try {
|
|
177
|
+
const { platform, service } = getSkillService(req);
|
|
178
|
+
const { directory } = req.body;
|
|
179
|
+
|
|
180
|
+
if (!directory) {
|
|
181
|
+
return res.status(400).json({ success: false, message: 'Missing directory' });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const result = service.installLocalSkill(directory);
|
|
185
|
+
res.json({ success: true, platform, ...result });
|
|
186
|
+
} catch (err) {
|
|
187
|
+
console.error('[Skills API] Install local skill error:', err);
|
|
188
|
+
res.status(500).json({ success: false, message: err.message });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
156
192
|
/**
|
|
157
193
|
* 创建自定义技能
|
|
158
194
|
* POST /api/skills/create
|
|
@@ -264,22 +300,23 @@ router.get('/repos', (req, res) => {
|
|
|
264
300
|
/**
|
|
265
301
|
* 添加仓库
|
|
266
302
|
* POST /api/skills/repos
|
|
267
|
-
* Body: { owner, name, branch, directory, enabled }
|
|
303
|
+
* Body: { provider, owner, name, host, projectPath, localPath, branch, directory, enabled }
|
|
268
304
|
* - directory: 可选,指定扫描的子目录路径
|
|
269
305
|
*/
|
|
270
306
|
router.post('/repos', (req, res) => {
|
|
271
307
|
try {
|
|
272
308
|
const { platform, service } = getSkillService(req);
|
|
273
|
-
const
|
|
309
|
+
const repo = extractRepoPayload(req.body);
|
|
310
|
+
repo.enabled = req.body.enabled !== false;
|
|
274
311
|
|
|
275
|
-
if (!owner || !name) {
|
|
312
|
+
if (!repo.localPath && !repo.projectPath && (!repo.owner || !repo.name)) {
|
|
276
313
|
return res.status(400).json({
|
|
277
314
|
success: false,
|
|
278
|
-
message: 'Missing
|
|
315
|
+
message: 'Missing repo info'
|
|
279
316
|
});
|
|
280
317
|
}
|
|
281
318
|
|
|
282
|
-
const repos = service.addRepo(
|
|
319
|
+
const repos = service.addRepo(repo);
|
|
283
320
|
|
|
284
321
|
res.json({
|
|
285
322
|
success: true,
|
|
@@ -295,6 +332,47 @@ router.post('/repos', (req, res) => {
|
|
|
295
332
|
}
|
|
296
333
|
});
|
|
297
334
|
|
|
335
|
+
router.delete('/repos', (req, res) => {
|
|
336
|
+
try {
|
|
337
|
+
const { platform, service } = getSkillService(req);
|
|
338
|
+
const { id = '', owner = '', name = '', directory = '' } = req.query;
|
|
339
|
+
const repos = service.removeRepo(owner, name, directory, id);
|
|
340
|
+
|
|
341
|
+
res.json({
|
|
342
|
+
success: true,
|
|
343
|
+
platform,
|
|
344
|
+
repos
|
|
345
|
+
});
|
|
346
|
+
} catch (err) {
|
|
347
|
+
console.error('[Skills API] Remove repo error:', err);
|
|
348
|
+
res.status(500).json({
|
|
349
|
+
success: false,
|
|
350
|
+
message: err.message
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
router.put('/repos/toggle', (req, res) => {
|
|
356
|
+
try {
|
|
357
|
+
const { platform, service } = getSkillService(req);
|
|
358
|
+
const { id = '', owner = '', name = '', enabled, directory = '' } = req.body;
|
|
359
|
+
|
|
360
|
+
const repos = service.toggleRepo(owner, name, directory, enabled, id);
|
|
361
|
+
|
|
362
|
+
res.json({
|
|
363
|
+
success: true,
|
|
364
|
+
platform,
|
|
365
|
+
repos
|
|
366
|
+
});
|
|
367
|
+
} catch (err) {
|
|
368
|
+
console.error('[Skills API] Toggle repo error:', err);
|
|
369
|
+
res.status(500).json({
|
|
370
|
+
success: false,
|
|
371
|
+
message: err.message
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
298
376
|
/**
|
|
299
377
|
* 删除仓库
|
|
300
378
|
* DELETE /api/skills/repos/:owner/:name
|
|
@@ -11,7 +11,7 @@ const { resolveModelPricing } = require('./utils/pricing');
|
|
|
11
11
|
const { recordRequest: recordCodexRequest } = require('./services/codex-statistics-service');
|
|
12
12
|
const { saveProxyStartTime, clearProxyStartTime, getProxyStartTime, getProxyRuntime } = require('./services/proxy-runtime');
|
|
13
13
|
const { createDecodedStream } = require('./services/response-decoder');
|
|
14
|
-
const {
|
|
14
|
+
const { getEffectiveApiKey } = require('./services/codex-channels');
|
|
15
15
|
const { persistProxyRequestSnapshot } = require('./services/request-logger');
|
|
16
16
|
|
|
17
17
|
let proxyServer = null;
|
|
@@ -585,16 +585,6 @@ async function startCodexProxyServer(options = {}) {
|
|
|
585
585
|
// 保存代理启动时间(如果是切换渠道,保留原有启动时间)
|
|
586
586
|
saveProxyStartTime('codex', preserveStartTime);
|
|
587
587
|
|
|
588
|
-
// 启动代理时同步配置到 Codex 的 config.toml
|
|
589
|
-
try {
|
|
590
|
-
const enabledChannels = getEnabledChannels();
|
|
591
|
-
if (enabledChannels.length > 0) {
|
|
592
|
-
writeCodexConfigForMultiChannel(enabledChannels);
|
|
593
|
-
}
|
|
594
|
-
} catch (err) {
|
|
595
|
-
// ignore sync error
|
|
596
|
-
}
|
|
597
|
-
|
|
598
588
|
resolve({ success: true, port });
|
|
599
589
|
});
|
|
600
590
|
|
package/src/server/index.js
CHANGED
|
@@ -5,7 +5,13 @@ const inquirer = require('inquirer');
|
|
|
5
5
|
const { loadConfig } = require('../config/loader');
|
|
6
6
|
const { PATHS, ensureStorageDirMigrated } = require('../config/paths');
|
|
7
7
|
const { startWebSocketServer: attachWebSocketServer } = require('./websocket-server');
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
isPortInUse,
|
|
10
|
+
killProcessByPort,
|
|
11
|
+
waitForPortRelease,
|
|
12
|
+
getPortToolIssue,
|
|
13
|
+
formatPortToolIssue
|
|
14
|
+
} = require('../utils/port-helper');
|
|
9
15
|
const { isProxyConfig } = require('./services/settings-manager');
|
|
10
16
|
const {
|
|
11
17
|
isProxyConfig: isCodexProxyConfig,
|
|
@@ -35,6 +41,18 @@ function printPortConflictHelp(port) {
|
|
|
35
41
|
console.log(chalk.gray(` 2. 或手动关闭占用端口 ${port} 的程序\n`));
|
|
36
42
|
}
|
|
37
43
|
|
|
44
|
+
function printPortToolIssue(issue = getPortToolIssue()) {
|
|
45
|
+
const lines = formatPortToolIssue(issue);
|
|
46
|
+
if (lines.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.error(chalk.yellow(`\n💡 ${lines[0]}`));
|
|
51
|
+
lines.slice(1).forEach((line) => {
|
|
52
|
+
console.error(chalk.gray(` ${line}`));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
async function startServer(port, host = '127.0.0.1', options = {}) {
|
|
39
57
|
ensureStorageDirMigrated();
|
|
40
58
|
const config = loadConfig();
|
|
@@ -85,7 +103,12 @@ async function startServer(port, host = '127.0.0.1', options = {}) {
|
|
|
85
103
|
const killed = killProcessByPort(port);
|
|
86
104
|
|
|
87
105
|
if (!killed) {
|
|
88
|
-
|
|
106
|
+
const toolIssue = getPortToolIssue();
|
|
107
|
+
if (toolIssue) {
|
|
108
|
+
printPortToolIssue(toolIssue);
|
|
109
|
+
} else {
|
|
110
|
+
console.error(chalk.red('\n❌ 无法关闭占用端口的进程'));
|
|
111
|
+
}
|
|
89
112
|
console.error(chalk.yellow('\n💡 请手动关闭占用端口的程序,或使用其他端口\n'));
|
|
90
113
|
process.exit(1);
|
|
91
114
|
}
|
|
@@ -194,6 +217,7 @@ async function startServer(port, host = '127.0.0.1', options = {}) {
|
|
|
194
217
|
|
|
195
218
|
// 配置导出/导入 API
|
|
196
219
|
app.use('/api/config-export', require('./api/config-export'));
|
|
220
|
+
app.use('/api/oauth-credentials', require('./api/oauth-credentials'));
|
|
197
221
|
|
|
198
222
|
// 配置同步 API
|
|
199
223
|
app.use('/api/config-sync', require('./api/config-sync'));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { isProxyConfig } = require('./settings-manager');
|
|
3
3
|
const { PATHS, NATIVE_PATHS } = require('../../config/paths');
|
|
4
|
+
const { clearNativeOAuth } = require('./native-oauth-adapters');
|
|
4
5
|
|
|
5
6
|
function getChannelsFilePath() {
|
|
6
7
|
const dir = PATHS.base;
|
|
@@ -165,11 +166,13 @@ function getCurrentSettings() {
|
|
|
165
166
|
return null;
|
|
166
167
|
}
|
|
167
168
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
169
|
+
const nativeOAuth = require('./native-oauth-adapters').readNativeOAuth('claude');
|
|
168
170
|
|
|
169
171
|
let baseUrl = settings.env?.ANTHROPIC_BASE_URL || '';
|
|
170
|
-
let apiKey = settings.env?.ANTHROPIC_API_KEY ||
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
let apiKey = settings.env?.ANTHROPIC_API_KEY || '';
|
|
173
|
+
if (!apiKey && !nativeOAuth) {
|
|
174
|
+
apiKey = settings.env?.ANTHROPIC_AUTH_TOKEN || '';
|
|
175
|
+
}
|
|
173
176
|
|
|
174
177
|
if (!apiKey && settings.apiKeyHelper) {
|
|
175
178
|
apiKey = extractApiKeyFromHelper(settings.apiKeyHelper);
|
|
@@ -288,14 +291,6 @@ function updateChannel(id, updates) {
|
|
|
288
291
|
console.log(`[Single-channel mode] Enabled "${nextChannel.name}", disabled all others`);
|
|
289
292
|
}
|
|
290
293
|
|
|
291
|
-
// Prevent disabling last enabled channel when proxy is OFF
|
|
292
|
-
if (!isProxyRunning && !nextChannel.enabled && oldChannel.enabled) {
|
|
293
|
-
const enabledCount = data.channels.filter(ch => ch.enabled).length;
|
|
294
|
-
if (enabledCount === 0) {
|
|
295
|
-
throw new Error('无法禁用最后一个启用的渠道。请先启用其他渠道或启动动态切换。');
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
294
|
saveChannels(data);
|
|
300
295
|
|
|
301
296
|
// Sync settings.json only when proxy is OFF.
|
|
@@ -341,6 +336,7 @@ function applyChannelToSettings(id) {
|
|
|
341
336
|
}
|
|
342
337
|
|
|
343
338
|
function updateClaudeSettingsWithModelConfig(channel) {
|
|
339
|
+
clearNativeOAuth('claude');
|
|
344
340
|
const settingsPath = getClaudeSettingsPath();
|
|
345
341
|
|
|
346
342
|
let settings = {};
|
|
@@ -354,17 +350,10 @@ function updateClaudeSettingsWithModelConfig(channel) {
|
|
|
354
350
|
|
|
355
351
|
const { baseUrl, apiKey, modelConfig, presetId, proxyUrl } = channel;
|
|
356
352
|
|
|
357
|
-
const useAuthToken = settings.env.ANTHROPIC_AUTH_TOKEN !== undefined;
|
|
358
|
-
const useApiKey = settings.env.ANTHROPIC_API_KEY !== undefined;
|
|
359
|
-
|
|
360
353
|
settings.env.ANTHROPIC_BASE_URL = baseUrl;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
delete settings.env.ANTHROPIC_API_KEY;
|
|
365
|
-
} else {
|
|
366
|
-
settings.env.ANTHROPIC_API_KEY = apiKey;
|
|
367
|
-
}
|
|
354
|
+
settings.env.ANTHROPIC_API_KEY = apiKey;
|
|
355
|
+
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
356
|
+
delete settings.env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
368
357
|
|
|
369
358
|
if (presetId && presetId !== 'official' && modelConfig) {
|
|
370
359
|
if (modelConfig.model) {
|
|
@@ -433,6 +422,12 @@ function getEffectiveApiKey(channel) {
|
|
|
433
422
|
return channel.apiKey || null;
|
|
434
423
|
}
|
|
435
424
|
|
|
425
|
+
function disableAllChannels() {
|
|
426
|
+
const data = loadChannels();
|
|
427
|
+
data.channels.forEach(ch => { ch.enabled = false; });
|
|
428
|
+
saveChannels(data);
|
|
429
|
+
}
|
|
430
|
+
|
|
436
431
|
module.exports = {
|
|
437
432
|
getAllChannels,
|
|
438
433
|
getCurrentChannel,
|
|
@@ -444,5 +439,6 @@ module.exports = {
|
|
|
444
439
|
getBestChannelForRestore,
|
|
445
440
|
updateClaudeSettings,
|
|
446
441
|
updateClaudeSettingsWithModelConfig,
|
|
447
|
-
getEffectiveApiKey
|
|
442
|
+
getEffectiveApiKey,
|
|
443
|
+
disableAllChannels
|
|
448
444
|
};
|