feat(claude-desktop): add 3P provider switching with proxy gateway

Adds a new ClaudeDesktop AppType that writes Claude Desktop's third-party
inference profile under configLibrary/, sharing _meta.json with other
launchers (Ollama-compatible) so cc-switch can coexist with them.

Two switch modes:
- direct: provider already exposes claude-* / anthropic/claude-* model
  ids on Anthropic Messages, Claude Desktop connects to it directly.
- proxy: cc-switch's local proxy acts as the inference gateway,
  presenting only claude-* route names to Claude Desktop and mapping
  them to real upstream models. Required after Anthropic restricted
  Claude Desktop to claude-family ids.

Backend:
- New module claude_desktop_config with snapshot/rollback, official seed
  bypass, /claude-desktop/v1/{models,messages} routes, and a single
  source of truth for default proxy routes.
- Gateway token persisted in SQLite, validated on every proxied request.
- get_claude_desktop_status surfaces drift signals (stale models,
  missing routes, proxy stopped, base URL mismatch, missing token).

Frontend:
- Slim ClaudeDesktopProviderForm independent from ProviderForm,
  controlled by a top-level appId guard.
- ProviderList banner consumes the status query (5s polling) and
  renders actionable diagnostics.
- ClaudeDesktopRouteToggle in the header to start/stop the local
  gateway without touching takeover state.
- Three-locale i18n synchronised.
This commit is contained in:
Jason
2026-05-08 11:50:01 +08:00
parent e15bfbfe7a
commit 8b3ad9caf9
64 changed files with 3328 additions and 109 deletions
+34
View File
@@ -25,6 +25,28 @@ export interface OpenTerminalOptions {
cwd?: string;
}
export interface ClaudeDesktopStatus {
supported: boolean;
configured: boolean;
appliedId?: string | null;
profilePath?: string | null;
configLibraryPath?: string | null;
mode?: "direct" | "proxy" | null;
expectedBaseUrl?: string | null;
actualBaseUrl?: string | null;
proxyRunning: boolean;
staleRawModels: boolean;
missingRouteMappings: boolean;
gatewayTokenConfigured: boolean;
}
export interface ClaudeDesktopDefaultRoute {
routeId: string;
envKey: string;
displayName: string;
supports1m: boolean;
}
export const providersApi = {
async getAll(appId: AppId): Promise<Record<string, Provider>> {
return await invoke("get_providers", { app: appId });
@@ -74,6 +96,18 @@ export const providersApi = {
return await invoke("import_default_config", { app: appId });
},
async importClaudeDesktopFromClaude(): Promise<number> {
return await invoke("import_claude_desktop_providers_from_claude");
},
async getClaudeDesktopStatus(): Promise<ClaudeDesktopStatus> {
return await invoke("get_claude_desktop_status");
},
async getClaudeDesktopDefaultRoutes(): Promise<ClaudeDesktopDefaultRoute[]> {
return await invoke("get_claude_desktop_default_routes");
},
async updateTrayMenu(): Promise<boolean> {
return await invoke("update_tray_menu");
},
+2
View File
@@ -4,6 +4,7 @@ import type { AppId } from "@/lib/api/types";
export type AppType =
| "claude"
| "claude-desktop"
| "codex"
| "gemini"
| "opencode"
@@ -13,6 +14,7 @@ export type AppType =
/** Skill 应用启用状态 */
export interface SkillApps {
claude: boolean;
"claude-desktop"?: boolean;
codex: boolean;
gemini: boolean;
opencode: boolean;
+1
View File
@@ -1,6 +1,7 @@
// 前端统一使用 AppId 作为应用标识(与后端命令参数 `app` 一致)
export type AppId =
| "claude"
| "claude-desktop"
| "codex"
| "gemini"
| "opencode"