From 417dcc1d378ab3829e64c99149aca5b00a3992a8 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 31 Aug 2025 17:07:35 +0800 Subject: [PATCH] feat(codex): require OPENAI_API_KEY when non-official preset selected; keep config.toml optional --- src/components/ProviderForm.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/components/ProviderForm.tsx b/src/components/ProviderForm.tsx index 74e2bca..8dc3874 100644 --- a/src/components/ProviderForm.tsx +++ b/src/components/ProviderForm.tsx @@ -103,6 +103,23 @@ const ProviderForm: React.FC = ({ try { const authJson = JSON.parse(codexAuth); + + // 非官方预设强制要求 OPENAI_API_KEY + if (selectedCodexPreset !== null) { + const preset = codexProviderPresets[selectedCodexPreset]; + const isOfficial = Boolean(preset?.isOfficial); + if (!isOfficial) { + const key = + typeof authJson.OPENAI_API_KEY === "string" + ? authJson.OPENAI_API_KEY.trim() + : ""; + if (!key) { + setError("请填写 OPENAI_API_KEY"); + return; + } + } + } + settingsConfig = { auth: authJson, config: codexConfig ?? "", @@ -430,6 +447,7 @@ const ProviderForm: React.FC = ({ : "只需要填这里,下方 auth.json 会自动填充" } disabled={isCodexOfficialPreset} + required={selectedCodexPreset !== null && !isCodexOfficialPreset} autoComplete="off" style={ isCodexOfficialPreset