chore(codex): 调整 Codex 预设模板与占位符(auth.json/config.toml 与表单占位)

This commit is contained in:
Jason
2025-08-30 23:02:49 +08:00
parent 7b5d5c6ce1
commit 0cb89c8f67
2 changed files with 28 additions and 19 deletions

View File

@@ -48,7 +48,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
const [codexConfig, setCodexConfig] = useState(""); const [codexConfig, setCodexConfig] = useState("");
const [codexApiKey, setCodexApiKey] = useState(""); const [codexApiKey, setCodexApiKey] = useState("");
const [selectedCodexPreset, setSelectedCodexPreset] = useState<number | null>( const [selectedCodexPreset, setSelectedCodexPreset] = useState<number | null>(
null, null
); );
// 初始化 Codex 配置 // 初始化 Codex 配置
@@ -134,7 +134,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
}; };
const handleChange = ( const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => { ) => {
const { name, value } = e.target; const { name, value } = e.target;
@@ -171,7 +171,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
// 更新JSON配置 // 更新JSON配置
const updatedConfig = updateCoAuthoredSetting( const updatedConfig = updateCoAuthoredSetting(
formData.settingsConfig, formData.settingsConfig,
checked, checked
); );
setFormData({ setFormData({
...formData, ...formData,
@@ -202,7 +202,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
// Codex: 应用预设 // Codex: 应用预设
const applyCodexPreset = ( const applyCodexPreset = (
preset: (typeof codexProviderPresets)[0], preset: (typeof codexProviderPresets)[0],
index: number, index: number
) => { ) => {
const authString = JSON.stringify(preset.auth || {}, null, 2); const authString = JSON.stringify(preset.auth || {}, null, 2);
setCodexAuth(authString); setCodexAuth(authString);
@@ -227,7 +227,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
const configString = setApiKeyInConfig( const configString = setApiKeyInConfig(
formData.settingsConfig, formData.settingsConfig,
key.trim(), key.trim(),
{ createIfMissing: selectedPreset !== null }, { createIfMissing: selectedPreset !== null }
); );
// 更新表单配置 // 更新表单配置
@@ -281,7 +281,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
useEffect(() => { useEffect(() => {
if (initialData) { if (initialData) {
const parsedKey = getApiKeyFromConfig( const parsedKey = getApiKeyFromConfig(
JSON.stringify(initialData.settingsConfig), JSON.stringify(initialData.settingsConfig)
); );
if (parsedKey) setApiKey(parsedKey); if (parsedKey) setApiKey(parsedKey);
} }
@@ -427,7 +427,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
placeholder={ placeholder={
isCodexOfficialPreset isCodexOfficialPreset
? "官方无需填写 API Key直接保存即可" ? "官方无需填写 API Key直接保存即可"
: "只需要填这里,方 auth.json 会自动填充" : "只需要填这里,方 auth.json 会自动填充"
} }
disabled={isCodexOfficialPreset} disabled={isCodexOfficialPreset}
autoComplete="off" autoComplete="off"
@@ -471,14 +471,15 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
setCodexAuth(value); setCodexAuth(value);
try { try {
const auth = JSON.parse(value || "{}"); const auth = JSON.parse(value || "{}");
const key = typeof auth.api_key === "string" ? auth.api_key : ""; const key =
typeof auth.api_key === "string" ? auth.api_key : "";
setCodexApiKey(key); setCodexApiKey(key);
} catch { } catch {
// ignore // ignore
} }
}} }}
placeholder={`{ placeholder={`{
"api_key": "your-codex-api-key" "OPENAI_API_KEY": "sk-your-api-key-here"
}`} }`}
rows={6} rows={6}
style={{ fontFamily: "monospace", fontSize: "14px" }} style={{ fontFamily: "monospace", fontSize: "14px" }}
@@ -493,9 +494,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
id="codexConfig" id="codexConfig"
value={codexConfig} value={codexConfig}
onChange={(e) => setCodexConfig(e.target.value)} onChange={(e) => setCodexConfig(e.target.value)}
placeholder={`# Codex configuration placeholder={``}
model = "codex-model"
temperature = 0.7`}
rows={8} rows={8}
style={{ fontFamily: "monospace", fontSize: "14px" }} style={{ fontFamily: "monospace", fontSize: "14px" }}
required required

View File

@@ -12,20 +12,30 @@ export interface CodexProviderPreset {
export const codexProviderPresets: CodexProviderPreset[] = [ export const codexProviderPresets: CodexProviderPreset[] = [
{ {
name: "Codex官方", name: "Codex官方",
websiteUrl: "https://codex", websiteUrl: "https://chatgpt.com/codex",
isOfficial: true, isOfficial: true,
// 官方一般不需要在 auth.json 里预置 key由用户根据实际环境填写 // 官方的 key 为null
auth: {}, auth: {
config: `# Codex 默认配置模板\n# 根据你的 Codex 安装或文档进行调整\nmodel = "default"\ntemperature = 0.7`, "OPENAI_API_KEY": null,
},
config: ``,
}, },
{ {
name: "PackyCode", name: "PackyCode",
websiteUrl: "https://www.packycode.com", websiteUrl: "https://codex.packycode.com/",
// PackyCode 一般通过 API Key请将占位符替换为你的实际 key // PackyCode 一般通过 API Key请将占位符替换为你的实际 key
auth: { auth: {
api_key: "sk-your-api-key-here", "OPENAI_API_KEY": "sk-your-api-key-here",
}, },
config: `# Codex 配置模板 - PackyCode\n# 如有需要可添加 base_url: \n# base_url = "https://api.packycode.com"\nmodel = "default"\ntemperature = 0.7`, config: `model_provider = "packycode"
model = "gpt-5"
model_reasoning_effort = "high"
[model_providers.packycode]
name = "packycode"
base_url = "https://codex-api.packycode.com/v1"
wire_api = "responses"
env_key = "packycode"`,
}, },
]; ];