2025-08-30 22:08:41 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Codex 预设供应商配置模板
|
|
|
|
|
|
*/
|
2025-09-11 22:33:55 +08:00
|
|
|
|
import { ProviderCategory } from "../types";
|
2025-11-02 21:05:48 +08:00
|
|
|
|
import type { PresetTheme } from "./claudeProviderPresets";
|
2025-09-11 22:33:55 +08:00
|
|
|
|
|
2025-08-30 22:08:41 +08:00
|
|
|
|
export interface CodexProviderPreset {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
websiteUrl: string;
|
2025-10-01 21:28:09 +08:00
|
|
|
|
// 第三方供应商可提供单独的获取 API Key 链接
|
|
|
|
|
|
apiKeyUrl?: string;
|
2025-08-30 22:08:41 +08:00
|
|
|
|
auth: Record<string, any>; // 将写入 ~/.codex/auth.json
|
|
|
|
|
|
config: string; // 将写入 ~/.codex/config.toml(TOML 字符串)
|
|
|
|
|
|
isOfficial?: boolean; // 标识是否为官方预设
|
2025-09-11 22:33:55 +08:00
|
|
|
|
category?: ProviderCategory; // 新增:分类
|
2025-09-21 19:04:56 +08:00
|
|
|
|
isCustomTemplate?: boolean; // 标识是否为自定义模板
|
feat: Implement Speed Test Function
* feat: add unified endpoint speed test for API providers
Add a comprehensive endpoint latency testing system that allows users to:
- Test multiple API endpoints concurrently
- Auto-select the fastest endpoint based on latency
- Add/remove custom endpoints dynamically
- View latency results with color-coded indicators
Backend (Rust):
- Implement parallel HTTP HEAD requests with configurable timeout
- Handle various error scenarios (timeout, connection failure, invalid URL)
- Return structured latency data with status codes
Frontend (React):
- Create interactive speed test UI component with auto-sort by latency
- Support endpoint management (add/remove custom endpoints)
- Extract and update Codex base_url from TOML configuration
- Integrate with provider presets for default endpoint candidates
This feature improves user experience when selecting optimal API endpoints,
especially useful for users with multiple provider options or proxy setups.
* refactor: convert endpoint speed test to modal dialog
- Transform EndpointSpeedTest component into a modal dialog
- Add "Advanced" button next to base URL input to open modal
- Support ESC key and backdrop click to close modal
- Apply Linear design principles: minimal styling, clean layout
- Remove unused showBaseUrlInput variable
- Implement same modal pattern for both Claude and Codex
* fix: prevent modal cascade closing when ESC is pressed
- Add state checks to prevent parent modal from closing when child modals (endpoint speed test or template wizard) are open
- Update ESC key handler dependencies to track all modal states
- Ensures only the topmost modal responds to ESC key
* refactor: unify speed test panel UI with project design system
UI improvements:
- Update modal border radius from rounded-lg to rounded-xl
- Unify header padding from px-6 py-4 to p-6
- Change speed test button color to blue theme (bg-blue-500) for consistency
- Update footer background from bg-gray-50 to bg-gray-100
- Style "Done" button as primary action button with blue theme
- Adjust footer button spacing and hover states
Simplify endpoint display:
- Remove endpoint labels (e.g., "Current Address", "Custom 1")
- Display only URL for cleaner interface
- Clean up all label-related logic:
* Remove label field from EndpointCandidate interface
* Remove label generation in buildInitialEntries function
* Remove label handling in useEffect merge logic
* Remove label generation in handleAddEndpoint
* Remove label parameters from claudeSpeedTestEndpoints
* Remove label parameters from codexSpeedTestEndpoints
* refactor: improve endpoint list UI consistency
- Show delete button for all endpoints on hover for uniform UI
- Change selected state to use blue theme matching main interface:
* Blue border (border-blue-500) for selected items
* Light blue background (bg-blue-50/dark:bg-blue-900/20)
* Blue indicator dot (bg-blue-500/dark:bg-blue-400)
- Switch from compact list (space-y-px) to card-based layout (space-y-2)
- Add rounded corners to each endpoint item for better visual separation
* feat: persist custom endpoints to settings.json
- Extend AppSettings to store custom endpoints for Claude and Codex
- Add Tauri commands: get/add/remove/update custom endpoints
- Update frontend API with endpoint persistence methods
- Modify EndpointSpeedTest to load/save custom endpoints via API
- Track endpoint last used time for future sorting/cleanup
- Store endpoints per app type in settings.json instead of localStorage
* - feat(types): add Provider.meta and ProviderMeta (snake_case) with custom_endpoints map
- feat(provider-form): persist custom endpoints on provider create by merging EndpointSpeedTest’s custom URLs into meta.custom_endpoints on submit
- feat(endpoint-speed-test): add onCustomEndpointsChange callback emitting normalized custom URLs; wire it for both Claude/Codex modals
- fix(api): send alias param names (app/appType/app_type and provider_id/providerId) in Tauri invokes to avoid “missing providerId” with older backends
- storage: custom endpoints are stored in ~/.cc-switch/config.json under providers[<id>].meta.custom_endpoints (not in settings.json)
- behavior: edit flow remains immediate writes; create flow now writes once via addProvider, removing the providerId dependency during creation
* feat: add endpoint candidates support and code formatting improvements
- Add endpointCandidates field to ProviderPreset and CodexProviderPreset interfaces
- Integrate preset endpoint candidates into speed test endpoint selection
- Add multiple endpoint options for PackyCode providers (Claude & Codex)
- Apply consistent code formatting (trailing commas, line breaks)
- Improve template value type safety and readability
* refactor: improve endpoint management button UX
Replace ambiguous "Advanced" text with intuitive "Manage & Test" label accompanied by Zap icon, making the endpoint management panel entry point more discoverable and self-explanatory for both Claude and Codex configurations.
* - merge: merge origin/main, resolve conflicts and preserve both feature sets
- feat(tauri): register import/export and file dialogs; keep endpoint speed test and custom endpoints
- feat(api): add updateTrayMenu and onProviderSwitched; wire import/export APIs
- feat(types): extend global API declarations (import/export)
- chore(presets): GLM preset supports both new and legacy model keys
- chore(rust): add chrono dependency; refresh lockfile
---------
Co-authored-by: Jason <farion1231@gmail.com>
2025-10-07 19:14:32 +08:00
|
|
|
|
// 新增:请求地址候选列表(用于地址管理/测速)
|
|
|
|
|
|
endpointCandidates?: string[];
|
2025-10-19 23:11:48 +08:00
|
|
|
|
// 新增:视觉主题配置
|
|
|
|
|
|
theme?: PresetTheme;
|
2025-09-21 19:04:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生成第三方供应商的 auth.json
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function generateThirdPartyAuth(apiKey: string): Record<string, any> {
|
|
|
|
|
|
return {
|
2025-10-23 16:53:42 +08:00
|
|
|
|
OPENAI_API_KEY: apiKey || "",
|
2025-09-21 19:04:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生成第三方供应商的 config.toml
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function generateThirdPartyConfig(
|
|
|
|
|
|
providerName: string,
|
|
|
|
|
|
baseUrl: string,
|
2025-10-08 21:22:56 +08:00
|
|
|
|
modelName = "gpt-5-codex",
|
2025-09-21 19:04:56 +08:00
|
|
|
|
): string {
|
|
|
|
|
|
// 清理供应商名称,确保符合TOML键名规范
|
2025-09-28 09:53:55 +08:00
|
|
|
|
const cleanProviderName =
|
|
|
|
|
|
providerName
|
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
|
.replace(/[^a-z0-9_]/g, "_")
|
|
|
|
|
|
.replace(/^_+|_+$/g, "") || "custom";
|
|
|
|
|
|
|
2025-09-21 19:04:56 +08:00
|
|
|
|
return `model_provider = "${cleanProviderName}"
|
|
|
|
|
|
model = "${modelName}"
|
|
|
|
|
|
model_reasoning_effort = "high"
|
|
|
|
|
|
disable_response_storage = true
|
|
|
|
|
|
|
|
|
|
|
|
[model_providers.${cleanProviderName}]
|
|
|
|
|
|
name = "${cleanProviderName}"
|
|
|
|
|
|
base_url = "${baseUrl}"
|
2025-10-10 16:00:12 +08:00
|
|
|
|
wire_api = "responses"
|
|
|
|
|
|
requires_openai_auth = true`;
|
2025-08-30 22:08:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const codexProviderPresets: CodexProviderPreset[] = [
|
|
|
|
|
|
{
|
2025-10-08 11:02:09 +08:00
|
|
|
|
name: "Codex Official",
|
2025-08-30 23:02:49 +08:00
|
|
|
|
websiteUrl: "https://chatgpt.com/codex",
|
2025-08-30 22:08:41 +08:00
|
|
|
|
isOfficial: true,
|
2025-09-11 22:33:55 +08:00
|
|
|
|
category: "official",
|
2025-10-23 16:04:35 +08:00
|
|
|
|
auth: {},
|
2025-08-30 23:02:49 +08:00
|
|
|
|
config: ``,
|
2025-10-19 23:11:48 +08:00
|
|
|
|
theme: {
|
|
|
|
|
|
icon: "codex",
|
|
|
|
|
|
backgroundColor: "#1F2937", // gray-800
|
|
|
|
|
|
textColor: "#FFFFFF",
|
|
|
|
|
|
},
|
2025-08-30 22:08:41 +08:00
|
|
|
|
},
|
2025-11-05 10:29:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: "Azure OpenAI (gpt-5-codex)",
|
|
|
|
|
|
websiteUrl:
|
|
|
|
|
|
"https://learn.microsoft.com/azure/ai-services/openai/how-to/overview",
|
|
|
|
|
|
category: "third_party",
|
|
|
|
|
|
isOfficial: true,
|
|
|
|
|
|
auth: generateThirdPartyAuth(""),
|
|
|
|
|
|
config: `model_provider = "azure"
|
|
|
|
|
|
model = "gpt-5-codex"
|
|
|
|
|
|
model_reasoning_effort = "high"
|
|
|
|
|
|
disable_response_storage = true
|
|
|
|
|
|
|
|
|
|
|
|
[model_providers.azure]
|
|
|
|
|
|
name = "Azure OpenAI (gpt-5-codex)"
|
|
|
|
|
|
base_url = "https://YOUR_RESOURCE_NAME.openai.azure.com/openai"
|
|
|
|
|
|
env_key = "OPENAI_API_KEY"
|
|
|
|
|
|
query_params = { "api-version" = "2025-04-01-preview" }
|
|
|
|
|
|
wire_api = "responses"
|
|
|
|
|
|
requires_openai_auth = true`,
|
|
|
|
|
|
endpointCandidates: ["https://YOUR_RESOURCE_NAME.openai.azure.com/openai"],
|
|
|
|
|
|
theme: {
|
|
|
|
|
|
icon: "codex",
|
|
|
|
|
|
backgroundColor: "#0078D4",
|
|
|
|
|
|
textColor: "#FFFFFF",
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-11-02 22:22:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: "AiHubMix",
|
|
|
|
|
|
websiteUrl: "https://aihubmix.com",
|
2025-11-02 23:24:49 +08:00
|
|
|
|
category: "aggregator",
|
2025-11-02 22:22:45 +08:00
|
|
|
|
auth: generateThirdPartyAuth(""),
|
|
|
|
|
|
config: generateThirdPartyConfig(
|
|
|
|
|
|
"aihubmix",
|
|
|
|
|
|
"https://aihubmix.com/v1",
|
|
|
|
|
|
"gpt-5-codex",
|
|
|
|
|
|
),
|
|
|
|
|
|
endpointCandidates: [
|
|
|
|
|
|
"https://aihubmix.com/v1",
|
|
|
|
|
|
"https://api.aihubmix.com/v1",
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
2025-08-30 22:08:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: "PackyCode",
|
2025-11-02 21:51:14 +08:00
|
|
|
|
websiteUrl: "https://www.packyapi.com",
|
2025-09-11 22:33:55 +08:00
|
|
|
|
category: "third_party",
|
2025-10-23 16:53:42 +08:00
|
|
|
|
auth: generateThirdPartyAuth(""),
|
2025-09-21 19:04:56 +08:00
|
|
|
|
config: generateThirdPartyConfig(
|
|
|
|
|
|
"packycode",
|
2025-11-02 21:51:14 +08:00
|
|
|
|
"https://www.packyapi.com/v1",
|
2025-10-08 21:22:56 +08:00
|
|
|
|
"gpt-5-codex",
|
2025-09-21 19:04:56 +08:00
|
|
|
|
),
|
feat: Implement Speed Test Function
* feat: add unified endpoint speed test for API providers
Add a comprehensive endpoint latency testing system that allows users to:
- Test multiple API endpoints concurrently
- Auto-select the fastest endpoint based on latency
- Add/remove custom endpoints dynamically
- View latency results with color-coded indicators
Backend (Rust):
- Implement parallel HTTP HEAD requests with configurable timeout
- Handle various error scenarios (timeout, connection failure, invalid URL)
- Return structured latency data with status codes
Frontend (React):
- Create interactive speed test UI component with auto-sort by latency
- Support endpoint management (add/remove custom endpoints)
- Extract and update Codex base_url from TOML configuration
- Integrate with provider presets for default endpoint candidates
This feature improves user experience when selecting optimal API endpoints,
especially useful for users with multiple provider options or proxy setups.
* refactor: convert endpoint speed test to modal dialog
- Transform EndpointSpeedTest component into a modal dialog
- Add "Advanced" button next to base URL input to open modal
- Support ESC key and backdrop click to close modal
- Apply Linear design principles: minimal styling, clean layout
- Remove unused showBaseUrlInput variable
- Implement same modal pattern for both Claude and Codex
* fix: prevent modal cascade closing when ESC is pressed
- Add state checks to prevent parent modal from closing when child modals (endpoint speed test or template wizard) are open
- Update ESC key handler dependencies to track all modal states
- Ensures only the topmost modal responds to ESC key
* refactor: unify speed test panel UI with project design system
UI improvements:
- Update modal border radius from rounded-lg to rounded-xl
- Unify header padding from px-6 py-4 to p-6
- Change speed test button color to blue theme (bg-blue-500) for consistency
- Update footer background from bg-gray-50 to bg-gray-100
- Style "Done" button as primary action button with blue theme
- Adjust footer button spacing and hover states
Simplify endpoint display:
- Remove endpoint labels (e.g., "Current Address", "Custom 1")
- Display only URL for cleaner interface
- Clean up all label-related logic:
* Remove label field from EndpointCandidate interface
* Remove label generation in buildInitialEntries function
* Remove label handling in useEffect merge logic
* Remove label generation in handleAddEndpoint
* Remove label parameters from claudeSpeedTestEndpoints
* Remove label parameters from codexSpeedTestEndpoints
* refactor: improve endpoint list UI consistency
- Show delete button for all endpoints on hover for uniform UI
- Change selected state to use blue theme matching main interface:
* Blue border (border-blue-500) for selected items
* Light blue background (bg-blue-50/dark:bg-blue-900/20)
* Blue indicator dot (bg-blue-500/dark:bg-blue-400)
- Switch from compact list (space-y-px) to card-based layout (space-y-2)
- Add rounded corners to each endpoint item for better visual separation
* feat: persist custom endpoints to settings.json
- Extend AppSettings to store custom endpoints for Claude and Codex
- Add Tauri commands: get/add/remove/update custom endpoints
- Update frontend API with endpoint persistence methods
- Modify EndpointSpeedTest to load/save custom endpoints via API
- Track endpoint last used time for future sorting/cleanup
- Store endpoints per app type in settings.json instead of localStorage
* - feat(types): add Provider.meta and ProviderMeta (snake_case) with custom_endpoints map
- feat(provider-form): persist custom endpoints on provider create by merging EndpointSpeedTest’s custom URLs into meta.custom_endpoints on submit
- feat(endpoint-speed-test): add onCustomEndpointsChange callback emitting normalized custom URLs; wire it for both Claude/Codex modals
- fix(api): send alias param names (app/appType/app_type and provider_id/providerId) in Tauri invokes to avoid “missing providerId” with older backends
- storage: custom endpoints are stored in ~/.cc-switch/config.json under providers[<id>].meta.custom_endpoints (not in settings.json)
- behavior: edit flow remains immediate writes; create flow now writes once via addProvider, removing the providerId dependency during creation
* feat: add endpoint candidates support and code formatting improvements
- Add endpointCandidates field to ProviderPreset and CodexProviderPreset interfaces
- Integrate preset endpoint candidates into speed test endpoint selection
- Add multiple endpoint options for PackyCode providers (Claude & Codex)
- Apply consistent code formatting (trailing commas, line breaks)
- Improve template value type safety and readability
* refactor: improve endpoint management button UX
Replace ambiguous "Advanced" text with intuitive "Manage & Test" label accompanied by Zap icon, making the endpoint management panel entry point more discoverable and self-explanatory for both Claude and Codex configurations.
* - merge: merge origin/main, resolve conflicts and preserve both feature sets
- feat(tauri): register import/export and file dialogs; keep endpoint speed test and custom endpoints
- feat(api): add updateTrayMenu and onProviderSwitched; wire import/export APIs
- feat(types): extend global API declarations (import/export)
- chore(presets): GLM preset supports both new and legacy model keys
- chore(rust): add chrono dependency; refresh lockfile
---------
Co-authored-by: Jason <farion1231@gmail.com>
2025-10-07 19:14:32 +08:00
|
|
|
|
endpointCandidates: [
|
2025-11-02 21:51:14 +08:00
|
|
|
|
"https://www.packyapi.com/v1",
|
|
|
|
|
|
"https://api-slb.packyapi.com/v1",
|
2025-10-23 16:53:42 +08:00
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "AnyRouter",
|
|
|
|
|
|
websiteUrl: "https://anyrouter.top",
|
|
|
|
|
|
category: "third_party",
|
|
|
|
|
|
auth: generateThirdPartyAuth(""),
|
|
|
|
|
|
config: generateThirdPartyConfig(
|
|
|
|
|
|
"anyrouter",
|
2025-11-02 22:22:45 +08:00
|
|
|
|
"https://anyrouter.top/v1",
|
2025-10-23 16:53:42 +08:00
|
|
|
|
"gpt-5-codex",
|
|
|
|
|
|
),
|
|
|
|
|
|
endpointCandidates: [
|
2025-11-02 22:22:45 +08:00
|
|
|
|
"https://anyrouter.top/v1",
|
|
|
|
|
|
"https://q.quuvv.cn/v1",
|
|
|
|
|
|
"https://pmpjfbhq.cn-nb1.rainapp.top/v1",
|
feat: Implement Speed Test Function
* feat: add unified endpoint speed test for API providers
Add a comprehensive endpoint latency testing system that allows users to:
- Test multiple API endpoints concurrently
- Auto-select the fastest endpoint based on latency
- Add/remove custom endpoints dynamically
- View latency results with color-coded indicators
Backend (Rust):
- Implement parallel HTTP HEAD requests with configurable timeout
- Handle various error scenarios (timeout, connection failure, invalid URL)
- Return structured latency data with status codes
Frontend (React):
- Create interactive speed test UI component with auto-sort by latency
- Support endpoint management (add/remove custom endpoints)
- Extract and update Codex base_url from TOML configuration
- Integrate with provider presets for default endpoint candidates
This feature improves user experience when selecting optimal API endpoints,
especially useful for users with multiple provider options or proxy setups.
* refactor: convert endpoint speed test to modal dialog
- Transform EndpointSpeedTest component into a modal dialog
- Add "Advanced" button next to base URL input to open modal
- Support ESC key and backdrop click to close modal
- Apply Linear design principles: minimal styling, clean layout
- Remove unused showBaseUrlInput variable
- Implement same modal pattern for both Claude and Codex
* fix: prevent modal cascade closing when ESC is pressed
- Add state checks to prevent parent modal from closing when child modals (endpoint speed test or template wizard) are open
- Update ESC key handler dependencies to track all modal states
- Ensures only the topmost modal responds to ESC key
* refactor: unify speed test panel UI with project design system
UI improvements:
- Update modal border radius from rounded-lg to rounded-xl
- Unify header padding from px-6 py-4 to p-6
- Change speed test button color to blue theme (bg-blue-500) for consistency
- Update footer background from bg-gray-50 to bg-gray-100
- Style "Done" button as primary action button with blue theme
- Adjust footer button spacing and hover states
Simplify endpoint display:
- Remove endpoint labels (e.g., "Current Address", "Custom 1")
- Display only URL for cleaner interface
- Clean up all label-related logic:
* Remove label field from EndpointCandidate interface
* Remove label generation in buildInitialEntries function
* Remove label handling in useEffect merge logic
* Remove label generation in handleAddEndpoint
* Remove label parameters from claudeSpeedTestEndpoints
* Remove label parameters from codexSpeedTestEndpoints
* refactor: improve endpoint list UI consistency
- Show delete button for all endpoints on hover for uniform UI
- Change selected state to use blue theme matching main interface:
* Blue border (border-blue-500) for selected items
* Light blue background (bg-blue-50/dark:bg-blue-900/20)
* Blue indicator dot (bg-blue-500/dark:bg-blue-400)
- Switch from compact list (space-y-px) to card-based layout (space-y-2)
- Add rounded corners to each endpoint item for better visual separation
* feat: persist custom endpoints to settings.json
- Extend AppSettings to store custom endpoints for Claude and Codex
- Add Tauri commands: get/add/remove/update custom endpoints
- Update frontend API with endpoint persistence methods
- Modify EndpointSpeedTest to load/save custom endpoints via API
- Track endpoint last used time for future sorting/cleanup
- Store endpoints per app type in settings.json instead of localStorage
* - feat(types): add Provider.meta and ProviderMeta (snake_case) with custom_endpoints map
- feat(provider-form): persist custom endpoints on provider create by merging EndpointSpeedTest’s custom URLs into meta.custom_endpoints on submit
- feat(endpoint-speed-test): add onCustomEndpointsChange callback emitting normalized custom URLs; wire it for both Claude/Codex modals
- fix(api): send alias param names (app/appType/app_type and provider_id/providerId) in Tauri invokes to avoid “missing providerId” with older backends
- storage: custom endpoints are stored in ~/.cc-switch/config.json under providers[<id>].meta.custom_endpoints (not in settings.json)
- behavior: edit flow remains immediate writes; create flow now writes once via addProvider, removing the providerId dependency during creation
* feat: add endpoint candidates support and code formatting improvements
- Add endpointCandidates field to ProviderPreset and CodexProviderPreset interfaces
- Integrate preset endpoint candidates into speed test endpoint selection
- Add multiple endpoint options for PackyCode providers (Claude & Codex)
- Apply consistent code formatting (trailing commas, line breaks)
- Improve template value type safety and readability
* refactor: improve endpoint management button UX
Replace ambiguous "Advanced" text with intuitive "Manage & Test" label accompanied by Zap icon, making the endpoint management panel entry point more discoverable and self-explanatory for both Claude and Codex configurations.
* - merge: merge origin/main, resolve conflicts and preserve both feature sets
- feat(tauri): register import/export and file dialogs; keep endpoint speed test and custom endpoints
- feat(api): add updateTrayMenu and onProviderSwitched; wire import/export APIs
- feat(types): extend global API declarations (import/export)
- chore(presets): GLM preset supports both new and legacy model keys
- chore(rust): add chrono dependency; refresh lockfile
---------
Co-authored-by: Jason <farion1231@gmail.com>
2025-10-07 19:14:32 +08:00
|
|
|
|
],
|
2025-08-30 22:08:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
];
|