Files
cc-switch/src/config/codexProviderPresets.ts
Jason 972650377d feat(codex): add AiHubMix provider and enhance configuration UX
- Add new AiHubMix provider preset with dual endpoints
- Fix AnyRouter base_url inconsistency (add /v1 suffix)
- Add configuration wizard shortcut link for Codex custom mode
- Improve accessibility with aria-label for wizard button
- Remove unused isCustomMode prop from CodexConfigEditor
- Add internationalization for new UI elements (zh/en)
2025-11-02 22:22:45 +08:00

120 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Codex 预设供应商配置模板
*/
import { ProviderCategory } from "../types";
import type { PresetTheme } from "./claudeProviderPresets";
export interface CodexProviderPreset {
name: string;
websiteUrl: string;
// 第三方供应商可提供单独的获取 API Key 链接
apiKeyUrl?: string;
auth: Record<string, any>; // 将写入 ~/.codex/auth.json
config: string; // 将写入 ~/.codex/config.tomlTOML 字符串)
isOfficial?: boolean; // 标识是否为官方预设
category?: ProviderCategory; // 新增:分类
isCustomTemplate?: boolean; // 标识是否为自定义模板
// 新增:请求地址候选列表(用于地址管理/测速)
endpointCandidates?: string[];
// 新增:视觉主题配置
theme?: PresetTheme;
}
/**
* 生成第三方供应商的 auth.json
*/
export function generateThirdPartyAuth(apiKey: string): Record<string, any> {
return {
OPENAI_API_KEY: apiKey || "",
};
}
/**
* 生成第三方供应商的 config.toml
*/
export function generateThirdPartyConfig(
providerName: string,
baseUrl: string,
modelName = "gpt-5-codex",
): string {
// 清理供应商名称确保符合TOML键名规范
const cleanProviderName =
providerName
.toLowerCase()
.replace(/[^a-z0-9_]/g, "_")
.replace(/^_+|_+$/g, "") || "custom";
return `model_provider = "${cleanProviderName}"
model = "${modelName}"
model_reasoning_effort = "high"
disable_response_storage = true
[model_providers.${cleanProviderName}]
name = "${cleanProviderName}"
base_url = "${baseUrl}"
wire_api = "responses"
requires_openai_auth = true`;
}
export const codexProviderPresets: CodexProviderPreset[] = [
{
name: "Codex Official",
websiteUrl: "https://chatgpt.com/codex",
isOfficial: true,
category: "official",
auth: {},
config: ``,
theme: {
icon: "codex",
backgroundColor: "#1F2937", // gray-800
textColor: "#FFFFFF",
},
},
{
name: "AiHubMix",
websiteUrl: "https://aihubmix.com",
category: "cn_official",
auth: generateThirdPartyAuth(""),
config: generateThirdPartyConfig(
"aihubmix",
"https://aihubmix.com/v1",
"gpt-5-codex",
),
endpointCandidates: [
"https://aihubmix.com/v1",
"https://api.aihubmix.com/v1",
],
},
{
name: "PackyCode",
websiteUrl: "https://www.packyapi.com",
category: "third_party",
auth: generateThirdPartyAuth(""),
config: generateThirdPartyConfig(
"packycode",
"https://www.packyapi.com/v1",
"gpt-5-codex",
),
endpointCandidates: [
"https://www.packyapi.com/v1",
"https://api-slb.packyapi.com/v1",
],
},
{
name: "AnyRouter",
websiteUrl: "https://anyrouter.top",
category: "third_party",
auth: generateThirdPartyAuth(""),
config: generateThirdPartyConfig(
"anyrouter",
"https://anyrouter.top/v1",
"gpt-5-codex",
),
endpointCandidates: [
"https://anyrouter.top/v1",
"https://q.quuvv.cn/v1",
"https://pmpjfbhq.cn-nb1.rainapp.top/v1",
],
},
];