yymaxapi 1.0.77 → 1.0.78
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 +34 -10
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -680,10 +680,14 @@ function writeCodexConfig(baseUrl, apiKey, modelId = 'gpt-5.4') {
|
|
|
680
680
|
const codexDir = path.join(os.homedir(), '.codex');
|
|
681
681
|
if (!fs.existsSync(codexDir)) fs.mkdirSync(codexDir, { recursive: true });
|
|
682
682
|
|
|
683
|
-
// ~/.codex/config.toml —
|
|
683
|
+
// ~/.codex/config.toml — 顶层设置和 section 分开管理
|
|
684
|
+
// TOML 规范:[section] 之后的 key=value 属于该 section,不是顶层
|
|
685
|
+
// 所以 model / model_provider 必须在所有 [section] 之前
|
|
684
686
|
const configPath = path.join(codexDir, 'config.toml');
|
|
685
687
|
const marker = '# >>> maxapi codex >>>';
|
|
686
688
|
const markerEnd = '# <<< maxapi codex <<<';
|
|
689
|
+
const topMarker = '# >>> maxapi codex top >>>';
|
|
690
|
+
const topMarkerEnd = '# <<< maxapi codex top <<<';
|
|
687
691
|
const providerKey = 'openclaw-relay';
|
|
688
692
|
// 确保 base_url 以 /v1 结尾(Codex CLI 要求)
|
|
689
693
|
let normalizedUrl = baseUrl.replace(/\/+$/, '');
|
|
@@ -692,24 +696,44 @@ function writeCodexConfig(baseUrl, apiKey, modelId = 'gpt-5.4') {
|
|
|
692
696
|
let existing = '';
|
|
693
697
|
if (fs.existsSync(configPath)) {
|
|
694
698
|
existing = fs.readFileSync(configPath, 'utf8');
|
|
695
|
-
// 移除旧的 maxapi section
|
|
699
|
+
// 移除旧的 maxapi section(provider block)
|
|
696
700
|
const re = new RegExp(`${marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${markerEnd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`, 'g');
|
|
697
|
-
existing = existing.replace(re, '')
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
+
existing = existing.replace(re, '');
|
|
702
|
+
// 移除旧的 maxapi top-level block
|
|
703
|
+
const topRe = new RegExp(`${topMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${topMarkerEnd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n?`, 'g');
|
|
704
|
+
existing = existing.replace(topRe, '');
|
|
705
|
+
// 兼容旧版:移除散落在 section 内的旧 model/model_provider(来自旧版 marker block 残留)
|
|
706
|
+
existing = existing.replace(/^model\s*=\s*"[^"]*"\s*$/gm, '');
|
|
707
|
+
existing = existing.replace(/^model_provider\s*=\s*"[^"]*"\s*$/gm, '');
|
|
708
|
+
existing = existing.replace(/\n{3,}/g, '\n\n').trim();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// 顶层设置(MUST 在所有 [section] 之前)
|
|
712
|
+
const topBlock = [
|
|
713
|
+
topMarker,
|
|
701
714
|
`model = "${modelId}"`,
|
|
702
715
|
`model_provider = "${providerKey}"`,
|
|
703
|
-
|
|
716
|
+
topMarkerEnd
|
|
717
|
+
].join('\n');
|
|
718
|
+
|
|
719
|
+
// Provider section(追加在文件末尾)
|
|
720
|
+
const providerBlock = [
|
|
721
|
+
marker,
|
|
704
722
|
`[model_providers.${providerKey}]`,
|
|
705
723
|
`name = "OpenClaw Relay"`,
|
|
706
724
|
`base_url = "${normalizedUrl}"`,
|
|
707
725
|
`wire_api = "responses"`,
|
|
708
726
|
`experimental_bearer_token = "${apiKey}"`,
|
|
709
|
-
`requires_openai_auth = true`,
|
|
710
727
|
markerEnd
|
|
711
728
|
].join('\n');
|
|
712
|
-
|
|
729
|
+
|
|
730
|
+
// 组装:顶层设置 → 原有内容 → provider section
|
|
731
|
+
let content;
|
|
732
|
+
if (existing) {
|
|
733
|
+
content = `${topBlock}\n\n${existing}\n\n${providerBlock}\n`;
|
|
734
|
+
} else {
|
|
735
|
+
content = `${topBlock}\n\n${providerBlock}\n`;
|
|
736
|
+
}
|
|
713
737
|
fs.writeFileSync(configPath, content, 'utf8');
|
|
714
738
|
} catch { /* 非关键,静默失败 */ }
|
|
715
739
|
|
|
@@ -808,7 +832,7 @@ function writeOpencodeConfig(claudeBaseUrl, codexBaseUrl, apiKey, modelId) {
|
|
|
808
832
|
`base_url = "${codexUrl}"`,
|
|
809
833
|
'wire_api = "responses"',
|
|
810
834
|
`experimental_bearer_token = "${apiKey}"`,
|
|
811
|
-
'requires_openai_auth =
|
|
835
|
+
'requires_openai_auth = false',
|
|
812
836
|
'# <<< yunyi opencode <<<'
|
|
813
837
|
);
|
|
814
838
|
}
|