refactor(codex): simplify custom template with minimal config
**Changes:** - Remove all comments from custom template (align with Claude/Gemini) - Remove base_url field from template (user fills in form instead) - Simplify getCodexCustomTemplate() - no locale parameter needed - Keep preset configurations unchanged with their baseUrl values **Template now contains only:** - model_provider, model, model_reasoning_effort - disable_response_storage - [model_providers.custom] section with minimal fields **Benefits:** - ✅ Cleaner, more focused template - ✅ Consistent with other apps (no comments) - ✅ Forces users to fill base_url via form field - ✅ Reduced template size from 35+ lines to 12 lines Net change: -74 lines (codexTemplates.ts)
This commit is contained in:
@@ -90,7 +90,7 @@ export function ProviderForm({
|
|||||||
initialData,
|
initialData,
|
||||||
showButtons = true,
|
showButtons = true,
|
||||||
}: ProviderFormProps) {
|
}: ProviderFormProps) {
|
||||||
const { t, i18n } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isEditMode = Boolean(initialData);
|
const isEditMode = Boolean(initialData);
|
||||||
|
|
||||||
const [selectedPresetId, setSelectedPresetId] = useState<string | null>(
|
const [selectedPresetId, setSelectedPresetId] = useState<string | null>(
|
||||||
@@ -221,14 +221,13 @@ export function ProviderForm({
|
|||||||
[originalHandleCodexConfigChange, debouncedValidate],
|
[originalHandleCodexConfigChange, debouncedValidate],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Codex 新建模式:初始化时自动填充模板(支持国际化)
|
// Codex 新建模式:初始化时自动填充模板
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (appId === "codex" && !initialData && selectedPresetId === "custom") {
|
if (appId === "codex" && !initialData && selectedPresetId === "custom") {
|
||||||
const locale = (i18n.language || "zh").startsWith("zh") ? "zh" : "en";
|
const template = getCodexCustomTemplate();
|
||||||
const template = getCodexCustomTemplate(locale);
|
|
||||||
resetCodexConfig(template.auth, template.config);
|
resetCodexConfig(template.auth, template.config);
|
||||||
}
|
}
|
||||||
}, [appId, initialData, selectedPresetId, resetCodexConfig, i18n.language]);
|
}, [appId, initialData, selectedPresetId, resetCodexConfig]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
form.reset(defaultValues);
|
form.reset(defaultValues);
|
||||||
@@ -535,10 +534,9 @@ export function ProviderForm({
|
|||||||
setActivePreset(null);
|
setActivePreset(null);
|
||||||
form.reset(defaultValues);
|
form.reset(defaultValues);
|
||||||
|
|
||||||
// Codex 自定义模式:加载模板(支持国际化)
|
// Codex 自定义模式:加载模板
|
||||||
if (appId === "codex") {
|
if (appId === "codex") {
|
||||||
const locale = (i18n.language || "zh").startsWith("zh") ? "zh" : "en";
|
const template = getCodexCustomTemplate();
|
||||||
const template = getCodexCustomTemplate(locale);
|
|
||||||
resetCodexConfig(template.auth, template.config);
|
resetCodexConfig(template.auth, template.config);
|
||||||
}
|
}
|
||||||
// Gemini 自定义模式:重置为空配置
|
// Gemini 自定义模式:重置为空配置
|
||||||
|
|||||||
@@ -10,86 +10,21 @@ export interface CodexTemplate {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 Codex 自定义模板
|
* 获取 Codex 自定义模板
|
||||||
* @param locale 语言环境 ('zh' | 'en')
|
|
||||||
* @returns Codex 模板配置
|
* @returns Codex 模板配置
|
||||||
*/
|
*/
|
||||||
export function getCodexCustomTemplate(
|
export function getCodexCustomTemplate(): CodexTemplate {
|
||||||
locale: "zh" | "en" = "zh",
|
const config = `model_provider = "custom"
|
||||||
): CodexTemplate {
|
model = "gpt-5-codex"
|
||||||
const templates = {
|
model_reasoning_effort = "high"
|
||||||
zh: `# ========================================
|
disable_response_storage = true
|
||||||
# Codex 自定义供应商配置模板
|
|
||||||
# ========================================
|
|
||||||
# 快速上手:
|
|
||||||
# 1. 在上方 auth.json 中设置 API Key
|
|
||||||
# 2. 将下方 'custom' 替换为供应商名称(小写、无空格)
|
|
||||||
# 3. 替换 base_url 为实际的 API 端点
|
|
||||||
# 4. 根据需要调整模型名称
|
|
||||||
#
|
|
||||||
# 文档: https://docs.anthropic.com
|
|
||||||
# ========================================
|
|
||||||
|
|
||||||
# ========== 模型配置 ==========
|
|
||||||
model_provider = "custom" # 供应商唯一标识
|
|
||||||
model = "gpt-5-codex" # 模型名称
|
|
||||||
model_reasoning_effort = "high" # 推理强度:low, medium, high
|
|
||||||
disable_response_storage = true # 隐私:不本地存储响应
|
|
||||||
|
|
||||||
# ========== 供应商设置 ==========
|
|
||||||
[model_providers.custom]
|
[model_providers.custom]
|
||||||
name = "custom" # 与上方 model_provider 保持一致
|
name = "custom"
|
||||||
base_url = "https://api.example.com/v1" # 👈 替换为实际端点
|
wire_api = "responses"
|
||||||
wire_api = "responses" # API 响应格式
|
requires_openai_auth = true`;
|
||||||
requires_openai_auth = true # 使用 auth.json 中的 OPENAI_API_KEY
|
|
||||||
|
|
||||||
# ========== 可选:自定义请求头 ==========
|
|
||||||
# 如果供应商需要自定义请求头,取消注释:
|
|
||||||
# [model_providers.custom.headers]
|
|
||||||
# X-Custom-Header = "value"
|
|
||||||
|
|
||||||
# ========== 可选:模型覆盖 ==========
|
|
||||||
# 如果需要覆盖特定模型,取消注释:
|
|
||||||
# [model_overrides]
|
|
||||||
# "gpt-5-codex" = { model_provider = "custom", model = "your-model-name" }`,
|
|
||||||
|
|
||||||
en: `# ========================================
|
|
||||||
# Codex Custom Provider Configuration Template
|
|
||||||
# ========================================
|
|
||||||
# Quick Start:
|
|
||||||
# 1. Set API Key in auth.json above
|
|
||||||
# 2. Replace 'custom' below with provider name (lowercase, no spaces)
|
|
||||||
# 3. Replace base_url with actual API endpoint
|
|
||||||
# 4. Adjust model name as needed
|
|
||||||
#
|
|
||||||
# Docs: https://docs.anthropic.com
|
|
||||||
# ========================================
|
|
||||||
|
|
||||||
# ========== Model Configuration ==========
|
|
||||||
model_provider = "custom" # Unique provider identifier
|
|
||||||
model = "gpt-5-codex" # Model name
|
|
||||||
model_reasoning_effort = "high" # Reasoning effort: low, medium, high
|
|
||||||
disable_response_storage = true # Privacy: do not store responses locally
|
|
||||||
|
|
||||||
# ========== Provider Settings ==========
|
|
||||||
[model_providers.custom]
|
|
||||||
name = "custom" # Must match model_provider above
|
|
||||||
base_url = "https://api.example.com/v1" # 👈 Replace with actual endpoint
|
|
||||||
wire_api = "responses" # API response format
|
|
||||||
requires_openai_auth = true # Use OPENAI_API_KEY from auth.json
|
|
||||||
|
|
||||||
# ========== Optional: Custom Headers ==========
|
|
||||||
# If provider requires custom headers, uncomment:
|
|
||||||
# [model_providers.custom.headers]
|
|
||||||
# X-Custom-Header = "value"
|
|
||||||
|
|
||||||
# ========== Optional: Model Overrides ==========
|
|
||||||
# If you need to override specific models, uncomment:
|
|
||||||
# [model_overrides]
|
|
||||||
# "gpt-5-codex" = { model_provider = "custom", model = "your-model-name" }`,
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
auth: { OPENAI_API_KEY: "" },
|
auth: { OPENAI_API_KEY: "" },
|
||||||
config: templates[locale] || templates.zh,
|
config,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user