yymaxapi 1.0.40 → 1.0.42
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/bin/yymaxapi.js +56 -2
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -608,8 +608,9 @@ function writeConfig(configPath, config) {
|
|
|
608
608
|
// ============ 多工具配置同步 ============
|
|
609
609
|
|
|
610
610
|
function writeClaudeCodeSettings(baseUrl, apiKey) {
|
|
611
|
+
const home = os.homedir();
|
|
611
612
|
// ~/.claude/settings.json
|
|
612
|
-
const claudeDir = path.join(
|
|
613
|
+
const claudeDir = path.join(home, '.claude');
|
|
613
614
|
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
614
615
|
try {
|
|
615
616
|
let settings = {};
|
|
@@ -617,12 +618,15 @@ function writeClaudeCodeSettings(baseUrl, apiKey) {
|
|
|
617
618
|
try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch { settings = {}; }
|
|
618
619
|
}
|
|
619
620
|
settings.apiBaseUrl = baseUrl.replace(/\/+$/, '');
|
|
621
|
+
if (!settings.env) settings.env = {};
|
|
622
|
+
settings.env.ANTHROPIC_BASE_URL = baseUrl.replace(/\/+$/, '');
|
|
623
|
+
settings.env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
|
620
624
|
if (!fs.existsSync(claudeDir)) fs.mkdirSync(claudeDir, { recursive: true });
|
|
621
625
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
622
626
|
} catch { /* 非关键,静默失败 */ }
|
|
623
627
|
|
|
624
628
|
// ~/.claude.json — 跳过 onboarding
|
|
625
|
-
const claudeJsonPath = path.join(
|
|
629
|
+
const claudeJsonPath = path.join(home, '.claude.json');
|
|
626
630
|
try {
|
|
627
631
|
let claudeJson = {};
|
|
628
632
|
if (fs.existsSync(claudeJsonPath)) {
|
|
@@ -633,6 +637,42 @@ function writeClaudeCodeSettings(baseUrl, apiKey) {
|
|
|
633
637
|
fs.writeFileSync(claudeJsonPath, JSON.stringify(claudeJson, null, 2), 'utf8');
|
|
634
638
|
}
|
|
635
639
|
} catch { /* 非关键,静默失败 */ }
|
|
640
|
+
|
|
641
|
+
// 写入 shell 环境变量
|
|
642
|
+
if (process.platform === 'win32') {
|
|
643
|
+
try {
|
|
644
|
+
execSync(
|
|
645
|
+
`powershell -NoProfile -Command "[Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL','${baseUrl.replace(/\/+$/, '')}','User'); [Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN','${apiKey}','User')"`,
|
|
646
|
+
{ stdio: 'pipe' }
|
|
647
|
+
);
|
|
648
|
+
} catch { /* best-effort */ }
|
|
649
|
+
} else {
|
|
650
|
+
const marker = '# >>> yymaxapi claude >>>';
|
|
651
|
+
const markerEnd = '# <<< yymaxapi claude <<<';
|
|
652
|
+
const cleanUrl = baseUrl.replace(/\/+$/, '');
|
|
653
|
+
const block = [marker, `export ANTHROPIC_BASE_URL="${cleanUrl}"`, `export ANTHROPIC_AUTH_TOKEN="${apiKey}"`, markerEnd].join('\n');
|
|
654
|
+
|
|
655
|
+
const shellEnv = process.env.SHELL || '';
|
|
656
|
+
const rcFiles = [];
|
|
657
|
+
if (shellEnv.includes('zsh') || !shellEnv) rcFiles.push(path.join(home, '.zshrc'));
|
|
658
|
+
if (shellEnv.includes('bash') || !shellEnv) rcFiles.push(path.join(home, '.bashrc'));
|
|
659
|
+
if (rcFiles.length === 0) rcFiles.push(path.join(home, '.profile'));
|
|
660
|
+
|
|
661
|
+
for (const rcFile of rcFiles) {
|
|
662
|
+
try {
|
|
663
|
+
let content = '';
|
|
664
|
+
if (fs.existsSync(rcFile)) {
|
|
665
|
+
content = fs.readFileSync(rcFile, 'utf8');
|
|
666
|
+
const re = new RegExp(
|
|
667
|
+
`${marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${markerEnd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`,
|
|
668
|
+
'g'
|
|
669
|
+
);
|
|
670
|
+
content = content.replace(re, '').trimEnd();
|
|
671
|
+
}
|
|
672
|
+
fs.writeFileSync(rcFile, content ? `${content}\n\n${block}\n` : `${block}\n`, 'utf8');
|
|
673
|
+
} catch { /* best-effort */ }
|
|
674
|
+
}
|
|
675
|
+
}
|
|
636
676
|
}
|
|
637
677
|
|
|
638
678
|
function writeCodexConfig(baseUrl, apiKey) {
|
|
@@ -2705,6 +2745,13 @@ async function autoActivate(paths, args = {}) {
|
|
|
2705
2745
|
console.log(chalk.gray(' API Key: 已设置'));
|
|
2706
2746
|
if (extSynced.length > 0) console.log(chalk.gray(` 同步: ${extSynced.join(', ')}`));
|
|
2707
2747
|
|
|
2748
|
+
const gwPort = config.gateway?.port || 18789;
|
|
2749
|
+
const gwToken = config.gateway?.auth?.token;
|
|
2750
|
+
if (gwToken) {
|
|
2751
|
+
console.log(chalk.green(`\n🌐 Web Dashboard:`));
|
|
2752
|
+
console.log(chalk.cyan(` http://localhost:${gwPort}/?token=${gwToken}`));
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2708
2755
|
// ---- 测试连接 ----
|
|
2709
2756
|
const shouldTestGateway = args.test !== undefined
|
|
2710
2757
|
? !['false', '0', 'no'].includes(String(args.test).toLowerCase())
|
|
@@ -3221,6 +3268,13 @@ async function switchModel(paths) {
|
|
|
3221
3268
|
console.log(chalk.green(`\n✅ 已切换到 ${selectedName}`));
|
|
3222
3269
|
console.log(chalk.gray(` ${newPrimary}`));
|
|
3223
3270
|
console.log(chalk.yellow('\n💡 切换后建议重启 Gateway: openclaw gateway restart'));
|
|
3271
|
+
|
|
3272
|
+
const gwPort = config.gateway?.port || 18789;
|
|
3273
|
+
const gwToken = config.gateway?.auth?.token;
|
|
3274
|
+
if (gwToken) {
|
|
3275
|
+
console.log(chalk.green(`\n🌐 Web Dashboard:`));
|
|
3276
|
+
console.log(chalk.cyan(` http://localhost:${gwPort}/?token=${gwToken}`));
|
|
3277
|
+
}
|
|
3224
3278
|
}
|
|
3225
3279
|
// ============ 测试连接 ============
|
|
3226
3280
|
async function testConnection(paths, args = {}) {
|