feat(codex): support native Responses direct-connect with generated model catalog

Codex providers can now run in two modes per provider:

- Proxy-Chat (route takeover): apiFormat=openai_chat, existing Responses<->Chat conversion. Unchanged.

- Native-Responses (direct): apiFormat=openai_responses, no proxy. cc-switch generates ~/.codex/cc-switch-model-catalog.json so Codex shows the custom models and tools work without the freeform apply_patch (type=custom) tool that native gateways like MiMo reject; editing falls back to shell_command.

Catalog generation is keyed on apiFormat (CodexCatalogToolProfile), decoupled from the takeover toggle, so native providers persist a catalog without enabling local route mapping.

Codex's catalog parser requires base_instructions on every entry; the native template carries a neutral default and per-vendor official text overrides it (MiMo, MiniMax). Synthesized catalogs for Qwen/Doubao/LongCat use the neutral default.

Existing native providers must be re-saved once to regenerate a valid catalog (no DB migration).
This commit is contained in:
Jason
2026-06-27 23:12:30 +08:00
parent 61d7ac01fb
commit 15e712e779
11 changed files with 692 additions and 154 deletions
+131 -121
View File
@@ -107,6 +107,15 @@ function createCatalogRow(seed?: Partial<CodexCatalogModel>): CodexCatalogRow {
model: seed?.model ?? "",
displayName: seed?.displayName ?? "",
contextWindow: seed?.contextWindow ?? "",
// Carry native-profile overrides verbatim (not user-editable in the row UI,
// but must survive load->save so the official catalog fidelity is kept).
...(seed?.supportsParallelToolCalls !== undefined
? { supportsParallelToolCalls: seed.supportsParallelToolCalls }
: {}),
...(seed?.inputModalities ? { inputModalities: seed.inputModalities } : {}),
...(seed?.baseInstructions
? { baseInstructions: seed.baseInstructions }
: {}),
};
}
@@ -571,148 +580,149 @@ export function CodexFormFields({
</div>
</div>
{/* 模型映射 —— 仅在本地路由开启 + 可编辑时显示(与上游格式解耦,
Responses 原生供应商同样可配置);上方恒有 UA 字段,分隔线无需条件 */}
{takeoverEnabled && canEditCatalog && (
<div className="space-y-4 border-t border-border-default pt-3">
<div className="space-y-1">
<div className="flex items-center justify-between gap-3">
<FormLabel>
{t("codexConfig.modelMappingTitle", {
defaultValue: "模型映射",
})}
</FormLabel>
{renderCatalogActionButtons(
handleAddCatalogRow,
t("codexConfig.addCatalogModel", {
defaultValue: "添加模型",
}),
)}
</div>
<p className="text-xs leading-relaxed text-muted-foreground">
{t("codexConfig.modelMappingHint", {
defaultValue:
"选择模型角色后,CC Switch 会自动生成 Codex 兼容路由;菜单显示名可以填 DeepSeek、Kimi 等品牌模型,实际请求模型按右侧填写内容发送。",
})}
</p>
</div>
{catalogRows.length > 0 && (
<div className="space-y-2">
{/* 列头:md+ 显示 */}
<div className="hidden grid-cols-[1fr_1fr_140px_36px] gap-2 px-1 text-xs font-medium text-muted-foreground md:grid">
<span>
{t("codexConfig.catalogColumnDisplay", {
defaultValue: "菜单显示名",
{/* 模型映射 / 模型目录 —— 接管开启(Chat 模式生成兼容路由)或
原生 Responses 模式(生成 model-catalogs.json)时显示;可编辑即渲染。 */}
{(takeoverEnabled || apiFormat === "openai_responses") &&
canEditCatalog && (
<div className="space-y-4 border-t border-border-default pt-3">
<div className="space-y-1">
<div className="flex items-center justify-between gap-3">
<FormLabel>
{t("codexConfig.modelMappingTitle", {
defaultValue: "模型映射",
})}
</span>
<span>
{t("codexConfig.catalogColumnModel", {
defaultValue: "实际请求模型",
})}
</span>
<span>
{t("codexConfig.catalogColumnContext", {
defaultValue: "上下文窗口",
})}
</span>
<span />
</FormLabel>
{renderCatalogActionButtons(
handleAddCatalogRow,
t("codexConfig.addCatalogModel", {
defaultValue: "添加模型",
}),
)}
</div>
<p className="text-xs leading-relaxed text-muted-foreground">
{t("codexConfig.modelMappingHint", {
defaultValue:
"选择模型角色后,CC Switch 会自动生成 Codex 兼容路由;菜单显示名可以填 DeepSeek、Kimi 等品牌模型,实际请求模型按右侧填写内容发送。",
})}
</p>
</div>
{catalogRows.map((row, index) => (
<div
key={row.rowId}
className="grid grid-cols-1 gap-2 md:grid-cols-[1fr_1fr_140px_36px]"
>
<Input
value={row.displayName ?? ""}
onChange={(event) =>
handleUpdateCatalogRow(index, {
displayName: event.target.value,
})
}
placeholder={t(
"codexConfig.catalogDisplayNamePlaceholder",
{
defaultValue: "例如: DeepSeek V4 Flash",
},
)}
aria-label={t("codexConfig.catalogColumnDisplay", {
{catalogRows.length > 0 && (
<div className="space-y-2">
{/* 列头:md+ 显示 */}
<div className="hidden grid-cols-[1fr_1fr_140px_36px] gap-2 px-1 text-xs font-medium text-muted-foreground md:grid">
<span>
{t("codexConfig.catalogColumnDisplay", {
defaultValue: "菜单显示名",
})}
/>
<div className="flex gap-1">
</span>
<span>
{t("codexConfig.catalogColumnModel", {
defaultValue: "实际请求模型",
})}
</span>
<span>
{t("codexConfig.catalogColumnContext", {
defaultValue: "上下文窗口",
})}
</span>
<span />
</div>
{catalogRows.map((row, index) => (
<div
key={row.rowId}
className="grid grid-cols-1 gap-2 md:grid-cols-[1fr_1fr_140px_36px]"
>
<Input
value={row.model}
value={row.displayName ?? ""}
onChange={(event) =>
handleUpdateCatalogRow(index, {
model: event.target.value,
displayName: event.target.value,
})
}
placeholder={t(
"codexConfig.catalogModelPlaceholder",
"codexConfig.catalogDisplayNamePlaceholder",
{
defaultValue: "例如: deepseek-v4-flash",
defaultValue: "例如: DeepSeek V4 Flash",
},
)}
aria-label={t("codexConfig.catalogColumnModel", {
defaultValue: "实际请求模型",
aria-label={t("codexConfig.catalogColumnDisplay", {
defaultValue: "菜单显示名",
})}
className="flex-1"
/>
{fetchedModels.length > 0 && (
<ModelDropdown
models={fetchedModels}
onSelect={(id) =>
<div className="flex gap-1">
<Input
value={row.model}
onChange={(event) =>
handleUpdateCatalogRow(index, {
model: id,
displayName: row.displayName?.trim()
? row.displayName
: id,
model: event.target.value,
})
}
placeholder={t(
"codexConfig.catalogModelPlaceholder",
{
defaultValue: "例如: deepseek-v4-flash",
},
)}
aria-label={t("codexConfig.catalogColumnModel", {
defaultValue: "实际请求模型",
})}
className="flex-1"
/>
)}
{fetchedModels.length > 0 && (
<ModelDropdown
models={fetchedModels}
onSelect={(id) =>
handleUpdateCatalogRow(index, {
model: id,
displayName: row.displayName?.trim()
? row.displayName
: id,
})
}
/>
)}
</div>
<Input
type="number"
min={1}
inputMode="numeric"
value={row.contextWindow ?? ""}
onChange={(event) =>
handleUpdateCatalogRow(index, {
contextWindow: event.target.value.replace(
/[^\d]/g,
"",
),
})
}
placeholder={t(
"codexConfig.contextWindowPlaceholder",
{
defaultValue: "例如: 128000",
},
)}
aria-label={t("codexConfig.catalogColumnContext", {
defaultValue: "上下文窗口",
})}
/>
<Button
type="button"
variant="ghost"
size="icon"
className="h-9 w-9 text-muted-foreground hover:text-destructive"
onClick={() => handleRemoveCatalogRow(index)}
title={t("common.delete", { defaultValue: "删除" })}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
<Input
type="number"
min={1}
inputMode="numeric"
value={row.contextWindow ?? ""}
onChange={(event) =>
handleUpdateCatalogRow(index, {
contextWindow: event.target.value.replace(
/[^\d]/g,
"",
),
})
}
placeholder={t(
"codexConfig.contextWindowPlaceholder",
{
defaultValue: "例如: 128000",
},
)}
aria-label={t("codexConfig.catalogColumnContext", {
defaultValue: "上下文窗口",
})}
/>
<Button
type="button"
variant="ghost"
size="icon"
className="h-9 w-9 text-muted-foreground hover:text-destructive"
onClick={() => handleRemoveCatalogRow(index)}
title={t("common.delete", { defaultValue: "删除" })}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
))}
</div>
)}
</div>
)}
))}
</div>
)}
</div>
)}
</CollapsibleContent>
</Collapsible>
)}
@@ -180,10 +180,24 @@ export const normalizeCodexCatalogModelsForSave = (
? Number.parseInt(rawContextWindow, 10)
: undefined;
const inputModalities = item.inputModalities?.filter(
(m) => typeof m === "string" && m.trim(),
);
const baseInstructions = item.baseInstructions?.trim();
normalized.push({
model,
...(displayName ? { displayName } : {}),
...(contextWindow && contextWindow > 0 ? { contextWindow } : {}),
// Native Responses profile overrides (ignored by the chat/proxy profile).
...(typeof item.supportsParallelToolCalls === "boolean"
? { supportsParallelToolCalls: item.supportsParallelToolCalls }
: {}),
...(inputModalities && inputModalities.length > 0
? { inputModalities }
: {}),
...(baseInstructions ? { baseInstructions } : {}),
});
}
@@ -599,7 +613,12 @@ function ProviderFormFull({
// 接管已开)。只在 useState 初始化与预设重置点设置,跟 localCodexApiFormat
// 对称,避免漂移。
const [codexTakeoverEnabled, setCodexTakeoverEnabled] = useState<boolean>(
() => codexCatalogCountFromSettings(initialData?.settingsConfig) > 0,
() =>
// Native (openai_responses) providers run DIRECT (no proxy takeover) yet
// still carry a modelCatalog so cc-switch can generate model-catalogs.json.
// So a catalog must NOT auto-enable takeover for native providers.
initialCodexApiFormat !== "openai_responses" &&
codexCatalogCountFromSettings(initialData?.settingsConfig) > 0,
);
const { configError: codexConfigError, debouncedValidate } =
@@ -1277,8 +1296,13 @@ function ProviderFormFull({
category !== "official" && (codexConfig ?? "").trim()
? setCodexWireApi(codexConfig ?? "", "responses")
: (codexConfig ?? "");
// Persist the catalog for proxy-takeover (Mode A) OR native-direct
// (Mode B, apiFormat=openai_responses). Native providers run without the
// proxy but still need cc-switch to generate model-catalogs.json, so the
// catalog must survive even when the takeover toggle is off.
const normalizedCatalogModels =
category !== "official" && codexTakeoverEnabled
category !== "official" &&
(codexTakeoverEnabled || localCodexApiFormat === "openai_responses")
? normalizeCodexCatalogModelsForSave(codexCatalogModels)
: [];
// Sync first catalog row's model into config.toml so Codex uses it as default
@@ -1671,8 +1695,12 @@ function ProviderFormFull({
codexApiFormatFromWireApi(extractCodexWireApi(config)) ??
"openai_responses",
);
// 路由开关与格式无关,仅按预设是否带模型映射决定
setCodexTakeoverEnabled((preset.modelCatalog?.length ?? 0) > 0);
// 接管开关:原生(openai_responses)预设走直连、不开接管,即便带 catalog
//catalog 用于生成 model-catalogs.json);只有 chat 预设按是否带映射开启。
setCodexTakeoverEnabled(
(preset.apiFormat ?? "openai_responses") !== "openai_responses" &&
(preset.modelCatalog?.length ?? 0) > 0,
);
form.reset({
name: preset.nameKey ? t(preset.nameKey) : preset.name,
+109 -1
View File
@@ -71,7 +71,20 @@ requires_openai_auth = true`;
function modelCatalog(
models: Array<
string | { model: string; displayName?: string; contextWindow?: number }
| string
| {
model: string;
displayName?: string;
contextWindow?: number;
// Native Responses (direct) overrides for the generated
// model-catalogs.json; omit to inherit the native template defaults
// (supports_parallel_tool_calls=false, input_modalities=["text"]).
supportsParallelToolCalls?: boolean;
inputModalities?: string[];
// Vendor's OFFICIAL base_instructions; omit to inherit the neutral
// template default. Required by Codex, so the backend always emits one.
baseInstructions?: string;
}
>,
): CodexCatalogModel[] {
return models.map((entry) =>
@@ -81,6 +94,9 @@ function modelCatalog(
model: entry.model,
displayName: entry.displayName,
contextWindow: entry.contextWindow,
supportsParallelToolCalls: entry.supportsParallelToolCalls,
inputModalities: entry.inputModalities,
baseInstructions: entry.baseInstructions,
},
);
}
@@ -204,6 +220,15 @@ export const codexProviderPresets: CodexProviderPreset[] = [
endpointCandidates: ["https://ark.cn-beijing.volces.com/api/v3"],
// 火山方舟主数据面 /api/v3 原生支持 Responses API/api/v3/responses),无需路由接管转换
apiFormat: "openai_responses",
// 无官方 catalog:合成 MiMo 式(shell_command 编辑、不发 freeform apply_patch),
// 让 Codex 直连显示模型并避免 custom 工具被网关拒绝
modelCatalog: modelCatalog([
{
model: "doubao-seed-2-1-pro",
displayName: "Doubao Seed 2.1 Pro",
contextWindow: 262144,
},
]),
category: "cn_official",
isPartner: true,
partnerPromotionKey: "doubaoseed",
@@ -411,6 +436,14 @@ requires_openai_auth = true`,
endpointCandidates: ["https://dashscope.aliyuncs.com/compatible-mode/v1"],
// 阿里百炼 DashScope 原生支持 OpenAI Responses API/compatible-mode/v1/responses,同一 base_url),无需路由接管转换
apiFormat: "openai_responses",
// 无官方 catalog:合成 MiMo 式(shell_command 编辑、不发 freeform apply_patch
modelCatalog: modelCatalog([
{
model: "qwen3-coder-plus",
displayName: "Qwen3 Coder Plus",
contextWindow: 1048576,
},
]),
category: "cn_official",
icon: "bailian",
iconColor: "#624AFF",
@@ -586,6 +619,15 @@ requires_openai_auth = true`,
endpointCandidates: ["https://api.longcat.chat/openai/v1"],
// 美团 LongCat 官方 Codex 文档用 wire_api=responses 对自家 base_url,原生 Responses,无需路由接管转换
apiFormat: "openai_responses",
// 无官方 catalog:合成 MiMo 式(shell_command 编辑、不发 freeform apply_patch)。
// 注:LongCat 的 /responses 工具类型契约文档化程度最低,建议真机冒烟一次
modelCatalog: modelCatalog([
{
model: "LongCat-2.0-Preview",
displayName: "LongCat 2.0 Preview",
contextWindow: 131072,
},
]),
category: "cn_official",
icon: "longcat",
iconColor: "#29E154",
@@ -603,6 +645,19 @@ requires_openai_auth = true`,
endpointCandidates: ["https://api.minimaxi.com/v1"],
// MiniMax 官方 API 参考已列 /v1/responses 为正式端点(CN/intl 双区,POST /v1/responses),原生 Responses,无需路由接管转换
apiFormat: "openai_responses",
// 官方 Codex catalogplatform.minimaxi.com/docs/token-plan/codex-cli):
// shell_command 编辑、并行工具、文本+图像,不声明 freeform apply_patch
modelCatalog: modelCatalog([
{
model: "MiniMax-M3",
displayName: "MiniMax-M3",
contextWindow: 1000000,
supportsParallelToolCalls: true,
inputModalities: ["text", "image"],
baseInstructions:
"You are Codex, a coding agent based on MiniMax-M3. You and the user share the same workspace and collaborate to achieve the user's goals.",
},
]),
category: "cn_official",
partnerPromotionKey: "minimax_cn",
theme: {
@@ -625,6 +680,19 @@ requires_openai_auth = true`,
endpointCandidates: ["https://api.minimax.io/v1"],
// MiniMax 官方 API 参考已列 /v1/responses 为正式端点(CN/intl 双区,POST /v1/responses),原生 Responses,无需路由接管转换
apiFormat: "openai_responses",
// 官方 Codex catalogplatform.minimax.io/docs/token-plan/codex):
// shell_command 编辑、并行工具、文本+图像,不声明 freeform apply_patch
modelCatalog: modelCatalog([
{
model: "MiniMax-M3",
displayName: "MiniMax-M3",
contextWindow: 1000000,
supportsParallelToolCalls: true,
inputModalities: ["text", "image"],
baseInstructions:
"You are Codex, a coding agent based on MiniMax-M3. You and the user share the same workspace and collaborate to achieve the user's goals.",
},
]),
category: "cn_official",
partnerPromotionKey: "minimax_en",
theme: {
@@ -668,6 +736,26 @@ requires_openai_auth = true`,
endpointCandidates: ["https://api.xiaomimimo.com/v1"],
// 小米 MiMo 官方 Codex 文档已声明原生支持 Responses APIwire_api=responses 对自家 base_url),无需路由接管转换
apiFormat: "openai_responses",
// 官方 Codex catalogmimo.mi.com/.../codex-configuration):
// shell_command 编辑、不声明 freeform apply_patch
modelCatalog: modelCatalog([
{
model: "mimo-v2.5-pro",
displayName: "MiMo V2.5 Pro",
contextWindow: 1048576,
inputModalities: ["text"],
baseInstructions:
"You are MiMo, an AI assistant developed by Xiaomi. Today's date: {date} {week}. Your knowledge cutoff date is December 2024.",
},
{
model: "mimo-v2.5",
displayName: "MiMo V2.5",
contextWindow: 1048576,
inputModalities: ["text", "image"],
baseInstructions:
"You are MiMo, an AI assistant developed by Xiaomi. Today's date: {date} {week}. Your knowledge cutoff date is December 2024.",
},
]),
category: "cn_official",
icon: "xiaomimimo",
iconColor: "#000000",
@@ -685,6 +773,26 @@ requires_openai_auth = true`,
endpointCandidates: ["https://token-plan-cn.xiaomimimo.com/v1"],
// 小米 MiMo 官方 Codex 文档已声明原生支持 Responses APIwire_api=responses 对自家 base_url),无需路由接管转换
apiFormat: "openai_responses",
// 官方 Codex catalogmimo.mi.com/.../codex-configuration):
// shell_command 编辑、不声明 freeform apply_patch
modelCatalog: modelCatalog([
{
model: "mimo-v2.5-pro",
displayName: "MiMo V2.5 Pro",
contextWindow: 1048576,
inputModalities: ["text"],
baseInstructions:
"You are MiMo, an AI assistant developed by Xiaomi. Today's date: {date} {week}. Your knowledge cutoff date is December 2024.",
},
{
model: "mimo-v2.5",
displayName: "MiMo V2.5",
contextWindow: 1048576,
inputModalities: ["text", "image"],
baseInstructions:
"You are MiMo, an AI assistant developed by Xiaomi. Today's date: {date} {week}. Your knowledge cutoff date is December 2024.",
},
]),
category: "cn_official",
icon: "xiaomimimo",
iconColor: "#000000",
+9
View File
@@ -258,6 +258,15 @@ export interface CodexCatalogModel {
model: string;
displayName?: string;
contextWindow?: string | number;
// Native Responses (direct) profile overrides for the generated
// model-catalogs.json. Ignored by the chat/proxy profile.
// e.g. MiniMax: supportsParallelToolCalls=true, inputModalities=["text","image"].
supportsParallelToolCalls?: boolean;
inputModalities?: string[];
// Vendor's OFFICIAL base_instructions (model identity / system preamble).
// Codex requires this field in every catalog entry; when omitted the backend
// falls back to a neutral default. e.g. MiMo "developed by Xiaomi".
baseInstructions?: string;
}
// Claude 认证字段类型