yymaxapi 1.0.70 → 1.0.71
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 +28 -5
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -1795,6 +1795,25 @@ function ensureGatewaySettings(config) {
|
|
|
1795
1795
|
|
|
1796
1796
|
}
|
|
1797
1797
|
|
|
1798
|
+
// 清理冲突的 env.vars(避免 OPENAI_API_KEY/OPENAI_BASE_URL 指向其他服务商导致 401)
|
|
1799
|
+
function cleanupConflictingEnvVars(config, codexBaseUrl, apiKey) {
|
|
1800
|
+
if (!config.env?.vars) return;
|
|
1801
|
+
const vars = config.env.vars;
|
|
1802
|
+
// 如果 OPENAI_API_KEY 存在且不是我们的 key,清掉
|
|
1803
|
+
if (vars.OPENAI_API_KEY && vars.OPENAI_API_KEY !== apiKey) {
|
|
1804
|
+
delete vars.OPENAI_API_KEY;
|
|
1805
|
+
}
|
|
1806
|
+
// 如果 OPENAI_BASE_URL 存在且不是我们的地址,清掉
|
|
1807
|
+
if (vars.OPENAI_BASE_URL && codexBaseUrl && !vars.OPENAI_BASE_URL.includes(new URL(codexBaseUrl).hostname)) {
|
|
1808
|
+
delete vars.OPENAI_BASE_URL;
|
|
1809
|
+
}
|
|
1810
|
+
// 如果 vars 空了,清掉整个 env 节点
|
|
1811
|
+
if (Object.keys(vars).length === 0) {
|
|
1812
|
+
delete config.env.vars;
|
|
1813
|
+
if (config.env && Object.keys(config.env).length === 0) delete config.env;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1798
1817
|
function isPortOpen(port, host = '127.0.0.1', timeoutMs = 800) {
|
|
1799
1818
|
return new Promise((resolve) => {
|
|
1800
1819
|
const socket = new net.Socket();
|
|
@@ -2284,7 +2303,7 @@ async function quickSetup(paths, args = {}) {
|
|
|
2284
2303
|
auth: DEFAULT_AUTH_MODE,
|
|
2285
2304
|
api: apiConfig.api,
|
|
2286
2305
|
headers: {},
|
|
2287
|
-
authHeader:
|
|
2306
|
+
authHeader: apiConfig.api.startsWith('openai'),
|
|
2288
2307
|
apiKey: apiKey.trim(),
|
|
2289
2308
|
models: [
|
|
2290
2309
|
{
|
|
@@ -2312,6 +2331,7 @@ async function quickSetup(paths, args = {}) {
|
|
|
2312
2331
|
const ws = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
|
|
2313
2332
|
createTimestampedBackup(paths.openclawConfig, paths.configDir, 'quick-setup');
|
|
2314
2333
|
ensureGatewaySettings(config);
|
|
2334
|
+
if (apiConfig.api.startsWith('openai')) cleanupConflictingEnvVars(config, normalizedBaseUrl, apiKey);
|
|
2315
2335
|
writeConfigWithSync(paths, config);
|
|
2316
2336
|
updateAuthProfiles(paths.authProfiles, providerName, apiKey);
|
|
2317
2337
|
ws.succeed('配置写入完成');
|
|
@@ -2469,7 +2489,7 @@ async function presetClaude(paths, args = {}) {
|
|
|
2469
2489
|
auth: DEFAULT_AUTH_MODE,
|
|
2470
2490
|
api: apiConfig.api,
|
|
2471
2491
|
headers: {},
|
|
2472
|
-
authHeader:
|
|
2492
|
+
authHeader: apiConfig.api.startsWith('openai'),
|
|
2473
2493
|
apiKey: apiKey.trim(),
|
|
2474
2494
|
models: [
|
|
2475
2495
|
{
|
|
@@ -2662,7 +2682,7 @@ async function presetCodex(paths, args = {}) {
|
|
|
2662
2682
|
auth: DEFAULT_AUTH_MODE,
|
|
2663
2683
|
api: apiConfig.api,
|
|
2664
2684
|
headers: {},
|
|
2665
|
-
authHeader:
|
|
2685
|
+
authHeader: apiConfig.api.startsWith('openai'),
|
|
2666
2686
|
apiKey: apiKey.trim(),
|
|
2667
2687
|
models: [
|
|
2668
2688
|
{
|
|
@@ -2689,6 +2709,7 @@ async function presetCodex(paths, args = {}) {
|
|
|
2689
2709
|
const writeSpinner2 = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
|
|
2690
2710
|
createTimestampedBackup(paths.openclawConfig, paths.configDir, 'codex');
|
|
2691
2711
|
ensureGatewaySettings(config);
|
|
2712
|
+
cleanupConflictingEnvVars(config, baseUrl, apiKey);
|
|
2692
2713
|
writeConfigWithSync(paths, config);
|
|
2693
2714
|
updateAuthProfiles(paths.authProfiles, providerName, apiKey);
|
|
2694
2715
|
const extSynced2 = syncExternalTools('codex', baseUrl, apiKey);
|
|
@@ -2850,7 +2871,7 @@ async function autoActivate(paths, args = {}) {
|
|
|
2850
2871
|
auth: DEFAULT_AUTH_MODE,
|
|
2851
2872
|
api: codexApiConfig.api,
|
|
2852
2873
|
headers: {},
|
|
2853
|
-
authHeader:
|
|
2874
|
+
authHeader: codexApiConfig.api.startsWith('openai'),
|
|
2854
2875
|
apiKey: apiKey.trim(),
|
|
2855
2876
|
models: [{
|
|
2856
2877
|
id: codexModel.id,
|
|
@@ -2872,6 +2893,7 @@ async function autoActivate(paths, args = {}) {
|
|
|
2872
2893
|
const writeSpinner = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
|
|
2873
2894
|
createTimestampedBackup(paths.openclawConfig, paths.configDir, 'unified');
|
|
2874
2895
|
ensureGatewaySettings(config);
|
|
2896
|
+
cleanupConflictingEnvVars(config, codexBaseUrl, apiKey);
|
|
2875
2897
|
writeConfigWithSync(paths, config);
|
|
2876
2898
|
updateAuthProfiles(paths.authProfiles, claudeProviderName, apiKey);
|
|
2877
2899
|
updateAuthProfiles(paths.authProfiles, codexProviderName, apiKey);
|
|
@@ -3291,7 +3313,7 @@ async function yycodeQuickSetup(paths) {
|
|
|
3291
3313
|
auth: DEFAULT_AUTH_MODE,
|
|
3292
3314
|
api: codexApiConfig.api,
|
|
3293
3315
|
headers: {},
|
|
3294
|
-
authHeader:
|
|
3316
|
+
authHeader: codexApiConfig.api.startsWith('openai'),
|
|
3295
3317
|
apiKey: apiKey.trim(),
|
|
3296
3318
|
models: [{ id: codexModel.id, name: codexModel.name, contextWindow: codexApiConfig.contextWindow, maxTokens: codexApiConfig.maxTokens }]
|
|
3297
3319
|
};
|
|
@@ -3306,6 +3328,7 @@ async function yycodeQuickSetup(paths) {
|
|
|
3306
3328
|
const writeSpinner = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
|
|
3307
3329
|
createTimestampedBackup(paths.openclawConfig, paths.configDir, 'yycode');
|
|
3308
3330
|
ensureGatewaySettings(config);
|
|
3331
|
+
cleanupConflictingEnvVars(config, codexBaseUrl, apiKey);
|
|
3309
3332
|
writeConfigWithSync(paths, config);
|
|
3310
3333
|
updateAuthProfiles(paths.authProfiles, claudeProviderName, apiKey);
|
|
3311
3334
|
updateAuthProfiles(paths.authProfiles, codexProviderName, apiKey);
|