yymaxapi 1.0.64 → 1.0.65

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 +24 -13
  2. package/package.json +1 -1
package/bin/yymaxapi.js CHANGED
@@ -721,26 +721,37 @@ function writeOpencodeConfig(claudeBaseUrl, codexBaseUrl, apiKey, modelId) {
721
721
  const configDir = process.platform === 'win32'
722
722
  ? path.join(process.env.APPDATA || path.join(home, 'AppData', 'Roaming'), 'opencode')
723
723
  : path.join(home, '.config', 'opencode');
724
- const configPath = path.join(configDir, 'config.json');
724
+ const configPath = path.join(configDir, 'opencode.json');
725
725
  try {
726
726
  if (!fs.existsSync(configDir)) fs.mkdirSync(configDir, { recursive: true });
727
+ let existing = {};
728
+ if (fs.existsSync(configPath)) {
729
+ try { existing = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch { existing = {}; }
730
+ }
727
731
  const cleanClaudeUrl = claudeBaseUrl.replace(/\/+$/, '');
728
732
  let cleanCodexUrl = (codexBaseUrl || '').replace(/\/+$/, '');
729
733
  if (cleanCodexUrl && !cleanCodexUrl.endsWith('/v1')) cleanCodexUrl += '/v1';
730
- const config = {
731
- provider: {
732
- anthropic: {
733
- apiKey: apiKey,
734
- baseURL: cleanClaudeUrl
735
- },
736
- openai: {
734
+ if (!existing.provider) existing.provider = {};
735
+ existing.provider.anthropic = {
736
+ options: {
737
+ apiKey: apiKey,
738
+ baseURL: cleanClaudeUrl
739
+ }
740
+ };
741
+ if (cleanCodexUrl) {
742
+ existing.provider.openai = {
743
+ options: {
737
744
  apiKey: apiKey,
738
- baseURL: cleanCodexUrl || cleanClaudeUrl
745
+ baseURL: cleanCodexUrl
739
746
  }
740
- },
741
- model: modelId || 'claude-sonnet-4-6'
742
- };
743
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8');
747
+ };
748
+ }
749
+ const rawModelId = modelId || 'claude-sonnet-4-6';
750
+ existing.model = rawModelId.startsWith('anthropic/') || rawModelId.startsWith('openai/')
751
+ ? rawModelId
752
+ : `anthropic/${rawModelId}`;
753
+ if (!existing.$schema) existing.$schema = 'https://opencode.ai/config.json';
754
+ fs.writeFileSync(configPath, JSON.stringify(existing, null, 2), 'utf8');
744
755
  return configPath;
745
756
  } catch {
746
757
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.64",
3
+ "version": "1.0.65",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {