coding-tool-x 3.4.6 → 3.4.7
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
package/src/reset-config.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { PATHS, NATIVE_PATHS, ensureStorageDirMigrated } = require('./config/paths');
|
|
3
|
+
const { isWindowsLikePlatform } = require('./utils/home-dir');
|
|
4
|
+
|
|
5
|
+
function buildEchoCommand(value) {
|
|
6
|
+
if (isWindowsLikePlatform(process.platform, process.env)) {
|
|
7
|
+
return `cmd /c echo ${value}`;
|
|
8
|
+
}
|
|
9
|
+
return `echo '${value}'`;
|
|
10
|
+
}
|
|
3
11
|
|
|
4
12
|
// 恢复配置到默认状态
|
|
5
13
|
async function resetConfig() {
|
|
@@ -56,7 +64,7 @@ async function resetConfig() {
|
|
|
56
64
|
if (!settings.env) settings.env = {};
|
|
57
65
|
settings.env.ANTHROPIC_BASE_URL = activeChannel.baseUrl;
|
|
58
66
|
settings.env.ANTHROPIC_API_KEY = activeChannel.apiKey;
|
|
59
|
-
settings.apiKeyHelper =
|
|
67
|
+
settings.apiKeyHelper = buildEchoCommand(activeChannel.apiKey);
|
|
60
68
|
|
|
61
69
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
62
70
|
console.log(`[OK] 已恢复到渠道: ${activeChannel.name}`);
|
package/src/server/api/proxy.js
CHANGED
|
@@ -107,34 +107,32 @@ function findActiveChannelFromSettings() {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
if (!baseUrl || !apiKey || baseUrl.includes('127.0.0.1')) {
|
|
111
|
-
console.log('[Proxy] Invalid settings: empty baseUrl/apiKey or localhost detected');
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
110
|
const channels = getAllChannels();
|
|
116
111
|
|
|
117
112
|
// Level 1: Exact match (baseUrl + apiKey)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
if (baseUrl && apiKey && !baseUrl.includes('127.0.0.1')) {
|
|
114
|
+
let matchingChannel = channels.find(ch =>
|
|
115
|
+
ch.baseUrl === baseUrl && ch.apiKey === apiKey
|
|
116
|
+
);
|
|
117
|
+
if (matchingChannel) {
|
|
118
|
+
console.log(`[Proxy] Level 1 - Exact match: ${matchingChannel.name}`);
|
|
119
|
+
return matchingChannel;
|
|
120
|
+
}
|
|
126
121
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
// Level 2: Match by baseUrl only (when apiKey differs)
|
|
123
|
+
matchingChannel = channels.find(ch => ch.baseUrl === baseUrl);
|
|
124
|
+
if (matchingChannel) {
|
|
125
|
+
console.log(`[Proxy] Level 2 - Matched by baseUrl only: ${matchingChannel.name}`);
|
|
126
|
+
return matchingChannel;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
console.log('[Proxy] settings.json has no valid baseUrl/apiKey, falling back to channel list');
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
// Level 3: Use active-channel.json for last known active channel
|
|
135
133
|
const activeChannelId = loadActiveChannelId();
|
|
136
134
|
if (activeChannelId) {
|
|
137
|
-
matchingChannel = channels.find(ch => ch.id === activeChannelId);
|
|
135
|
+
const matchingChannel = channels.find(ch => ch.id === activeChannelId);
|
|
138
136
|
if (matchingChannel) {
|
|
139
137
|
console.log(`[Proxy] Level 3 - Using last active channel: ${matchingChannel.name}`);
|
|
140
138
|
return matchingChannel;
|
|
@@ -142,10 +140,10 @@ function findActiveChannelFromSettings() {
|
|
|
142
140
|
}
|
|
143
141
|
|
|
144
142
|
// Level 4: Return first enabled channel as last resort
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
console.log(`[Proxy] Level 4 - Using first enabled channel: ${
|
|
148
|
-
return
|
|
143
|
+
const fallbackChannel = channels.find(ch => ch.enabled !== false);
|
|
144
|
+
if (fallbackChannel) {
|
|
145
|
+
console.log(`[Proxy] Level 4 - Using first enabled channel: ${fallbackChannel.name}`);
|
|
146
|
+
return fallbackChannel;
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
console.log('[Proxy] No matching channel found after all fallback levels');
|
|
@@ -4,6 +4,7 @@ const BaseChannelService = require('./base/base-channel-service');
|
|
|
4
4
|
const { isProxyConfig } = require('./settings-manager');
|
|
5
5
|
const { PATHS, NATIVE_PATHS } = require('../../config/paths');
|
|
6
6
|
const { clearNativeOAuth } = require('./native-oauth-adapters');
|
|
7
|
+
const { isWindowsLikePlatform } = require('../../utils/home-dir');
|
|
7
8
|
|
|
8
9
|
// ── Claude 特有工具函数 ──
|
|
9
10
|
|
|
@@ -51,7 +52,10 @@ function extractApiKeyFromHelper(apiKeyHelper) {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
function buildApiKeyHelperCommand() {
|
|
54
|
-
|
|
55
|
+
if (isWindowsLikePlatform(process.platform, process.env)) {
|
|
56
|
+
return 'cmd /c echo ctx-managed';
|
|
57
|
+
}
|
|
58
|
+
return "echo 'ctx-managed'";
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
// ── Claude 原生设置写入 ──
|
|
@@ -105,6 +109,10 @@ function updateClaudeSettingsWithModelConfig(channel) {
|
|
|
105
109
|
delete settings.env.NO_PROXY;
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
if (settings.env && Object.keys(settings.env).length === 0) {
|
|
113
|
+
delete settings.env;
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
settings.apiKeyHelper = buildApiKeyHelperCommand();
|
|
109
117
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
110
118
|
}
|
|
@@ -133,6 +141,10 @@ function updateClaudeSettings(baseUrl, apiKey) {
|
|
|
133
141
|
settings.env.ANTHROPIC_API_KEY = apiKey;
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
if (settings.env && Object.keys(settings.env).length === 0) {
|
|
145
|
+
delete settings.env;
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
settings.apiKeyHelper = buildApiKeyHelperCommand();
|
|
137
149
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
138
150
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { NATIVE_PATHS } = require('../../config/paths');
|
|
3
|
+
const { isWindowsLikePlatform } = require('../../utils/home-dir');
|
|
4
|
+
|
|
5
|
+
function buildEchoCommand(value) {
|
|
6
|
+
if (isWindowsLikePlatform(process.platform, process.env)) {
|
|
7
|
+
return `cmd /c echo ${value}`;
|
|
8
|
+
}
|
|
9
|
+
return `echo '${value}'`;
|
|
10
|
+
}
|
|
3
11
|
|
|
4
12
|
// Claude Code 配置文件路径
|
|
5
13
|
function getSettingsPath() {
|
|
@@ -113,7 +121,7 @@ function setProxyConfig(proxyPort) {
|
|
|
113
121
|
// 修改为代理配置(使用 Claude Code 的标准格式)
|
|
114
122
|
settings.env.ANTHROPIC_BASE_URL = `http://127.0.0.1:${proxyPort}`;
|
|
115
123
|
settings.env.ANTHROPIC_API_KEY = 'PROXY_KEY';
|
|
116
|
-
settings.apiKeyHelper =
|
|
124
|
+
settings.apiKeyHelper = buildEchoCommand('PROXY_KEY');
|
|
117
125
|
|
|
118
126
|
// 写入
|
|
119
127
|
writeSettings(settings);
|