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(providers): strip credentials for no-auth requests
vastsaea5ea8d43802
diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.tsindex 61def1497..9492e4be2 100644--- a/packages/agent-runtime/src/provider-binding.test.ts+++ b/packages/agent-runtime/src/provider-binding.test.ts@@ -238,6 +238,7 @@ describe("Anthropic runtime endpoint", () => {expect(result.stopReason).toBe("error");expect(request).toBeDefined();if (!request) throw new Error("Expected the no-auth request to reach fetch");+ expect(request.url).not.toContain("pi-desktop-no-auth");expect(request.headers.get("x-api-key")).toBeNull();expect(request.headers.get("Authorization")).toBeNull();});@@ -282,6 +283,7 @@ describe("Anthropic runtime endpoint", () => {expect(request).toBeDefined();if (!request) throw new Error("Expected the no-auth Google request to reach fetch");+ expect(request.url).not.toContain("pi-desktop-no-auth");expect(request.headers.get("x-goog-api-key")).toBe("");expect(request.headers.get("Authorization")).toBeNull();});diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.tsindex 2abbf9e43..810ff45b3 100644--- a/packages/agent-runtime/src/provider-binding.ts+++ b/packages/agent-runtime/src/provider-binding.ts@@ -112,21 +112,24 @@ export function adapterAcceptsCustomFetch(api: Api | undefined): boolean {}const NO_AUTH_REQUEST_KEY = "pi-desktop-no-auth";+const API_KEY_HEADERS = new Set(["api-key", "x-api-key", "x-goog-api-key"]);function withoutNoAuthCredential(fetchFn: FetchFunction): FetchFunction {return (input, init) => {const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined),);- for (const [name, value] of headers) {+ for (const [name, value] of [...headers]) {+ const normalizedName = name.toLowerCase();const trimmedValue = value.trim();const bearerValue = trimmedValue.slice(0, 7).toLowerCase() === "bearer "? trimmedValue.slice(7).trim(): undefined;- if (- trimmedValue === NO_AUTH_REQUEST_KEY ||- (name === "authorization" && bearerValue === NO_AUTH_REQUEST_KEY)- ) {+ const isPlaceholderApiKey = API_KEY_HEADERS.has(normalizedName)+ && trimmedValue === NO_AUTH_REQUEST_KEY;+ const isPlaceholderAuthorization = normalizedName === "authorization"+ && (trimmedValue === NO_AUTH_REQUEST_KEY || bearerValue === NO_AUTH_REQUEST_KEY);+ if (isPlaceholderApiKey || isPlaceholderAuthorization) {headers.delete(name);}}diff --git a/scripts/e2e/provider-api-style.tsx b/scripts/e2e/provider-api-style.tsxindex bb90c3f9b..5f2e72c23 100644--- a/scripts/e2e/provider-api-style.tsx+++ b/scripts/e2e/provider-api-style.tsx@@ -123,9 +123,9 @@ globalThis.providerApiStyleProbe = async () => {Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, value);input.dispatchEvent(new Event("input", { bubbles: true }));};- const labeledCheckbox = (label: string) =>- [...document.querySelectorAll<HTMLInputElement>('input[type="checkbox"]')]- .find((input) => input.closest("label")?.textContent?.trim() === label);+ const labeledSwitch = (label: string) =>+ [...document.querySelectorAll<HTMLButtonElement>('[role="switch"]')]+ .find((button) => button.getAttribute("aria-label") === label);/* A Field explains itself through the help icon's accessible name, so read therow's explanations from the affordance that carries them. */const rowHints = () => [...document.querySelectorAll<HTMLElement>(@@ -277,8 +277,8 @@ globalThis.providerApiStyleProbe = async () => {`${locale}: new custom form offers the account format ${style}`);}await closeApiStyleMenu();- const noKeyControl = labeledCheckbox(i18n.t("settings.noApiKeyRequired"));- assert(noKeyControl && !noKeyControl.checked,+ const noKeyControl = labeledSwitch(i18n.t("settings.noApiKeyRequired"));+ assert(noKeyControl && noKeyControl.getAttribute("aria-checked") === "false",`${locale}: custom endpoint must default to API-key authentication`);const identityInputs = [...document.querySelectorAll<HTMLInputElement>(".provider-setup-custom-identity-row input",@@ -287,10 +287,12 @@ globalThis.providerApiStyleProbe = async () => {setValue(identityInputs[0]!, "Local Ollama");setValue(identityInputs[1]!, "http://127.0.0.1:11434/v1");click(noKeyControl);- assert(noKeyControl.checked, `${locale}: no-API-key mode did not turn on`);- assert(!document.querySelector('input[type="password"]'),- `${locale}: no-API-key mode left an API key input visible`);- assert(document.documentElement.innerText.includes(i18n.t("settings.noApiKeyRequiredHint")),+ assert(noKeyControl.getAttribute("aria-checked") === "true",+ `${locale}: no-API-key mode did not turn on`);+ const disabledKeyInput = document.querySelector<HTMLInputElement>('input[type="password"]');+ assert(disabledKeyInput?.disabled && disabledKeyInput.value === "",+ `${locale}: no-API-key mode did not clear and disable the API-key input`);+ assert(document.documentElement.innerText.includes(i18n.t("settings.noApiKeyHint")),`${locale}: no-API-key behavior was not explained`);const beforeLocalDiscovery = discoveries.length;await until(() => discoveries.length > beforeLocalDiscovery, "local no-auth discovery");@@ -330,12 +332,13 @@ globalThis.providerApiStyleProbe = async () => {baseUrl: "http://127.0.0.1:9000/v1",};render({ provider: editableKeyProvider });- const editNoKeyControl = labeledCheckbox(i18n.t("settings.noApiKeyRequired"));- assert(editNoKeyControl && !editNoKeyControl.checked,+ const editNoKeyControl = labeledSwitch(i18n.t("settings.noApiKeyRequired"));+ assert(editNoKeyControl && editNoKeyControl.getAttribute("aria-checked") === "false",`${locale}: API-key provider edit opened in the wrong mode`);click(editNoKeyControl);- assert(!document.querySelector('input[type="password"]'),- `${locale}: switched no-auth edit still shows an API-key field`);+ const disabledEditKeyInput = document.querySelector<HTMLInputElement>('input[type="password"]');+ assert(disabledEditKeyInput?.disabled,+ `${locale}: switched no-auth edit did not disable the API-key field`);const beforeNoAuthUpdate = updates.length;click(control("settings.saveProvider"));await until(() => updates.length === beforeNoAuthUpdate + 1, "provider changed to no-auth");