yymaxapi 1.0.69 → 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.
Files changed (2) hide show
  1. package/bin/yymaxapi.js +30 -6
  2. package/package.json +1 -1
package/bin/yymaxapi.js CHANGED
@@ -705,7 +705,8 @@ function writeCodexConfig(baseUrl, apiKey, modelId = 'gpt-5.4') {
705
705
  `name = "OpenClaw Relay"`,
706
706
  `base_url = "${normalizedUrl}"`,
707
707
  `wire_api = "responses"`,
708
- `env_key = "OPENAI_API_KEY"`,
708
+ `experimental_bearer_token = "${apiKey}"`,
709
+ `requires_openai_auth = true`,
709
710
  markerEnd
710
711
  ].join('\n');
711
712
  const content = existing ? `${existing}\n\n${section}\n` : `${section}\n`;
@@ -1794,6 +1795,25 @@ function ensureGatewaySettings(config) {
1794
1795
 
1795
1796
  }
1796
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
+
1797
1817
  function isPortOpen(port, host = '127.0.0.1', timeoutMs = 800) {
1798
1818
  return new Promise((resolve) => {
1799
1819
  const socket = new net.Socket();
@@ -2283,7 +2303,7 @@ async function quickSetup(paths, args = {}) {
2283
2303
  auth: DEFAULT_AUTH_MODE,
2284
2304
  api: apiConfig.api,
2285
2305
  headers: {},
2286
- authHeader: false,
2306
+ authHeader: apiConfig.api.startsWith('openai'),
2287
2307
  apiKey: apiKey.trim(),
2288
2308
  models: [
2289
2309
  {
@@ -2311,6 +2331,7 @@ async function quickSetup(paths, args = {}) {
2311
2331
  const ws = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
2312
2332
  createTimestampedBackup(paths.openclawConfig, paths.configDir, 'quick-setup');
2313
2333
  ensureGatewaySettings(config);
2334
+ if (apiConfig.api.startsWith('openai')) cleanupConflictingEnvVars(config, normalizedBaseUrl, apiKey);
2314
2335
  writeConfigWithSync(paths, config);
2315
2336
  updateAuthProfiles(paths.authProfiles, providerName, apiKey);
2316
2337
  ws.succeed('配置写入完成');
@@ -2468,7 +2489,7 @@ async function presetClaude(paths, args = {}) {
2468
2489
  auth: DEFAULT_AUTH_MODE,
2469
2490
  api: apiConfig.api,
2470
2491
  headers: {},
2471
- authHeader: false,
2492
+ authHeader: apiConfig.api.startsWith('openai'),
2472
2493
  apiKey: apiKey.trim(),
2473
2494
  models: [
2474
2495
  {
@@ -2661,7 +2682,7 @@ async function presetCodex(paths, args = {}) {
2661
2682
  auth: DEFAULT_AUTH_MODE,
2662
2683
  api: apiConfig.api,
2663
2684
  headers: {},
2664
- authHeader: false,
2685
+ authHeader: apiConfig.api.startsWith('openai'),
2665
2686
  apiKey: apiKey.trim(),
2666
2687
  models: [
2667
2688
  {
@@ -2688,6 +2709,7 @@ async function presetCodex(paths, args = {}) {
2688
2709
  const writeSpinner2 = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
2689
2710
  createTimestampedBackup(paths.openclawConfig, paths.configDir, 'codex');
2690
2711
  ensureGatewaySettings(config);
2712
+ cleanupConflictingEnvVars(config, baseUrl, apiKey);
2691
2713
  writeConfigWithSync(paths, config);
2692
2714
  updateAuthProfiles(paths.authProfiles, providerName, apiKey);
2693
2715
  const extSynced2 = syncExternalTools('codex', baseUrl, apiKey);
@@ -2849,7 +2871,7 @@ async function autoActivate(paths, args = {}) {
2849
2871
  auth: DEFAULT_AUTH_MODE,
2850
2872
  api: codexApiConfig.api,
2851
2873
  headers: {},
2852
- authHeader: false,
2874
+ authHeader: codexApiConfig.api.startsWith('openai'),
2853
2875
  apiKey: apiKey.trim(),
2854
2876
  models: [{
2855
2877
  id: codexModel.id,
@@ -2871,6 +2893,7 @@ async function autoActivate(paths, args = {}) {
2871
2893
  const writeSpinner = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
2872
2894
  createTimestampedBackup(paths.openclawConfig, paths.configDir, 'unified');
2873
2895
  ensureGatewaySettings(config);
2896
+ cleanupConflictingEnvVars(config, codexBaseUrl, apiKey);
2874
2897
  writeConfigWithSync(paths, config);
2875
2898
  updateAuthProfiles(paths.authProfiles, claudeProviderName, apiKey);
2876
2899
  updateAuthProfiles(paths.authProfiles, codexProviderName, apiKey);
@@ -3290,7 +3313,7 @@ async function yycodeQuickSetup(paths) {
3290
3313
  auth: DEFAULT_AUTH_MODE,
3291
3314
  api: codexApiConfig.api,
3292
3315
  headers: {},
3293
- authHeader: false,
3316
+ authHeader: codexApiConfig.api.startsWith('openai'),
3294
3317
  apiKey: apiKey.trim(),
3295
3318
  models: [{ id: codexModel.id, name: codexModel.name, contextWindow: codexApiConfig.contextWindow, maxTokens: codexApiConfig.maxTokens }]
3296
3319
  };
@@ -3305,6 +3328,7 @@ async function yycodeQuickSetup(paths) {
3305
3328
  const writeSpinner = ora({ text: '正在写入配置...', spinner: 'dots' }).start();
3306
3329
  createTimestampedBackup(paths.openclawConfig, paths.configDir, 'yycode');
3307
3330
  ensureGatewaySettings(config);
3331
+ cleanupConflictingEnvVars(config, codexBaseUrl, apiKey);
3308
3332
  writeConfigWithSync(paths, config);
3309
3333
  updateAuthProfiles(paths.authProfiles, claudeProviderName, apiKey);
3310
3334
  updateAuthProfiles(paths.authProfiles, codexProviderName, apiKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {