Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(settings): release explicitly deselected image models
yuxino087d0eff4dcb
diff --git a/apps/desktop/src/components/settings/image-generation-default.ts b/apps/desktop/src/components/settings/image-generation-default.tsindex 13f91ffe7..63259aa62 100644--- a/apps/desktop/src/components/settings/image-generation-default.ts+++ b/apps/desktop/src/components/settings/image-generation-default.ts@@ -6,7 +6,7 @@* Saving a provider may extend that list, but adding one must not take over the* default: the chat default's rule applies here too — the stored choice* survives while a configured provider can actually run it, and only an- * unrunnable one is replaced.+ * unrunnable or explicitly deselected one is replaced.** "Can run it" is one rule everywhere: this file, the picker row* (`ImageGenerationModelRow.tsx`) and the runtime@@ -96,7 +96,7 @@ function cappedImageGenerationCandidates(* The saved provider's selection replaces its own earlier candidates, while the* candidates of other providers stay listed — minus the rows whose provider no* longer exists, which nothing can pick or run. The active default moves only- * when the stored choice stops being runnable, and then to the first candidate+ * when explicitly deselected or no longer runnable, and then to the first candidate* that is, so a newly added provider claims the default exactly when nothing* else can hold it. When nothing can, the default stays empty rather than* naming a binding that would fail on the next request.@@ -115,7 +115,11 @@ export function planImageGenerationDefaults(providerId: savedProviderId,modelId,}));- const active = current.imageGeneration ?? null;+ const previous = current.imageGeneration ?? null;+ const active = previous?.providerId === savedProviderId &&+ !selected.some((binding) => modelIdsMatch(binding.modelId, previous.modelId))+ ? null+ : previous;const imageGenerationModels = cappedImageGenerationCandidates([...existing.filter((binding) => binding.providerId !== savedProviderId), ...selected].filter((binding) =>diff --git a/apps/desktop/test/image-generation-default.test.mjs b/apps/desktop/test/image-generation-default.test.mjsindex c607ca004..b33dc9418 100644--- a/apps/desktop/test/image-generation-default.test.mjs+++ b/apps/desktop/test/image-generation-default.test.mjs@@ -292,3 +292,39 @@ test("a long candidate list is capped like the host and keeps the active binding"the active binding must stay in the capped candidate list",);});++for (const candidates of [undefined, [], [binding("x", "chat-model")]]) {+ test(`unchecking the only image model releases it for chat (${JSON.stringify(candidates)})`, async () => {+ const { imageGenerationBindings } = await import("@pi-desktop/shared");+ const { defaultModelOptions } = await import("../src/components/settings/default-model.ts");+ const providers = [provider("x", ["chat-model"])];+ const plan = planImageGenerationDefaults(+ { imageGenerationModels: candidates, imageGeneration: binding("x", "chat-model") },+ "x", [], providers,+ );+ assert.equal(plan.imageGeneration, null);+ assert.deepEqual(plan.imageGenerationModels, []);+ const reloaded = JSON.parse(JSON.stringify(plan));+ assert.deepEqual(defaultModelOptions(providers,+ imageGenerationBindings(reloaded.imageGenerationModels, reloaded.imageGeneration)+ ).map(({ modelId }) => modelId), ["chat-model"]);+ });+}++test("unchecking the active model selects a remaining runnable candidate", () => {+ const plan = planImageGenerationDefaults(+ { imageGenerationModels: [binding("x", "old"), binding("y", "other")],+ imageGeneration: binding("x", "old") },+ "x", ["next"], [provider("x", ["old", "next"]), provider("y", ["other"], { enabled: false })],+ );+ assert.deepEqual(plan.imageGeneration, binding("x", "next"));+ assert.deepEqual(plan.imageGenerationModels, [binding("y", "other"), binding("x", "next")]);+});++test("saving the active provider preserves a still-selected default", () => {+ const plan = planImageGenerationDefaults(+ { imageGeneration: binding("x", "current") },+ "x", ["first", "current"], [provider("x", ["first", "current"])],+ );+ assert.deepEqual(plan.imageGeneration, binding("x", "current"));+});diff --git a/docs/spec/03-runtime/21-image-generation.md b/docs/spec/03-runtime/21-image-generation.mdindex cea75dcb0..174e8997b 100644--- a/docs/spec/03-runtime/21-image-generation.md+++ b/docs/spec/03-runtime/21-image-generation.md@@ -4,7 +4,7 @@ The desktop exposes `AppSettings.imageGeneration` as the current default image-g## Configuration-Model Advanced exposes **Set as image model** alongside the image and document attachment capabilities in the model capability group, not as a separate control row. The checkbox is multi-select: saving a provider persists every checked model in `imageGenerationModels`; Cancel leaves settings unchanged. Saving candidates does not replace the default conversation model. Below the default model row in the same defaults panel, **Image generation model** shows the current default and offers a menu to choose one from all marked candidates. When no candidate is configured, the summary row is hidden. An existing candidate that is missing, disabled, credential-less or removed displays only **Currently unavailable**. OAuth accounts are not eligible; there is no fallback.+Model Advanced exposes **Set as image model** alongside the image and document attachment capabilities in the model capability group, not as a separate control row. The checkbox is multi-select: saving a provider persists every checked model in `imageGenerationModels`; Cancel leaves settings unchanged. Saving candidates does not replace the default conversation model. Unchecking the current image model and saving removes its default binding: the first remaining runnable candidate becomes the default, or the default becomes null if none remains. The unmarked model is available for chat again after saving and reopening settings. Saving another provider preserves a still-runnable image default. Below the default model row in the same defaults panel, **Image generation model** shows the current default and offers a menu to choose one from all marked candidates. When no candidate is configured, the summary row is hidden. An existing candidate that is missing, disabled, credential-less or removed displays only **Currently unavailable**. OAuth accounts are not eligible; there is no fallback.All marked provider/model pairs are excluded from the default conversation picker, provider quick-default action, and Composer model menu. Other providers with the same model ID remain independent. Existing conversation bindings and history are preserved; a conversation still pinned to any image candidate must select a chat model before sending. Runtime launch rejects every marked image model before inference.## Agent contractdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 39a771835..472d771d7 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -28,6 +28,12 @@Mark candidates in the attachment capability group, save, and select onefrom the summary menu. An existing missing/disabled candidate shows onlyCurrently unavailable. Covered in `scripts/e2e-image-generation-ui.mjs`.+- **Image model deselection (#826):** With one provider and one model marked+ for images, uncheck it in the provider editor. Cancel must preserve the image+ default; Save must clear both its candidate and default binding. Reopen settings+ and the editor: the image row stays hidden, the checkbox stays unchecked, and+ the model can be selected as the chat default. Covered in English and Chinese+ by `scripts/e2e-image-generation-ui.mjs` with an API-boundary fixture.- **Conversation selection:** Every marked image provider/model is absent fromdefault and Composer candidates. Other providers retain same-ID models. Anexisting session pinned to any marked image binding is rejected beforediff --git a/docs/zh-CN/spec/03-runtime/21-image-generation.md b/docs/zh-CN/spec/03-runtime/21-image-generation.mdindex eb740a64e..ac47fe1b3 100644--- a/docs/zh-CN/spec/03-runtime/21-image-generation.md+++ b/docs/zh-CN/spec/03-runtime/21-image-generation.md@@ -6,7 +6,7 @@## 配置-模型高级设置将“设为生图模型”与图片、文档附件能力放在同一能力组中,不再单独占一行;复选框支持多选,保存服务商表单后把所有勾选模型写入 `imageGenerationModels`,取消不会改变设置。保存候选不会替换默认对话模型。默认模型下方同一面板中的“生图模型”显示当前默认,并提供菜单从所有已标记候选中选择一个。没有候选时隐藏摘要行;已存在但服务商停用、缺少凭据或模型移除的候选仅显示“暂不可用”。OAuth 账户不适用,也不会自动回退。+模型高级设置将“设为生图模型”与图片、文档附件能力放在同一能力组中,不再单独占一行;复选框支持多选,保存服务商表单后把所有勾选模型写入 `imageGenerationModels`,取消不会改变设置。保存候选不会替换默认对话模型。取消勾选当前生图模型并保存后,默认生图绑定改为剩余的第一个可用候选;没有可用候选时清空。取消标记的模型恢复为可选对话模型,重新打开设置后仍保持这一状态。保存其他服务商时保留仍可用的默认生图模型。默认模型下方同一面板中的“生图模型”显示当前默认,并提供菜单从所有已标记候选中选择一个。没有候选时隐藏摘要行;已存在但服务商停用、缺少凭据或模型移除的候选仅显示“暂不可用”。OAuth 账户不适用,也不会自动回退。所有已标记的服务商/模型组合都会从默认对话模型选择器、服务商快速设为默认操作和 Composer 模型菜单中排除。其他服务商的同名模型独立保留。已有会话绑定和历史不改写;仍绑定任一生图候选的会话必须选择对话模型才能发送,运行时也会在推理前拒绝所有已标记生图模型。## Agent 合约diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 3015ed50a..a263ed716 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -9,6 +9,13 @@---+### E2E-IMAGES-deselect-default++- **前提:** 只有一个服务商、一个模型,且该模型已标记为生图模型。+- **步骤:** 在服务商编辑器取消生图勾选,先取消编辑,再重新操作并保存;重新打开设置和编辑器,选择该模型作为默认对话模型。+- **预期:** 取消编辑保留原绑定;保存清除候选和默认生图绑定。重新打开后摘要行隐藏、复选框未勾选,模型恢复为可选对话模型。+- **覆盖:** `scripts/e2e-image-generation-ui.mjs` 使用 API 边界 fixture 验证英文与中文交互;不代表真实服务商测试。+## 1. 目标- 记录 MVP 必须验证的每个用户可见和协议可见的行为。diff --git a/scripts/e2e/image-generation-ui.tsx b/scripts/e2e/image-generation-ui.tsxindex 4815e5545..6da30e75a 100644--- a/scripts/e2e/image-generation-ui.tsx+++ b/scripts/e2e/image-generation-ui.tsx@@ -241,6 +241,46 @@ globalThis.imageGenerationProbe = async () => {);assert(!unsetImageRow, "unset image model row should be hidden");+ // Issue #826: release the only chat model through the real edit/save path.+ providers.splice(0, providers.length, chatProvider);+ settings = {+ ...settings,+ imageGeneration: { providerId: "chat", modelId: "chat-model" },+ imageGenerationModels: [{ providerId: "chat", modelId: "chat-model" }],+ };+ flushSync(() => useAppStore.setState({ settings, providers: [...providers] }));+ const editOnlyProvider = () => click(container.querySelector<HTMLButtonElement>(+ 'button[aria-label="' + i18n.t("settings.editProvider") + '"]',+ ));+ editOnlyProvider();+ await until(() => !!imageModelToggle(i18n.t("settings.imageModelSelected")), "selected image checkbox missing");+ click(imageModelToggle(i18n.t("settings.imageModelSelected")));+ click(button(i18n.t("settings.cancel")));+ assert(settings.imageGeneration?.modelId === "chat-model", "cancel cleared the image default");+ editOnlyProvider();+ await until(() => !!imageModelToggle(i18n.t("settings.imageModelSelected")), "selected checkbox did not reopen");+ click(imageModelToggle(i18n.t("settings.imageModelSelected")));+ click(button(i18n.t("settings.saveProvider")));+ await until(() => !document.querySelector(".provider-setup-dialog"), "unmark save did not finish");+ assert(settings.imageGeneration === null, "unmark kept the old image default");+ assert(settings.imageGenerationModels?.length === 0, "unmark kept image candidates");+ // Remount settings from the saved API value, then reopen the provider.+ flushSync(() => root.render(null));+ flushSync(() => useAppStore.setState({ settings: structuredClone(settings) }));+ render();+ assert(!container.querySelector(".model-image-row"), "image summary returned after reopen");+ editOnlyProvider();+ await until(() => !!imageModelToggle(i18n.t("settings.setImageModel")), "unmarked checkbox did not persist");+ assert(!imageModelToggle(i18n.t("settings.setImageModel"))?.checked, "reopened model is still marked");+ click(button(i18n.t("settings.cancel")));+ click(container.querySelector<HTMLButtonElement>(".model-default-trigger"));+ await until(() => !!document.querySelector('[aria-label="Chat · chat-model"]'), "released chat model is missing");+ click(document.querySelector<HTMLButtonElement>('[aria-label="Chat · chat-model"]'));+ await until(() => !document.querySelector(".model-default-list"), "chat selection did not finish");+ assert(settings.defaultProviderId === "chat" && settings.defaultModelId === "chat-model", "released model cannot be the chat default");+ providers.splice(0, providers.length, provider, alternate, chatProvider);+ flushSync(() => useAppStore.setState({ providers: [...providers] }));+}const message = {id: "image",@@ -290,6 +330,7 @@ globalThis.imageGenerationProbe = async () => {locales: ["en", "zh-CN"],scenarios: ["advanced-save-cancel",+ "unmark-only-image-model-save-reopen-chat-selection","advanced-provider-switch","read-only-summary-typography","unconfigured-summary-hidden",