Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(settings): keep add-service forms out of plugin setup

vastsa317434b954d9
diff --git a/apps/desktop/src/components/settings/ModelConfigPage.tsx b/apps/desktop/src/components/settings/ModelConfigPage.tsx
index 61abf0c76..351aefe1d 100644
--- a/apps/desktop/src/components/settings/ModelConfigPage.tsx
+++ b/apps/desktop/src/components/settings/ModelConfigPage.tsx
@@ -41,6 +41,7 @@ import { ModelConfigImportPanel } from "../../features/settings/imports/ModelCon
import { ImportToggleButton } from "../../features/settings/import-workbench";
import { JevSettingsCard } from "./JevSettingsCard";
import { JEV_SERVICE } from "./service-catalog";
+import { isPluginCatalogSetupForProvider } from "./provider-setup-mode";
type CatalogStatus = {
loaded: boolean;
@@ -551,7 +552,10 @@ export function ModelConfigPage() {
<ProviderSetupDialog
key={setupFor}
provider={editingProvider}
- pluginCatalogSetup={pluginCatalogSetup?.providerId === editingProvider?.id}
+ pluginCatalogSetup={isPluginCatalogSetupForProvider(
+ pluginCatalogSetup,
+ editingProvider,
+ )}
pluginCatalogPluginName={pluginCatalogSetup?.pluginName}
initialDraft={copyDraft}
initialService={jevSetup ? JEV_SERVICE : undefined}
diff --git a/apps/desktop/src/components/settings/provider-setup-mode.ts b/apps/desktop/src/components/settings/provider-setup-mode.ts
new file mode 100644
index 000000000..238630573
--- /dev/null
+++ b/apps/desktop/src/components/settings/provider-setup-mode.ts
@@ -0,0 +1,9 @@
+/** Whether the provider setup dialog is targeting a selected plugin-owned row. */
+export function isPluginCatalogSetupForProvider(
+ selection: { providerId: string } | null,
+ provider: { id: string } | null,
+): boolean {
+ return selection !== null &&
+ provider !== null &&
+ selection.providerId === provider.id;
+}
diff --git a/apps/desktop/test/plugin-provider-catalog-user-path.test.mjs b/apps/desktop/test/plugin-provider-catalog-user-path.test.mjs
index b5c3957ec..5277d61ab 100644
--- a/apps/desktop/test/plugin-provider-catalog-user-path.test.mjs
+++ b/apps/desktop/test/plugin-provider-catalog-user-path.test.mjs
@@ -18,6 +18,7 @@ import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import { catalogs, flattenCatalog } from "@pi-desktop/i18n";
import { ProviderSetupDialog } from "../../apps/desktop/src/components/settings/ProviderSetupDialog";
+import { isPluginCatalogSetupForProvider } from "../../apps/desktop/src/components/settings/provider-setup-mode";
import { useAppStore } from "../../apps/desktop/src/stores/app-store";
const calls = [];
@@ -136,7 +137,7 @@ function PluginCatalogSurface() {
return React.createElement(ProviderSetupDialog, {
key: selected?.providerId ?? "add",
provider,
- pluginCatalogSetup: !!selected,
+ pluginCatalogSetup: isPluginCatalogSetupForProvider(selected, provider),
pluginCatalogPluginName: selected?.pluginName,
onClose: () => mount(null),
onSaved: () => { saved = true; mount(null); },
@@ -144,7 +145,31 @@ function PluginCatalogSurface() {
});
}
+function BuiltInServiceSurface() {
+ return React.createElement(ProviderSetupDialog, {
+ provider: null,
+ pluginCatalogSetup: isPluginCatalogSetupForProvider(null, null),
+ onClose: () => mount(null),
+ onSaved: () => {},
+ });
+}
+
window.pluginProviderCatalogProbe = async () => {
+ // The empty add state has no selected provider. Choosing a built-in service
+ // must reach the ordinary key form instead of the plugin-only empty state.
+ mount(React.createElement(BuiltInServiceSurface));
+ const builtInTile = await waitFor(
+ () => document.querySelector('[data-service-id="openai"]'),
+ "the built-in service tile was not shown",
+ );
+ flushSync(() => builtInTile.click());
+ const builtInKeyField = await waitFor(
+ () => document.querySelector('input[type="password"]'),
+ "selecting a built-in provider did not open its API key form",
+ );
+ const builtInServiceOpensKeyForm = !!builtInKeyField &&
+ !document.documentElement.innerText.includes("The selected provider is no longer available.");
+
mount(React.createElement(PluginCatalogSurface));
const category = await waitFor(
() => document.querySelector('[data-plugin-provider-category="公益 AI 站"]'),
@@ -184,6 +209,7 @@ window.pluginProviderCatalogProbe = async () => {
"saving one key hid another unconfigured provider",
);
return {
+ builtInServiceOpensKeyForm,
categoryShown: !!category,
publisherShown,
tileEndpointShown,
@@ -281,6 +307,7 @@ app.whenReady().then(async () => {
const line = output.split(/\r?\n/).find((item) => item.startsWith("PLUGIN_PROVIDER_CATALOG_PROBE "));
assert(line, output.slice(-6000));
assert.deepEqual(JSON.parse(line.slice("PLUGIN_PROVIDER_CATALOG_PROBE ".length)), {
+ builtInServiceOpensKeyForm: true,
categoryShown: true,
publisherShown: false,
tileEndpointShown: false,
diff --git a/apps/desktop/test/provider-model-config.test.mjs b/apps/desktop/test/provider-model-config.test.mjs
index 565f43172..5b7c33ae2 100644
--- a/apps/desktop/test/provider-model-config.test.mjs
+++ b/apps/desktop/test/provider-model-config.test.mjs
@@ -16,6 +16,9 @@ import { loadStyles } from "./helpers/styles.mjs";
register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
const { normalizeApiStyle } = await import("@pi-desktop/shared");
const { normalizeBaseUrlInput } = await import("../src/components/settings/provider-endpoint-guidance.ts");
+const { isPluginCatalogSetupForProvider } = await import(
+ "../src/components/settings/provider-setup-mode.ts"
+);
const read = (rel) => readFile(new URL(rel, import.meta.url), "utf8");
@@ -68,6 +71,29 @@ test("adding an AI service is a single form, not a staged wizard", () => {
assert.match(setupSource, /settings\.saveProvider/);
});
+test("the add flow only enters plugin setup for a resolved selected provider", () => {
+ assert.equal(isPluginCatalogSetupForProvider(null, null), false);
+ assert.equal(isPluginCatalogSetupForProvider({ providerId: "plugin:demo:first" }, null), false);
+ assert.equal(
+ isPluginCatalogSetupForProvider(
+ { providerId: "plugin:demo:first" },
+ { id: "plugin:demo:first" },
+ ),
+ true,
+ );
+ assert.equal(
+ isPluginCatalogSetupForProvider(
+ { providerId: "plugin:demo:first" },
+ { id: "plugin:demo:second" },
+ ),
+ false,
+ );
+ assert.match(
+ pageSource,
+ /pluginCatalogSetup=\{isPluginCatalogSetupForProvider\([\s\S]*?pluginCatalogSetup,[\s\S]*?editingProvider,[\s\S]*?\)\}/,
+ );
+});
+
test("discovery is debounced, race-guarded and survives a bad URL", () => {
assert.match(hookSource, /FETCH_DEBOUNCE_MS/);
assert.match(hookSource, /requestSeq/);
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 5c0e707f1..fe0f3fcaf 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1018,12 +1018,12 @@ identify the platform validation still needed.
#### E2E-005: Add a provider and save API key
- **Preconditions**: App running; no provider configured; the models.dev snapshot ships with the build.
-- **Steps**: 1) Open Settings → Model configuration and choose Add provider. 2) Confirm the dialog is ONE form with no stepper or Next/Back buttons. The first control is Service — a searchable menu (Choose a service, Custom endpoint, then a flat vendor list from models.dev including Xiaomi), not a native select, region grouping, or vendor-card grid. Open it, type to filter client-side, then choose **Custom endpoint**. Confirm Name and Base URL appear on one row with no helper paragraph under the URL (placeholder only), API Key and API format appear side by side on the next row (not behind Advanced), and that a focused field plus its 2px accent ring stays fully inside the dialog, including on a window narrower than 1040px. 3) Enter a name and a base URL for a service that publishes a `/models` route, then paste an API key. 4) Confirm the models section fills with the models THAT SERVICE returned, not with every model its vendor publishes; confirm a model the deployment does not host is absent. 5) Type in the filter box and confirm the list narrows client-side with no network request per keystroke. 6) Confirm each row shows the models.dev-derived context/output for models the catalog knows, that its compact text tracks the published value instead of a coarser rounded one (a 1,050,000 window reads `1.05M`, never `1.1M`), and that a model with no catalog match still lists with generic defaults. 7) Select two models with the checkboxes. 8) Expand Advanced on one chosen row, override its limits and toggle thinking chips; confirm each numeric field has a five-chip preset ladder for common values, clicking a chip writes the value, hand editing remains possible, and a non-preset value leaves the ladder unselected. Set max output to 8,192 while its context window still follows the catalog. On a model whose published image input is enabled, toggle image input off and then back on before saving, so the explicit choice equals the current catalog value. Confirm the label and optional hint sit above one compact grouped control and do not force the options onto a second row at normal dialog width; confirm all seven canonical levels are available, that published levels start selected for a known reasoning model, and that a non-reasoning or unknown row shows the same chips unselected with the manual-override hint; enable one level on that row and confirm the other row is unaffected. 9) Open the form-level Advanced and confirm the API format is present but pre-derived. 10) Add a free-form model ID the service did not return; confirm it is added with 128,000 / 8,192 / no-thinking defaults, then enable a thinking level if the endpoint supports it; confirm re-adding the same ID in different letter case is rejected as already added. 11) Save.
+- **Steps**: 1) Open Settings → Model configuration and choose Add provider. 2) Confirm the searchable service chooser opens. Filter and select a built-in API-key service or **Custom endpoint**; the selection must open its matching form, never the plugin-only “selected service unavailable” state. Confirm the form has no stepper or Next/Back buttons. For **Custom endpoint**, Name and Base URL appear on one row with no helper paragraph under the URL (placeholder only), API Key and API format appear side by side on the next row (not behind Advanced), and a focused field plus its 2px accent ring stays fully inside the dialog, including on a window narrower than 1040px. 3) Enter a name and a base URL for a service that publishes a `/models` route, then paste an API key. 4) Confirm the models section fills with the models THAT SERVICE returned, not with every model its vendor publishes; confirm a model the deployment does not host is absent. 5) Type in the filter box and confirm the list narrows client-side with no network request per keystroke. 6) Confirm each row shows the models.dev-derived context/output for models the catalog knows, that its compact text tracks the published value instead of a coarser rounded one (a 1,050,000 window reads `1.05M`, never `1.1M`), and that a model with no catalog match still lists with generic defaults. 7) Select two models with the checkboxes. 8) Expand Advanced on one chosen row, override its limits and toggle thinking chips; confirm each numeric field has a five-chip preset ladder for common values, clicking a chip writes the value, hand editing remains possible, and a non-preset value leaves the ladder unselected. Set max output to 8,192 while its context window still follows the catalog. On a model whose published image input is enabled, toggle image input off and then back on before saving, so the explicit choice equals the current catalog value. Confirm the label and optional hint sit above one compact grouped control and do not force the options onto a second row at normal dialog width; confirm all seven canonical levels are available, that published levels start selected for a known reasoning model, and that a non-reasoning or unknown row shows the same chips unselected with the manual-override hint; enable one level on that row and confirm the other row is unaffected. 9) Open the form-level Advanced and confirm the API format is present but pre-derived. 10) Add a free-form model ID the service did not return; confirm it is added with 128,000 / 8,192 / no-thinking defaults, then enable a thinking level if the endpoint supports it; confirm re-adding the same ID in different letter case is rejected as already added. 11) Save.
- **Expected**: The service is asked first and models.dev only enriches the answer and seeds known-model defaults. Newly fetched or checked model rows stay collapsed until the user opens Advanced, so every selected model ID remains visible in the right pane after a multi-select. The settings picker always offers the seven canonical thinking levels, and the Composer later renders the explicit levels saved in the same model binding; an empty or `off`-only binding resolves to `off`. Discovery is debounced ~600 ms, does not mark loading until that window elapses, and a slow reply from an earlier keystroke never replaces a newer list; named add-path discovery waits for an API key, while an unsaved custom provider is probed with the typed base URL (and key, if any) before it exists. Preset ladders cover common context/output limits while preserving hand-edited values. The explicitly selected 8,192 output remains pinned independently of the catalog-sourced context window, and the image-input choice remains explicitly enabled after it is toggled back to the published value; neither is reinterpreted as "follow catalog" on save/reopen. Later catalog corrections change only values whose own source is `catalog`. Limit text renders through one shared compact formatter, so neighbouring published windows stay distinguishable (`1M` / `1.05M` / `1.1M`) and a compact limit never reads above its published value. Custom endpoint keeps API format beside the key and omits Base URL helper copy; named endpoints do not show format. Point the same custom form at an unreachable or unauthorized URL and confirm one classified sentence reaches the app toast while the left pane keeps its single “no list” label (not a raw JSON/HTML dump and not a second “no models” empty state); with cached rows from a later edit the same reason is toasted while the rows stay. Point a second provider at a base URL with no `/models` route and confirm the list falls back to the catalog, is labelled as coming from models.dev rather than the service, and still saves. The provider appears as a row with its host, model count and secret badge; the key is stored securely (not in plaintext config); `models` contains both bindings and `models[0]` remains the provider default.
- **Specs linked**: `03-runtime/11-provider-model-system.md`, `03-runtime/12-provider-config-schema.md`, `03-runtime/13-model-catalog-and-selection.md`, `03-runtime/14-secrets-storage.md`, `04-ux/06-settings-ia.md`
- **Acceptance**: B (multi-model provider configuration, save key)
- **Milestone**: M2
-- **Status**: Manual UI + automated protocol smoke (provider create + secret, no plaintext echo)
+- **Status**: Manual model-picker acceptance; chooser-to-key-form selection is covered by `apps/desktop/test/plugin-provider-catalog-user-path.test.mjs`; automated protocol smoke covers provider creation and secret handling without plaintext echo.
#### E2E-PROVIDER-defaults-survive-an-added-provider: An added provider leaves the app defaults alone