pumpkinai-config 1.0.20 → 1.3.0
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/claude-api.js +17 -35
- package/claude-fix.js +138 -0
- package/claude-network.js +372 -0
- package/claude-setup.js +17 -35
- package/codex-api.js +1 -19
- package/codex-network.js +307 -0
- package/codex-setup.js +1 -19
- package/main-config.js +371 -0
- package/package.json +5 -8
package/codex-api.js
CHANGED
|
@@ -61,16 +61,6 @@ function getUserInput(question) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// 检查 @openai/codex 是否已安装
|
|
65
|
-
function checkCodexInstalled() {
|
|
66
|
-
try {
|
|
67
|
-
const output = execSync('npm list -g @openai/codex --depth=0', { encoding: 'utf8' });
|
|
68
|
-
return output.includes('@openai/codex');
|
|
69
|
-
} catch (error) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
// 获取 @openai/codex 版本号
|
|
75
65
|
function getCodexVersion() {
|
|
76
66
|
try {
|
|
@@ -87,15 +77,7 @@ function installCodex() {
|
|
|
87
77
|
const osType = getOS();
|
|
88
78
|
let command;
|
|
89
79
|
|
|
90
|
-
log('\n[
|
|
91
|
-
|
|
92
|
-
// 先检查是否已安装
|
|
93
|
-
if (checkCodexInstalled()) {
|
|
94
|
-
log('[成功] @openai/codex 已安装,跳过安装步骤', 'green');
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
log('[安装] 开始安装 @openai/codex...', 'cyan');
|
|
80
|
+
log('\n[安装] 开始安装 @openai/codex...', 'cyan');
|
|
99
81
|
|
|
100
82
|
if (osType === 'windows') {
|
|
101
83
|
command = 'npm install -g @openai/codex --registry https://registry.npmmirror.com';
|
package/codex-network.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Codex 网络修复工具
|
|
5
|
+
* 检测当前域名并允许切换到备用域名
|
|
6
|
+
* 只修改 config.toml 配置文件,不修改环境变量
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
|
|
14
|
+
// 颜色输出
|
|
15
|
+
const colors = {
|
|
16
|
+
red: '\x1b[31m',
|
|
17
|
+
green: '\x1b[32m',
|
|
18
|
+
yellow: '\x1b[33m',
|
|
19
|
+
blue: '\x1b[34m',
|
|
20
|
+
magenta: '\x1b[35m',
|
|
21
|
+
cyan: '\x1b[36m',
|
|
22
|
+
reset: '\x1b[0m',
|
|
23
|
+
dim: '\x1b[2m',
|
|
24
|
+
bright: '\x1b[1m'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function log(message, color = 'reset') {
|
|
28
|
+
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 可用域名列表 (Codex 使用 /v1 后缀)
|
|
32
|
+
const domainOptions = [
|
|
33
|
+
{ name: '主域名', url: 'https://code.ppchat.vip/v1' },
|
|
34
|
+
{ name: '备用域名1', url: 'https://code2.ppchat.vip/v1' },
|
|
35
|
+
{ name: '备用域名2', url: 'https://code.pumpkinai.vip/v1' },
|
|
36
|
+
{ name: '清理DNS缓存-推荐', url: 'dns_flush' }
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// 检测操作系统
|
|
40
|
+
function getOS() {
|
|
41
|
+
const platform = os.platform();
|
|
42
|
+
if (platform === 'win32') return 'windows';
|
|
43
|
+
if (platform === 'darwin') return 'mac';
|
|
44
|
+
return 'linux';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 获取用户目录
|
|
48
|
+
function getHomeDir() {
|
|
49
|
+
if (process.platform !== 'win32' && process.env.SUDO_USER) {
|
|
50
|
+
const actualUser = process.env.SUDO_USER;
|
|
51
|
+
return process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
|
|
52
|
+
}
|
|
53
|
+
return os.homedir();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 获取当前使用的域名 (从 config.toml 读取)
|
|
57
|
+
function getCurrentDomain() {
|
|
58
|
+
const homeDir = getHomeDir();
|
|
59
|
+
const configPath = path.join(homeDir, '.codex', 'config.toml');
|
|
60
|
+
|
|
61
|
+
if (fs.existsSync(configPath)) {
|
|
62
|
+
try {
|
|
63
|
+
const content = fs.readFileSync(configPath, 'utf8');
|
|
64
|
+
// 匹配 base_url = "xxx" 格式
|
|
65
|
+
const match = content.match(/base_url\s*=\s*"([^"]+)"/);
|
|
66
|
+
if (match) {
|
|
67
|
+
return match[1];
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 更新 config.toml 中的域名
|
|
76
|
+
function updateConfigToml(newUrl) {
|
|
77
|
+
const homeDir = getHomeDir();
|
|
78
|
+
const configPath = path.join(homeDir, '.codex', 'config.toml');
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
if (fs.existsSync(configPath)) {
|
|
82
|
+
let content = fs.readFileSync(configPath, 'utf8');
|
|
83
|
+
|
|
84
|
+
// 替换 base_url 的值
|
|
85
|
+
const regex = /base_url\s*=\s*"[^"]+"/;
|
|
86
|
+
if (content.match(regex)) {
|
|
87
|
+
content = content.replace(regex, `base_url = "${newUrl}"`);
|
|
88
|
+
fs.writeFileSync(configPath, content, 'utf8');
|
|
89
|
+
|
|
90
|
+
// 如果是通过 sudo 运行的,修改文件所有者
|
|
91
|
+
if (process.platform !== 'win32' && process.env.SUDO_USER) {
|
|
92
|
+
const actualUser = process.env.SUDO_USER;
|
|
93
|
+
const group = process.platform === 'darwin' ? 'staff' : actualUser;
|
|
94
|
+
try {
|
|
95
|
+
execSync(`chown ${actualUser}:${group} ${configPath}`);
|
|
96
|
+
} catch (error) {}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return true;
|
|
100
|
+
} else {
|
|
101
|
+
log('[警告] config.toml 中未找到 base_url 配置', 'yellow');
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
log('[警告] config.toml 文件不存在,请先运行安装配置', 'yellow');
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
log(`[警告] 更新 config.toml 失败: ${error.message}`, 'yellow');
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 清理 DNS 缓存
|
|
115
|
+
function flushDnsCache() {
|
|
116
|
+
const osType = getOS();
|
|
117
|
+
log('\n[DNS] 正在清理 DNS 缓存...', 'cyan');
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
if (osType === 'windows') {
|
|
121
|
+
execSync('ipconfig /flushdns', { stdio: 'pipe' });
|
|
122
|
+
log('[成功] DNS 缓存已清理 (ipconfig /flushdns)', 'green');
|
|
123
|
+
} else if (osType === 'mac') {
|
|
124
|
+
// macOS 需要 sudo 权限
|
|
125
|
+
const isRoot = process.getuid && process.getuid() === 0;
|
|
126
|
+
if (isRoot) {
|
|
127
|
+
execSync('dscacheutil -flushcache && killall -HUP mDNSResponder', { stdio: 'pipe' });
|
|
128
|
+
} else {
|
|
129
|
+
execSync('sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder', { stdio: 'pipe' });
|
|
130
|
+
}
|
|
131
|
+
log('[成功] DNS 缓存已清理 (dscacheutil -flushcache)', 'green');
|
|
132
|
+
} else {
|
|
133
|
+
// Linux - 不同发行版命令不同,尝试常见的
|
|
134
|
+
const isRoot = process.getuid && process.getuid() === 0;
|
|
135
|
+
try {
|
|
136
|
+
if (isRoot) {
|
|
137
|
+
execSync('systemd-resolve --flush-caches 2>/dev/null || resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
|
|
138
|
+
} else {
|
|
139
|
+
execSync('sudo systemd-resolve --flush-caches 2>/dev/null || sudo resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
|
|
140
|
+
}
|
|
141
|
+
log('[成功] DNS 缓存已清理', 'green');
|
|
142
|
+
} catch (e) {
|
|
143
|
+
log('[提示] DNS 缓存清理命令不适用于此系统,已跳过', 'yellow');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
log(`[警告] DNS 缓存清理失败: ${error.message}`, 'yellow');
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 切换域名
|
|
154
|
+
function switchDomain(newUrl) {
|
|
155
|
+
log(`\n[切换] 正在切换到: ${newUrl}`, 'cyan');
|
|
156
|
+
|
|
157
|
+
// 更新 config.toml
|
|
158
|
+
const configUpdated = updateConfigToml(newUrl);
|
|
159
|
+
if (configUpdated) {
|
|
160
|
+
log('[成功] config.toml 已更新', 'green');
|
|
161
|
+
log('\n[完成] 域名切换成功!', 'green');
|
|
162
|
+
log('[提示] 新域名将在下次启动 Codex 时生效', 'yellow');
|
|
163
|
+
} else {
|
|
164
|
+
log('\n[警告] 配置文件更新失败,请先运行安装配置', 'yellow');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let selectedIndex = 0;
|
|
169
|
+
|
|
170
|
+
// 渲染域名选择菜单
|
|
171
|
+
function renderMenu() {
|
|
172
|
+
console.clear();
|
|
173
|
+
log('\n', 'reset');
|
|
174
|
+
log(' ' + '='.repeat(54), 'cyan');
|
|
175
|
+
log(' Codex 网络修复 - 域名切换', 'magenta');
|
|
176
|
+
log(' ' + '='.repeat(54), 'cyan');
|
|
177
|
+
log('', 'reset');
|
|
178
|
+
|
|
179
|
+
const currentDomain = getCurrentDomain();
|
|
180
|
+
|
|
181
|
+
log(' 请选择要使用的域名 (↑↓选择, Enter确认, ESC返回):\n', 'cyan');
|
|
182
|
+
|
|
183
|
+
domainOptions.forEach((option, index) => {
|
|
184
|
+
const isSelected = index === selectedIndex;
|
|
185
|
+
const prefix = isSelected ? ' ▶ ' : ' ';
|
|
186
|
+
const nameColor = isSelected ? '\x1b[1m\x1b[33m' : '\x1b[0m';
|
|
187
|
+
const numLabel = `${index + 1}. `;
|
|
188
|
+
|
|
189
|
+
// 检查是否是当前使用的域名
|
|
190
|
+
const isCurrent = option.url && currentDomain === option.url;
|
|
191
|
+
const currentIndicator = isCurrent ? ' \x1b[32m← 当前使用\x1b[0m' : '';
|
|
192
|
+
|
|
193
|
+
console.log(`${prefix}${nameColor}${numLabel}${option.name}${currentIndicator}\x1b[0m`);
|
|
194
|
+
if (option.url && option.url !== 'dns_flush') {
|
|
195
|
+
const descColor = isSelected ? '\x1b[36m' : '\x1b[2m';
|
|
196
|
+
console.log(` ${descColor}${option.url}\x1b[0m`);
|
|
197
|
+
}
|
|
198
|
+
console.log('');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
log(' ' + '='.repeat(54), 'cyan');
|
|
202
|
+
|
|
203
|
+
if (currentDomain) {
|
|
204
|
+
log(`\n 当前域名: ${currentDomain}`, 'dim');
|
|
205
|
+
} else {
|
|
206
|
+
log('\n 当前域名: 未配置', 'dim');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 主函数
|
|
211
|
+
async function main() {
|
|
212
|
+
// 启用原始模式以捕获按键
|
|
213
|
+
if (process.stdin.isTTY) {
|
|
214
|
+
process.stdin.setRawMode(true);
|
|
215
|
+
}
|
|
216
|
+
process.stdin.resume();
|
|
217
|
+
process.stdin.setEncoding('utf8');
|
|
218
|
+
|
|
219
|
+
renderMenu();
|
|
220
|
+
|
|
221
|
+
return new Promise((resolve) => {
|
|
222
|
+
const handleKeyPress = (key) => {
|
|
223
|
+
// Ctrl+C 退出
|
|
224
|
+
if (key === '\u0003') {
|
|
225
|
+
console.clear();
|
|
226
|
+
process.exit(0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ESC 返回
|
|
230
|
+
if (key === '\u001b') {
|
|
231
|
+
if (process.stdin.isTTY) {
|
|
232
|
+
process.stdin.setRawMode(false);
|
|
233
|
+
}
|
|
234
|
+
process.stdin.removeAllListeners('data');
|
|
235
|
+
resolve(false);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 上箭头
|
|
240
|
+
if (key === '\u001b[A' || key === 'k') {
|
|
241
|
+
selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : domainOptions.length - 1;
|
|
242
|
+
renderMenu();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 下箭头
|
|
246
|
+
if (key === '\u001b[B' || key === 'j') {
|
|
247
|
+
selectedIndex = selectedIndex < domainOptions.length - 1 ? selectedIndex + 1 : 0;
|
|
248
|
+
renderMenu();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Enter 确认
|
|
252
|
+
if (key === '\r' || key === '\n') {
|
|
253
|
+
const selected = domainOptions[selectedIndex];
|
|
254
|
+
|
|
255
|
+
// 切换域名
|
|
256
|
+
if (process.stdin.isTTY) {
|
|
257
|
+
process.stdin.setRawMode(false);
|
|
258
|
+
}
|
|
259
|
+
process.stdin.removeAllListeners('data');
|
|
260
|
+
|
|
261
|
+
// 根据选项执行不同操作
|
|
262
|
+
if (selected.url === 'dns_flush') {
|
|
263
|
+
flushDnsCache();
|
|
264
|
+
} else {
|
|
265
|
+
switchDomain(selected.url);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 等待用户按键返回
|
|
269
|
+
log('\n按任意键返回菜单...', 'dim');
|
|
270
|
+
|
|
271
|
+
if (process.stdin.isTTY) {
|
|
272
|
+
process.stdin.setRawMode(true);
|
|
273
|
+
}
|
|
274
|
+
process.stdin.resume();
|
|
275
|
+
process.stdin.once('data', () => {
|
|
276
|
+
if (process.stdin.isTTY) {
|
|
277
|
+
process.stdin.setRawMode(false);
|
|
278
|
+
}
|
|
279
|
+
selectedIndex = 0;
|
|
280
|
+
resolve(false);
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 数字键快捷选择
|
|
286
|
+
const num = parseInt(key);
|
|
287
|
+
if (num >= 1 && num <= domainOptions.length) {
|
|
288
|
+
selectedIndex = num - 1;
|
|
289
|
+
renderMenu();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
process.stdin.on('data', handleKeyPress);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 如果直接运行此脚本
|
|
298
|
+
if (require.main === module) {
|
|
299
|
+
main().then(() => {
|
|
300
|
+
process.exit(0);
|
|
301
|
+
}).catch(error => {
|
|
302
|
+
log(`\n[错误] ${error.message}`, 'red');
|
|
303
|
+
process.exit(1);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = { main, getCurrentDomain, switchDomain };
|
package/codex-setup.js
CHANGED
|
@@ -61,16 +61,6 @@ function getUserInput(question) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// 检查 @openai/codex 是否已安装
|
|
65
|
-
function checkCodexInstalled() {
|
|
66
|
-
try {
|
|
67
|
-
const output = execSync('npm list -g @openai/codex --depth=0', { encoding: 'utf8' });
|
|
68
|
-
return output.includes('@openai/codex');
|
|
69
|
-
} catch (error) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
// 获取 @openai/codex 版本号
|
|
75
65
|
function getCodexVersion() {
|
|
76
66
|
try {
|
|
@@ -87,15 +77,7 @@ function installCodex() {
|
|
|
87
77
|
const osType = getOS();
|
|
88
78
|
let command;
|
|
89
79
|
|
|
90
|
-
log('\n[
|
|
91
|
-
|
|
92
|
-
// 先检查是否已安装
|
|
93
|
-
if (checkCodexInstalled()) {
|
|
94
|
-
log('[成功] @openai/codex 已安装,跳过安装步骤', 'green');
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
log('[安装] 开始安装 @openai/codex...', 'cyan');
|
|
80
|
+
log('\n[安装] 开始安装 @openai/codex...', 'cyan');
|
|
99
81
|
|
|
100
82
|
if (osType === 'windows') {
|
|
101
83
|
command = 'npm install -g @openai/codex --registry https://registry.npmmirror.com';
|