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(models): place saved-key clear icon beside the input
vastsa45412281f702
diff --git a/apps/desktop/src/components/settings/ProviderConnectionFields.tsx b/apps/desktop/src/components/settings/ProviderConnectionFields.tsxindex cdb2e67ce..ec4f23b98 100644--- a/apps/desktop/src/components/settings/ProviderConnectionFields.tsx+++ b/apps/desktop/src/components/settings/ProviderConnectionFields.tsx@@ -10,7 +10,8 @@import type { RefObject } from "react";import { useTranslation } from "react-i18next";import type { CatalogApiStyle } from "@pi-desktop/shared";-import { Button, Field, Input } from "../ui";+import { Field, Input, TooltipButton } from "../ui";+import { IconTrash } from "../icons";import { SettingsMenuSelect } from "./SettingsMenuSelect";import { ServiceMonogram } from "./ServiceMonogram";import { endpointLabel } from "./service-catalog";@@ -173,29 +174,31 @@ export function ProviderConnectionFields({<div className="provider-setup-field-row provider-setup-custom-auth-row"><div className="provider-setup-key"><Field label={t("settings.apiKey")} hint={keyHint}>- <Input- ref={apiKeyRef}- type="password"- value={apiKey}- placeholder="sk-…"- className="font-mono text-sm-plus"- autoComplete="off"- disabled={saving}- onChange={(event) => onApiKeyChange(event.target.value)}- />+ <div className="provider-setup-key-control">+ <Input+ ref={apiKeyRef}+ type="password"+ value={apiKey}+ placeholder="sk-…"+ className="font-mono text-sm-plus"+ autoComplete="off"+ disabled={saving}+ onChange={(event) => onApiKeyChange(event.target.value)}+ />+ {hasSavedApiKey && onClearApiKey ? (+ <TooltipButton+ type="button"+ className="icon-btn icon-btn-square"+ tooltip={t("settings.clearApiKey")}+ ariaLabel={t("settings.clearApiKey")}+ disabled={saving}+ onClick={onClearApiKey}+ >+ <IconTrash size={14} aria-hidden />+ </TooltipButton>+ ) : null}+ </div></Field>- {hasSavedApiKey && onClearApiKey ? (- <Button- type="button"- variant="ghost"- size="sm"- className="self-start"- disabled={saving}- onClick={onClearApiKey}- >- {t("settings.clearApiKey")}- </Button>- ) : null}</div><Fieldlabel={t("settings.apiStyle")}diff --git a/apps/desktop/src/styles/model-config.css b/apps/desktop/src/styles/model-config.cssindex 2122098b8..d98a2962c 100644--- a/apps/desktop/src/styles/model-config.css+++ b/apps/desktop/src/styles/model-config.css@@ -271,6 +271,22 @@min-width: 0;}+.provider-setup-key-control {+ display: flex;+ align-items: center;+ gap: 6px;+ min-width: 0;+}++.provider-setup-key-control > input {+ flex: 1;+ min-width: 0;+}++.provider-setup-key-control > button {+ flex-shrink: 0;+}+.provider-service-anchor {width: 100%;min-width: 0;diff --git a/apps/desktop/test/custom-provider-no-api-key-user-path.test.mjs b/apps/desktop/test/custom-provider-no-api-key-user-path.test.mjsindex 873914d60..85b86d6ec 100644--- a/apps/desktop/test/custom-provider-no-api-key-user-path.test.mjs+++ b/apps/desktop/test/custom-provider-no-api-key-user-path.test.mjs@@ -2,7 +2,7 @@import assert from "node:assert/strict";import { spawn } from "node:child_process";import { createRequire } from "node:module";-import { mkdtemp, rm, writeFile } from "node:fs/promises";+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";import { join } from "node:path";import test from "node:test";import { repositoryRoot, resolveElectronBinary } from "../../../scripts/e2e/boot.mjs";@@ -103,7 +103,7 @@ function mount(element) { flushSync(() => rootNode.render(element)); }window.customProviderNoApiKeyProbe = async () => {const check = (condition, message) => { if (!condition) throw new Error(message); };const button = (label) => [...document.querySelectorAll("button")]- .find((item) => item.textContent.trim() === label);+ .find((item) => item.getAttribute("aria-label") === label || item.textContent.trim() === label);const keyField = () => document.querySelector('input[type="password"]');const edit = (provider, key) => {updateInput = null;@@ -181,8 +181,17 @@ window.customProviderNoApiKeyProbe = async () => {"an untouched empty input overwrote the saved key");edit(keyedProvider, "edit-keyed-clear-and-cancel");- check(button("Clear saved API key"), "the saved-key removal action was missing");- flushSync(() => button("Clear saved API key").click());+ const clearButton = button("Clear saved API key");+ check(clearButton, "the saved-key removal action was missing");+ check(clearButton.textContent.trim() === "" && clearButton.querySelector('svg[aria-hidden="true"]'),+ "the saved-key removal action is not an accessible icon-only button");+ const inputRect = keyField().getBoundingClientRect();+ const clearRect = clearButton.getBoundingClientRect();+ check(clearRect.left >= inputRect.right && clearRect.top < inputRect.bottom+ && clearRect.bottom > inputRect.top, "the clear icon is not beside the API-key input");+ check(clearRect.width >= 24 && clearRect.height >= 24, "the clear icon target is too small");+ flushSync(() => clearButton.click());+ check(document.activeElement === keyField(), "clearing the key did not focus its input");check(!updateInput, "clearing a key persisted before Save");check(keyField().value === "" && !keyField().disabled, "clearing a saved key disabled the input");const afterClear = calls.length;@@ -283,9 +292,15 @@ test("a custom endpoint can be saved and selected without an API key", {},nodePaths: [join(root, "apps/desktop/node_modules")],});+ const styles = await Promise.all(+ ["tokens", "base", "ui-kit", "settings", "composer", "providers", "model-config"].map(+ (name) => readFile(join(root, "apps/desktop/src/styles/" + name + ".css"), "utf8"),+ ),+ );+ await writeFile(join(temp, "style.css"), styles.join("\n").replace(/@theme(?: inline)?/g, ":root"));await writeFile(join(temp, "index.html"),- '<!doctype html><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src \'self\'; style-src \'self\' \'unsafe-inline\'"><body><div id="root"></div><script type="module" src="renderer.js"></script>',+ '<!doctype html><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src \'self\'; style-src \'self\' \'unsafe-inline\'"><link rel="stylesheet" href="style.css"><body><div id="root"></div><script type="module" src="renderer.js"></script>',);await writeFile(join(temp, "main.cjs"),diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex 3aebd75ef..bf61c3f75 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -28,8 +28,10 @@ entitled to it.endpoint keys are optional, with no authentication-mode switch. An empty orwhitespace-only key on a row without a stored key saves `authKind: "none"`without `secretValue`; a supplied key uses API-key authentication. Editing- with an empty key preserves the stored key. **Clear saved API key** stages- removal, keeps the input enabled, and stops discovery from reusing that key;+ with an empty key preserves the stored key. **Clear saved API key** is an+ icon button beside the input on the same row, with a localized tooltip and+ accessible name. It stages removal, keeps the input enabled, and stops+ discovery from reusing that key;Save applies the removal and no-auth mode unless a replacement key is typed.Closing without saving changes no stored credential. Named cloud serviceskeep their existing authentication defaults.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 93ad86b71..98ca771c9 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -1265,7 +1265,7 @@ identify the platform validation still needed.#### E2E-PROVIDER-custom-endpoint-no-api-key: Configure a custom service without credentials- **Preconditions**: Isolated settings profile and a local OpenAI-compatible fixture that lists a model without credentials; no live or paid provider.-- **Steps**: 1) Open Settings → Model configuration → Add provider → Custom endpoint. 2) Enter a name and the fixture URL; leave the optional API key empty, without selecting an authentication mode. 3) Confirm model discovery succeeds without a key, select the returned model, and save. 4) Reopen and save without changes, then type a key and save; confirm API-key authentication is restored. 5) Edit an API-key provider and save with a blank input; confirm its key is retained. Reopen, choose **Clear saved API key**, and confirm subsequent discovery does not reuse the stored key. Close without saving and confirm no credential changed. Repeat Clear followed by Save, and Clear followed by a replacement key and Save. 6) Confirm the no-auth provider and model are offered by chat/default-model and subagent selectors. 7) Send a request through the no-auth provider fixture.+- **Steps**: 1) Open Settings → Model configuration → Add provider → Custom endpoint. 2) Enter a name and the fixture URL; leave the optional API key empty, without selecting an authentication mode. 3) Confirm model discovery succeeds without a key, select the returned model, and save. 4) Reopen and save without changes, then type a key and save; confirm API-key authentication is restored. 5) Edit an API-key provider and save with a blank input; confirm its key is retained. Reopen and confirm **Clear saved API key** is an icon-only button to the right of the input on the same row, with a localized accessible name and tooltip. Activate it, confirm focus returns to the input, and confirm subsequent discovery does not reuse the stored key. Close without saving and confirm no credential changed. Repeat Clear followed by Save, and Clear followed by a replacement key and Save. 6) Confirm the no-auth provider and model are offered by chat/default-model and subagent selectors. 7) Send a request through the no-auth provider fixture.- **Expected**: The custom form has no no-key switch and keeps the key input enabled. An empty or whitespace-only key with no saved credential automatically saves `authKind: "none"` without `secretValue`; a supplied key uses API-key authentication. A blank edit retains an existing key. Clear is staged until Save and a replacement key takes precedence over removal. The enabled no-auth provider with `hasSecret: false` remains selectable for chat, defaults, subagents, and image generation where its model supports that operation. Named cloud presets remain unchanged. Runtime requests contain no API-key or Authorization credentials.- **Automation**: `node --test apps/desktop/test/custom-provider-no-api-key-user-path.test.mjs` covers empty/whitespace keys, keyed creation, save/reopen, preservation, staged removal/cancellation, discovery without the old secret, and replacement. `pnpm test:e2e:provider-api-style` renders the production setup form in English and Simplified Chinese with a stubbed model-discovery/API boundary and verifies create/update payloads and chat/default/subagent selector eligibility. `pnpm --filter @pi-desktop/agent-runtime exec vitest run src/provider-binding.test.ts` verifies request headers; `apps/desktop/test/image-generation-default.test.mjs` covers no-auth image-model availability; `cargo test -p host-core --locked switching_provider_to_no_auth_clears_its_api_key` verifies Host persistence and secret removal.- **Specs linked**: `03-runtime/11-provider-model-system.md`, `03-runtime/12-provider-config-schema.md`, `03-runtime/13-model-catalog-and-selection.md`, `04-ux/06-settings-ia.md`.diff --git a/scripts/e2e/provider-api-style.tsx b/scripts/e2e/provider-api-style.tsxindex 90ca2cac0..01877c807 100644--- a/scripts/e2e/provider-api-style.tsx+++ b/scripts/e2e/provider-api-style.tsx@@ -114,7 +114,8 @@ globalThis.providerApiStyleProbe = async (reasoningOnly = false) => {flushSync(() => element!.click());};const button = (key: string) => [...document.querySelectorAll<HTMLButtonElement>("button")]- .find((element) => element.textContent?.trim() === i18n.t(key));+ .find((element) => element.getAttribute("aria-label") === i18n.t(key)+ || element.textContent?.trim() === i18n.t(key));const control = (key: string) => {const element = button(key);assert(element, `missing control ${key}`);