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
feat(ai): allow deleting manually entered AI models
lxk955387d215c81ee
diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vueindex a60cda31c3..6a671c9988 100644--- a/apps/desktop/src/components/editor/AiAssistant.vue+++ b/apps/desktop/src/components/editor/AiAssistant.vue@@ -192,7 +192,7 @@ import {} from "@/lib/ai/desktopAiRunRegistry";import { createDesktopAiRunSnapshotScheduler } from "@/lib/ai/desktopAiRunSnapshotScheduler";import { isTauriRuntime } from "@/lib/backend/tauriRuntime";-import { addConfiguredAiModel, aiModelOptions } from "@/lib/ai/aiConfigList";+import { addConfiguredAiModel, aiModelOptions, removeConfiguredAiModel } from "@/lib/ai/aiConfigList";import { orderAiConfigsForDisplay } from "@/lib/ai/aiConfigOrdering";import { effortSelectionEquals, runtimeEffortFromPreference } from "@/lib/ai/aiEffortPreference";import { useAiModelCatalog } from "@/composables/useAiModelCatalog";@@ -1733,9 +1733,7 @@ async function applyManualModel(configId: string) {const config = settings.aiConfigs.find((item) => item.id === configId);if (!config) return;try {- if (config.model.trim() !== modelId) {- await settings.updateAiConfigItem(configId, { models: addConfiguredAiModel(config.models, modelId) });- }+ await settings.updateAiConfigItem(configId, { models: addConfiguredAiModel(config.models, modelId) });handleModelSelect(configId, modelId);manualModelConfigId.value = "";manualModelId.value = "";@@ -1744,6 +1742,43 @@ async function applyManualModel(configId: string) {}}+function canRemoveModel(config: AiConfigItem, modelId: string): boolean {+ if (isCliProvider(config.provider) && modelId === "default") return false;+ const isDiscovered = (modelCatalogs.get(config.id)?.models ?? []).some((m) => m.id === modelId);+ if (isDiscovered) return false;+ const preset = getAiProviderPreset(config.provider, config.endpoint);+ if (preset.group === "partner" && (preset.models ?? []).some((m) => m.name.trim() === modelId)) {+ return false;+ }+ return (config.models ?? []).some((m) => m.name.trim() === modelId);+}++async function handleRemoveModel(configId: string, modelId: string) {+ const config = settings.aiConfigs.find((item) => item.id === configId);+ if (!config) return;+ const nextModels = removeConfiguredAiModel(config.models, modelId);+ const updates: Partial<AiConfigItem> = { models: nextModels };+ if (config.model.trim() === modelId) {+ updates.model = isCliProvider(config.provider) ? "default" : (nextModels[0]?.name ?? "");+ }+ try {+ await settings.updateAiConfigItem(configId, updates);+ if (settings.activeModel?.configId === configId && settings.activeModel?.modelId === modelId) {+ const remaining = aiModelOptions({ ...config, ...updates }, modelCatalogs.get(configId)?.models ?? []);+ const nextActiveModelId = remaining[0]?.id;+ if (nextActiveModelId) {+ handleModelSelect(configId, nextActiveModelId);+ } else {+ settings.updateActiveModel(null);+ }+ }+ effortCatalogs.delete(effortKey(configId, modelId));+ closeEffortMenu();+ } catch (error) {+ toast(translateBackendError(t, error));+ }+}+const activeEffortEntry = computed(() => {const active = settings.activeModel;if (!active) return undefined;@@ -7717,20 +7752,31 @@ async function openExternalUrl(url: string) {{{ modelSearchQuery.trim() ? t("ai.noModelMatch") : t("ai.noModels") }}</div><template v-if="getConfigModelOptions(config).length">- <button+ <divv-for="model in getConfigModelOptions(config)":key="model.id"- type="button"- class="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs hover:bg-accent hover:text-accent-foreground"+ class="group/model flex w-full items-center gap-1.5 rounded-sm px-2 py-1 text-left text-xs hover:bg-accent hover:text-accent-foreground":class="model.id === settings.activeModel?.modelId && config.id === settings.activeModel?.configId ? 'bg-accent text-accent-foreground' : ''"- @click="handleModelSelect(config.id, model.id)">- <span class="min-w-0 flex-1 truncate">- {{ model.displayName || model.id }}- <span v-if="model.displayName && model.displayName !== model.id" class="ml-1 text-[10px] text-muted-foreground">{{ model.id }}</span>- </span>- <Check v-if="model.id === settings.activeModel?.modelId && config.id === settings.activeModel?.configId" class="h-3.5 w-3.5 shrink-0 text-primary" />- </button>+ <button type="button" class="flex min-w-0 flex-1 items-center gap-2 py-0.5 text-left" :data-model-id="model.id" @click="handleModelSelect(config.id, model.id)">+ <span class="min-w-0 flex-1 truncate">+ {{ model.displayName || model.id }}+ <span v-if="model.displayName && model.displayName !== model.id" class="ml-1 text-[10px] text-muted-foreground">{{ model.id }}</span>+ </span>+ <Check v-if="model.id === settings.activeModel?.modelId && config.id === settings.activeModel?.configId" class="h-3.5 w-3.5 shrink-0 text-primary" />+ </button>+ <button+ v-if="canRemoveModel(config, model.id)"+ type="button"+ class="rounded p-0.5 text-muted-foreground opacity-0 transition-opacity hover:text-destructive focus-visible:opacity-100 group-hover/model:opacity-100"+ :title="t('common.delete')"+ :aria-label="t('common.delete')"+ :data-remove-model="model.id"+ @click.stop="handleRemoveModel(config.id, model.id)"+ >+ <X class="h-3 w-3 shrink-0" />+ </button>+ </div></template><div v-if="getModelCatalog(config.id).status === 'error' && getModelsForConfig(config.id).length" class="flex items-center justify-between gap-2 px-2 py-1 text-[10px] text-muted-foreground"><span class="truncate" :title="getModelCatalog(config.id).error">{{ t("ai.modelLoadFailed") }}</span>diff --git a/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts b/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.tsindex 50694e5f07..d8486e06c6 100644--- a/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts@@ -182,6 +182,7 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {return result ? Promise.resolve(result) : Promise.reject(new Error("readUserSkills not configured"));},loadAiConfigs: empty,+ saveAiConfigItem: () => Promise.resolve(),listPlugins: empty,loadPromptTemplates: empty,getAiGlobalCustomInstructions: () => Promise.resolve(""),@@ -618,6 +619,51 @@ describe("AiAssistant mount", () => {expect(errors.map(String)).toEqual([]);});+ it("allows deleting manually entered AI models from the model selector popover", async () => {+ let currentSettings: any;+ const { errors, container } = await mountPanel(true, undefined, (settings) => {+ aiAssistantMountApi.tauriRuntime = true;+ currentSettings = settings;+ settings.aiConfigs = [+ {+ id: "cli-default",+ name: "Claude Code",+ provider: "claude-code-cli",+ apiKey: "",+ authMethod: "api-key",+ endpoint: "",+ model: "default",+ models: [{ name: "my-custom-model" }],+ apiStyle: "completions",+ isDefault: true,+ },+ ];+ settings.activeModel = { configId: "cli-default", modelId: "my-custom-model" };+ });++ const trigger = container.querySelector<HTMLButtonElement>(".ai-model-selector-trigger");+ expect(trigger).not.toBeNull();+ trigger!.click();+ await new Promise((resolve) => setTimeout(resolve, 50));++ const popover = container.querySelector('[data-slot="popover-content"]');+ expect(popover).not.toBeNull();++ // Default model should not have delete button+ expect(popover!.querySelector('[data-remove-model="default"]')).toBeNull();++ // Manually added model should have delete button+ const deleteButton = popover!.querySelector<HTMLButtonElement>('[data-remove-model="my-custom-model"]');+ expect(deleteButton).not.toBeNull();++ deleteButton!.click();+ await new Promise((resolve) => setTimeout(resolve, 50));++ // Config should have model removed+ expect(currentSettings.aiConfigs[0].models).toEqual([]);+ expect(errors.map(String)).toEqual([]);+ });+// These states settle through requestAnimationFrame plus async measurement, and the component// measures asynchronously, so they can lag the DOM. Budget by event-loop turns rather than// wall-clock: a CI worker's event loop can stall for seconds behind another worker's modulediff --git a/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts b/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.tsindex 5040979faf..34a2c53c6c 100644--- a/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts+++ b/apps/desktop/src/lib/ai/__tests__/aiConfigList.spec.ts@@ -1,5 +1,5 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { addConfiguredAiModel, aiModelOptions, generateId, prepareImportedAiConfigs } from "@/lib/ai/aiConfigList";+import { addConfiguredAiModel, aiModelOptions, generateId, prepareImportedAiConfigs, removeConfiguredAiModel } from "@/lib/ai/aiConfigList";describe("generateId", () => {afterEach(() => {@@ -53,6 +53,13 @@ describe("AI model options", () => {expect(addConfiguredAiModel([{ name: "ark-code-latest" }], "ark-code-latest")).toEqual([{ name: "ark-code-latest" }]);});+ it("removes a configured manual model", () => {+ expect(removeConfiguredAiModel([{ name: "ark-code-latest" }, { name: "doubao-seed-2.0-code" }], "doubao-seed-2.0-code")).toEqual([{ name: "ark-code-latest" }]);+ expect(removeConfiguredAiModel([{ name: "ark-code-latest" }], "non-existent")).toEqual([{ name: "ark-code-latest" }]);+ expect(removeConfiguredAiModel(undefined, "model")).toEqual([]);+ expect(removeConfiguredAiModel([{ name: "ark-code-latest" }], " ")).toEqual([{ name: "ark-code-latest" }]);+ });+it("merges saved metadata with discovered capabilities", () => {const options = aiModelOptions({diff --git a/apps/desktop/src/lib/ai/aiConfigList.ts b/apps/desktop/src/lib/ai/aiConfigList.tsindex 5b1fcea040..8b40c3ef55 100644--- a/apps/desktop/src/lib/ai/aiConfigList.ts+++ b/apps/desktop/src/lib/ai/aiConfigList.ts@@ -107,6 +107,13 @@ export function addConfiguredAiModel(models: AiConfiguredModel[] | undefined, moreturn [...existing, { name: id }];}+/** Remove a manually entered model from configured models. */+export function removeConfiguredAiModel(models: AiConfiguredModel[] | undefined, modelId: string): AiConfiguredModel[] {+ const id = modelId.trim();+ if (!id || !models?.length) return models ?? [];+ return models.filter((model) => model.name.trim() !== id);+}+export type ConfigNameValidationResult = "empty" | "duplicate" | "valid";export function validateConfigName(name: string, configs: AiConfigItem[], excludeId?: string): ConfigNameValidationResult {diff --git a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts b/apps/desktop/src/stores/__tests__/settingsStore.spec.tsindex 342efbb31f..ca97d931d8 100644--- a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts+++ b/apps/desktop/src/stores/__tests__/settingsStore.spec.ts@@ -2446,6 +2446,20 @@ describe("settingsStore activeModel lifecycle", () => {expect(store.aiConfigs[1].isDefault).toBe(false);});+ it("updateActiveModel(null) clears the active model when the last model is deleted", async () => {+ const { useSettingsStore } = await import("@/stores/settingsStore");+ const store = useSettingsStore();++ store.aiConfigs = [makeTestConfig({ id: "c1", model: "model-a", isDefault: true })];+ store.isAiConfigLoaded = true;++ store.updateActiveModel({ configId: "c1", modelId: "model-a" });+ expect(store.activeModel).toEqual({ configId: "c1", modelId: "model-a" });++ store.updateActiveModel(null);+ expect(store.activeModel).toBeNull();+ });+it("setDefaultAiConfig(id) changes the fallback config without replacing the active model", async () => {const setDefaultAiConfig = vi.fn().mockResolvedValue(undefined);diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.tsindex ac5ff5c375..10c313b154 100644--- a/apps/desktop/src/stores/settingsStore.ts+++ b/apps/desktop/src/stores/settingsStore.ts@@ -2710,11 +2710,8 @@ export const useSettingsStore = defineStore("settings", () => {});}- function updateActiveModel(model: { configId: string; modelId: string }) {- activeModel.value = {- configId: model.configId,- modelId: model.modelId.trim(),- };+ function updateActiveModel(model: { configId: string; modelId: string } | null) {+ activeModel.value = model ? { configId: model.configId, modelId: model.modelId.trim() } : null;persistAiChatSelection();}