25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(ai): preserve distinct imported cc-switch profiles
_Mr丶s ゛😁®92814874edc6
diff --git a/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts b/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.tsindex e9706ebeb9..5040979faf 100644--- a/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts+++ b/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts@@ -112,4 +112,50 @@ describe("CC-SWITCH imports", () => {).map((config) => config.name),).toEqual(["Gateway (CC-SWITCH)", "Gateway (CC-SWITCH 2)"]);});++ it("keeps distinct profiles with matching connection settings and skips them on re-import", () => {+ const profiles = [+ {+ id: "codex-profile",+ name: "Codex Gateway",+ provider: "openai-compatible" as const,+ apiKey: "shared-key",+ authMethod: "bearer" as const,+ endpoint: "https://gateway.example",+ model: "gpt-test",+ apiStyle: "responses" as const,+ },+ {+ id: "claude-profile",+ name: "Claude Gateway",+ provider: "openai-compatible" as const,+ apiKey: "shared-key",+ authMethod: "bearer" as const,+ endpoint: "https://gateway.example",+ model: "gpt-test",+ apiStyle: "responses" as const,+ },+ ];++ const prepared = prepareImportedAiConfigs([], profiles);++ expect(prepared.map((config) => config.name)).toEqual(["Codex Gateway", "Claude Gateway"]);+ expect(prepareImportedAiConfigs(prepared, profiles)).toEqual([]);+ });++ it("collapses exact duplicates inside a single import batch", () => {+ const config = {+ id: "first",+ name: "Gateway",+ provider: "openai-compatible" as const,+ apiKey: "secret",+ authMethod: "bearer" as const,+ endpoint: "https://gateway.example",+ model: "gpt-test",+ apiStyle: "responses" as const,+ };+ const duplicate = { ...config, id: "second" };++ expect(prepareImportedAiConfigs([], [config, duplicate])).toEqual([{ ...config, name: "Gateway", isDefault: false }]);+ });});diff --git a/apps/desktop/src/lib/ai/aiConfigList.ts b/apps/desktop/src/lib/ai/aiConfigList.tsindex 43a9744688..7b7d857180 100644--- a/apps/desktop/src/lib/ai/aiConfigList.ts+++ b/apps/desktop/src/lib/ai/aiConfigList.ts@@ -15,14 +15,21 @@ export function getConfigKey(config: AiConfig): string {/** Prepare imported configurations without overwriting existing entries. */export function prepareImportedAiConfigs(existing: AiConfigItem[], imported: AiConfigItem[]): AiConfigItem[] {- const existingKeys = new Set(existing.map(getConfigKey));+ const existingImportCounts = new Map<string, number>();+ for (const config of existing) {+ const key = getImportedConfigKey(config);+ existingImportCounts.set(key, (existingImportCounts.get(key) ?? 0) + 1);+ }const usedNames = new Set(existing.map((config) => config.name.trim().toLocaleLowerCase()));const prepared: AiConfigItem[] = [];for (const config of imported) {- const key = getConfigKey(config);- if (existingKeys.has(key)) continue;- existingKeys.add(key);+ const key = getImportedConfigKey(config);+ const existingCount = existingImportCounts.get(key) ?? 0;+ if (existingCount > 0) {+ existingImportCounts.set(key, existingCount - 1);+ continue;+ }const originalName = config.name.trim() || "CC-SWITCH";let name = originalName;@@ -32,12 +39,21 @@ export function prepareImportedAiConfigs(existing: AiConfigItem[], imported: AiCname = `${originalName} (CC-SWITCH${suffix > 1 ? ` ${suffix}` : ""})`;}usedNames.add(name.toLocaleLowerCase());+ // Count the prepared entry so an exact duplicate later in the same batch is skipped.+ existingImportCounts.set(key, (existingImportCounts.get(key) ?? 0) + 1);prepared.push({ ...config, name, isDefault: false });}return prepared;}+function getImportedConfigKey(config: AiConfigItem): string {+ // Keep distinct CC-SWITCH profiles even when their connection settings match.+ // Strip the suffix added below so importing the same profiles again is idempotent.+ const sourceName = (config.name.trim() || "CC-SWITCH").replace(/ \(CC-SWITCH(?: \d+)?\)$/i, "").toLocaleLowerCase();+ return `${getConfigKey(config)}|${sourceName}`;+}+export function aiConfigToItem(config: AiConfig, id: string, name: string): AiConfigItem {return {...config,