yymaxapi 1.0.41 → 1.0.43

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.
Files changed (2) hide show
  1. package/bin/yymaxapi.js +44 -4
  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(os.homedir(), '.claude');
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(os.homedir(), '.claude.json');
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) {
@@ -2830,8 +2870,8 @@ async function yycodeQuickSetup(paths) {
2830
2870
 
2831
2871
  // Claude 侧
2832
2872
  const claudeBaseUrl = buildFullUrl(selectedEndpoint.url, 'claude');
2833
- const claudeModelId = 'claude-opus-4-6';
2834
- const claudeModel = CLAUDE_MODELS.find(m => m.id === claudeModelId) || { id: claudeModelId, name: 'Claude Opus 4.6' };
2873
+ const claudeModelId = 'claude-sonnet-4-6';
2874
+ const claudeModel = CLAUDE_MODELS.find(m => m.id === claudeModelId) || { id: claudeModelId, name: 'Claude Sonnet 4.6' };
2835
2875
  const claudeModelKey = `${claudeProviderName}/${claudeModelId}`;
2836
2876
 
2837
2877
  config.models.providers[claudeProviderName] = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {