yymaxapi 1.0.64 → 1.0.66
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 +38 -34
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -634,8 +634,9 @@ function writeClaudeCodeSettings(baseUrl, apiKey) {
|
|
|
634
634
|
// 写入 shell 环境变量
|
|
635
635
|
if (process.platform === 'win32') {
|
|
636
636
|
try {
|
|
637
|
+
const cleanUrl = baseUrl.replace(/\/+$/, '');
|
|
637
638
|
execSync(
|
|
638
|
-
`powershell -NoProfile -Command "[Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL','${
|
|
639
|
+
`powershell -NoProfile -Command "[Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL','${cleanUrl}','User'); [Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN','${apiKey}','User'); [Environment]::SetEnvironmentVariable('NODE_TLS_REJECT_UNAUTHORIZED','0','User')"`,
|
|
639
640
|
{ stdio: 'pipe' }
|
|
640
641
|
);
|
|
641
642
|
} catch { /* best-effort */ }
|
|
@@ -643,7 +644,14 @@ function writeClaudeCodeSettings(baseUrl, apiKey) {
|
|
|
643
644
|
const marker = '# >>> yymaxapi claude >>>';
|
|
644
645
|
const markerEnd = '# <<< yymaxapi claude <<<';
|
|
645
646
|
const cleanUrl = baseUrl.replace(/\/+$/, '');
|
|
646
|
-
const block = [
|
|
647
|
+
const block = [
|
|
648
|
+
marker,
|
|
649
|
+
`export ANTHROPIC_BASE_URL="${cleanUrl}"`,
|
|
650
|
+
`export ANTHROPIC_AUTH_TOKEN="${apiKey}"`,
|
|
651
|
+
'# 中转站证书校验放宽,避免 unknown certificate verification error',
|
|
652
|
+
'export NODE_TLS_REJECT_UNAUTHORIZED=0',
|
|
653
|
+
markerEnd
|
|
654
|
+
].join('\n');
|
|
647
655
|
|
|
648
656
|
const shellEnv = process.env.SHELL || '';
|
|
649
657
|
const rcFiles = [];
|
|
@@ -721,26 +729,36 @@ function writeOpencodeConfig(claudeBaseUrl, codexBaseUrl, apiKey, modelId) {
|
|
|
721
729
|
const configDir = process.platform === 'win32'
|
|
722
730
|
? path.join(process.env.APPDATA || path.join(home, 'AppData', 'Roaming'), 'opencode')
|
|
723
731
|
: path.join(home, '.config', 'opencode');
|
|
724
|
-
const configPath = path.join(configDir, '
|
|
732
|
+
const configPath = path.join(configDir, 'opencode.json');
|
|
725
733
|
try {
|
|
726
734
|
if (!fs.existsSync(configDir)) fs.mkdirSync(configDir, { recursive: true });
|
|
735
|
+
let existing = {};
|
|
736
|
+
if (fs.existsSync(configPath)) {
|
|
737
|
+
try { existing = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch { existing = {}; }
|
|
738
|
+
}
|
|
727
739
|
const cleanClaudeUrl = claudeBaseUrl.replace(/\/+$/, '');
|
|
728
740
|
let cleanCodexUrl = (codexBaseUrl || '').replace(/\/+$/, '');
|
|
729
|
-
if (
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
741
|
+
if (!existing.provider) existing.provider = {};
|
|
742
|
+
existing.provider.anthropic = {
|
|
743
|
+
options: {
|
|
744
|
+
apiKey: apiKey,
|
|
745
|
+
baseURL: cleanClaudeUrl
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
if (cleanCodexUrl) {
|
|
749
|
+
existing.provider.openai = {
|
|
750
|
+
options: {
|
|
737
751
|
apiKey: apiKey,
|
|
738
|
-
baseURL: cleanCodexUrl
|
|
752
|
+
baseURL: cleanCodexUrl
|
|
739
753
|
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
const rawModelId = modelId || 'claude-sonnet-4-6';
|
|
757
|
+
existing.model = rawModelId.startsWith('anthropic/') || rawModelId.startsWith('openai/')
|
|
758
|
+
? rawModelId
|
|
759
|
+
: `anthropic/${rawModelId}`;
|
|
760
|
+
if (!existing.$schema) existing.$schema = 'https://opencode.ai/config.json';
|
|
761
|
+
fs.writeFileSync(configPath, JSON.stringify(existing, null, 2), 'utf8');
|
|
744
762
|
return configPath;
|
|
745
763
|
} catch {
|
|
746
764
|
return null;
|
|
@@ -2767,6 +2785,8 @@ async function autoActivate(paths, args = {}) {
|
|
|
2767
2785
|
console.log(chalk.gray(` 节点: ${selectedEndpoint.url} (${selectedEndpoint.name})`));
|
|
2768
2786
|
console.log(chalk.gray(' API Key: 已设置'));
|
|
2769
2787
|
if (extSynced.length > 0) console.log(chalk.gray(` 同步: ${extSynced.join(', ')}`));
|
|
2788
|
+
console.log(chalk.gray(' 若遇 certificate 报错,请新开终端或执行 source ~/.zshrc 后重试(已放宽 TLS 校验)'));
|
|
2789
|
+
console.log(chalk.gray(' 使用 OpenCode 时可在界面中切换 Claude Sonnet 4.6 / GPT 5.4;Codex 仅支持 GPT'));
|
|
2770
2790
|
|
|
2771
2791
|
const gwPort = config.gateway?.port || 18789;
|
|
2772
2792
|
const gwToken = config.gateway?.auth?.token;
|
|
@@ -3691,24 +3711,8 @@ async function testConnection(paths, args = {}) {
|
|
|
3691
3711
|
// 检查当前激活的是哪个
|
|
3692
3712
|
let primary = config.agents?.defaults?.model?.primary || '';
|
|
3693
3713
|
if (!primary.includes('/')) {
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
const providerNames = Object.keys(providers);
|
|
3697
|
-
if (providerNames.length === 0) {
|
|
3698
|
-
console.log(chalk.yellow('⚠️ 请先设置主模型'));
|
|
3699
|
-
return;
|
|
3700
|
-
}
|
|
3701
|
-
const preferOrder = ['maxapi', 'heibai', 'claude-yunyi', 'yunyi', 'maxapi-codex'];
|
|
3702
|
-
const preferred = preferOrder.find(n => providerNames.includes(n));
|
|
3703
|
-
const firstP = preferred || providerNames.find(n => n.includes('claude')) || providerNames[0];
|
|
3704
|
-
const firstModels = providers[firstP]?.models || [];
|
|
3705
|
-
if (firstModels.length > 0) {
|
|
3706
|
-
primary = `${firstP}/${firstModels[0].id}`;
|
|
3707
|
-
console.log(chalk.yellow(`⚠️ 主模型未设置,自动使用: ${primary}`));
|
|
3708
|
-
} else {
|
|
3709
|
-
console.log(chalk.yellow('⚠️ 请先设置主模型'));
|
|
3710
|
-
return;
|
|
3711
|
-
}
|
|
3714
|
+
console.log(chalk.yellow('⚠️ 主模型未设置,请先通过「切换模型」或「一键配置」设置主模型'));
|
|
3715
|
+
return;
|
|
3712
3716
|
}
|
|
3713
3717
|
|
|
3714
3718
|
const providerName = primary.split('/')[0];
|