Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(providers): Local Mode switch that lists only own-hardware providers

rubenluetke10-beep2ca5567fffa3
diff --git a/jarvis/ui/web/frontend/src/components/onboarding/steps/ApiKeysStep.tsx b/jarvis/ui/web/frontend/src/components/onboarding/steps/ApiKeysStep.tsx
index 99a4703b3e..b3b124ae4b 100644
--- a/jarvis/ui/web/frontend/src/components/onboarding/steps/ApiKeysStep.tsx
+++ b/jarvis/ui/web/frontend/src/components/onboarding/steps/ApiKeysStep.tsx
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { CheckCircle2, HardDrive, KeyRound, Radio, Waypoints } from "lucide-react";
import { Button } from "@/components/ui/button";
import { switchBrainProvider } from "@/hooks/useProviders";
+import { setLocalMode } from "@/lib/localMode";
import { putVoiceMode } from "@/lib/voiceEngineMode";
import { useT } from "@/i18n";
import type { StepProps } from "../OnboardingFlow";
@@ -56,6 +57,12 @@ function LocalPathCard() {
// realtime cards with their choice having changed nothing audible.
// Persisted, because onboarding ends in a restart.
await putVoiceMode("pipeline");
+ // Somebody who picks the local path here lands in a provider console
+ // whose cards are almost entirely hosted accounts they just declined.
+ // Local Mode opens it on the handful that need no key. A view preference,
+ // reversible with one click on the switch in that view's header — never a
+ // state the user has to hunt for a way out of.
+ setLocalMode(true);
setActive(true);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
diff --git a/jarvis/ui/web/frontend/src/components/providers/ProviderTierSection.tsx b/jarvis/ui/web/frontend/src/components/providers/ProviderTierSection.tsx
index 28feb91d8b..855a8cece9 100644
--- a/jarvis/ui/web/frontend/src/components/providers/ProviderTierSection.tsx
+++ b/jarvis/ui/web/frontend/src/components/providers/ProviderTierSection.tsx
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState } from "react";
-import { AlertCircle, Bot, Brain, Check, Copy, Download, Loader2, LogIn, LogOut, Mic, PlugZap, Radio, Sparkles, Terminal, Volume2, Wand2, Waypoints, XCircle } from "lucide-react";
+import { AlertCircle, Bot, Brain, Check, Copy, Download, HardDrive, Loader2, LogIn, LogOut, Mic, PlugZap, Radio, Sparkles, Terminal, Volume2, Wand2, Waypoints, XCircle } from "lucide-react";
import { AltCredentialNote } from "@/components/AltCredentialNote";
import { ApiKeyForm } from "@/components/ApiKeyForm";
import { BrainModelSelector } from "@/components/BrainModelSelector";
@@ -48,6 +48,7 @@ import {
import { useEventStore } from "@/store/events";
import { agentBrand, agentsBrand } from "@/lib/agentBrand";
import { robustCopy } from "@/lib/clipboard";
+import { filterForLocalMode } from "@/lib/localMode";
import {
realtimeTransportIssueKey,
requestRealtimeTransportOffer,
@@ -345,6 +346,108 @@ export function EngineModeSwitch({
);
}
+/**
+ * The Local Mode toggle that sits next to the engine switch in the header.
+ *
+ * One button, two legible states, and an explicit on/off word rather than a
+ * lit-versus-unlit icon: the whole complaint this answers is that the previous
+ * local path felt like something that happened TO the user and could not be
+ * clearly turned back off. A control you can read the state of, and click once
+ * to reverse, is the fix.
+ *
+ * Presentation only — see `lib/localMode.ts`. It never switches a provider and
+ * never writes config, so leaving it on can't break an install.
+ */
+export function LocalModeSwitch({
+ enabled,
+ onToggle,
+}: {
+ enabled: boolean;
+ onToggle: (next: boolean) => void;
+}) {
+ const t = useT();
+ return (
+ <div className="shrink-0">
+ <button
+ type="button"
+ data-testid="local-mode-switch"
+ aria-pressed={enabled}
+ onClick={() => onToggle(!enabled)}
+ title={t(
+ enabled ? "apikeys_view.local_mode_title_on" : "apikeys_view.local_mode_title_off",
+ )}
+ className={cn(
+ "inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-[0.4375rem] text-xs font-medium transition-colors",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ enabled
+ ? "border-primary/40 bg-primary/15 text-primary"
+ : "border-border bg-card/40 text-muted-foreground hover:text-foreground",
+ )}
+ >
+ <HardDrive aria-hidden="true" className="h-3.5 w-3.5" />
+ <span className="whitespace-nowrap">{t("apikeys_view.local_mode_label")}</span>
+ <span
+ className={cn(
+ "whitespace-nowrap rounded-full px-1 py-px text-[8px] font-semibold uppercase tracking-wide",
+ enabled
+ ? "bg-primary/25 text-primary"
+ : "border border-border bg-background/60 text-muted-foreground/80",
+ )}
+ >
+ {t(enabled ? "apikeys_view.local_mode_on" : "apikeys_view.local_mode_off")}
+ </span>
+ </button>
+ {/* Mirrors the engine switch's one-line hint so the two controls sit on
+ the same baseline and the header stays a single tidy row. */}
+ <p
+ data-testid="local-mode-hint"
+ className="mt-1 text-right text-[10px] leading-tight text-muted-foreground/70"
+ >
+ {t("apikeys_view.local_mode_hint")}
+ </p>
+ </div>
+ );
+}
+
+/**
+ * The one line that explains a shorter card list. Without it, a user who
+ * forgot the switch is on reads the missing hosted cards as a broken install —
+ * so the notice states the count, and carries the switch-off action itself.
+ */
+export function LocalModeNotice({
+ hiddenCount,
+ keptActiveHosted,
+ onDisable,
+}: {
+ hiddenCount: number;
+ keptActiveHosted: boolean;
+ onDisable: () => void;
+}) {
+ const t = useT();
+ return (
+ <div
+ data-testid="local-mode-notice"
+ className="mb-3 flex items-start gap-2.5 rounded-xl border border-primary/25 bg-primary/[0.05] px-3 py-2"
+ >
+ <HardDrive aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
+ <p className="min-w-0 text-xs leading-relaxed text-muted-foreground">
+ <span className="font-medium text-foreground">
+ {t("apikeys_view.local_mode_label")}
+ </span>{" "}
+ · {t("apikeys_view.local_mode_notice").replace("{0}", String(hiddenCount))}
+ {keptActiveHosted && ` ${t("apikeys_view.local_mode_notice_active")}`}{" "}
+ <button
+ type="button"
+ onClick={onDisable}
+ className="font-medium text-primary underline-offset-2 hover:underline"
+ >
+ {t("apikeys_view.local_mode_show_all")}
+ </button>
+ </p>
+ </div>
+ );
+}
+
/**
* Compact, scrollable context for the header-level engine control. Keeping
* explanatory copy and recommendations inside the provider scroller gives the
@@ -658,6 +761,8 @@ export function ProviderCategory({
onActivateOptimistic,
health,
intro,
+ localMode = false,
+ onDisableLocalMode,
}: {
meta: CategoryMeta;
tier: ProviderTier;
@@ -671,16 +776,36 @@ export function ProviderCategory({
health?: SectionHealth;
/** Optional guidance band rendered between the hero and the card list. */
intro?: React.ReactNode;
+ /** Show only cards that run on the user's own hardware. Presentation only —
+ * defaults off so every existing caller renders the full catalog. */
+ localMode?: boolean;
+ /** Turns Local Mode back off from the notice above the list. */
+ onDisableLocalMode?: () => void;
}) {
const t = useT();
- const tierProviders = providers.filter(
+ const allTierProviders = providers.filter(
(p) => p.tier === tier && p.brain_switchable !== false,
);
+ const {
+ visible: tierProviders,
+ hiddenCount,
+ keptActiveHosted,
+ } = filterForLocalMode(allTierProviders, localMode);
return (
<div role="tabpanel">
<CategoryHero icon={meta.icon} title={meta.title} description={meta.description} />
+ {/* Above the guidance band: the shorter list has to be explained before
+ the user starts scanning it, not after. */}
+ {localMode && hiddenCount > 0 && (
+ <LocalModeNotice
+ hiddenCount={hiddenCount}
+ keptActiveHosted={keptActiveHosted}
+ onDisable={() => onDisableLocalMode?.()}
+ />
+ )}
+
{intro}
{loading && (
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 551d1cba84..6c3d8128fa 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -1186,6 +1186,15 @@
"tab_jarvis_key": "{name} Key",
"jarvis_key_title": "{name} Key",
"jarvis_key_desc": "Der eine Schlüssel, der diese Installation schützt — er entsperrt {name} im Browser und weist lokale Agenten aus.",
+ "local_mode_label": "Local Mode",
+ "local_mode_on": "An",
+ "local_mode_off": "Aus",
+ "local_mode_hint": "Nur Anbieter auf deiner eigenen Hardware.",
+ "local_mode_title_on": "Local Mode ist an — es werden nur Anbieter gezeigt, die auf deiner eigenen Hardware laufen. Klicken, um wieder alle Anbieter zu sehen.",
+ "local_mode_title_off": "Local Mode ist aus — alle Anbieter werden gezeigt. Klicken, um nur die auf deiner eigenen Hardware zu sehen.",
+ "local_mode_notice": "{0} Cloud-Anbieter sind ausgeblendet.",
+ "local_mode_notice_active": "Der gerade genutzte Anbieter bleibt sichtbar, damit du immer siehst, worauf {name} läuft.",
+ "local_mode_show_all": "Alle Anbieter zeigen",
"mode_pipeline": "Pipeline",
"mode_realtime": "Realtime",
"mode_active_badge": "Aktiv",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 9007476662..652dfbefa3 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -1186,6 +1186,15 @@
"tab_jarvis_key": "{name} Key",
"jarvis_key_title": "{name} Key",
"jarvis_key_desc": "The one key that protects this install — it unlocks {name} in the browser and authenticates local agents.",
+ "local_mode_label": "Local Mode",
+ "local_mode_on": "On",
+ "local_mode_off": "Off",
+ "local_mode_hint": "Only providers on your own hardware.",
+ "local_mode_title_on": "Local Mode is on — only providers running on your own hardware are listed. Click to show every provider again.",
+ "local_mode_title_off": "Local Mode is off — every provider is listed. Click to show only the ones running on your own hardware.",
+ "local_mode_notice": "{0} hosted providers are hidden.",
+ "local_mode_notice_active": "The provider currently in use stays visible so you can always see what {name} is running on.",
+ "local_mode_show_all": "Show all providers",
"mode_pipeline": "Pipeline",
"mode_realtime": "Realtime",
"mode_active_badge": "Active",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 69e6a8ebfe..f41a3d091e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -1186,6 +1186,15 @@
"tab_jarvis_key": "{name} Key",
"jarvis_key_title": "{name} Key",
"jarvis_key_desc": "La única clave que protege esta instalación: desbloquea {name} en el navegador y autentica a los agentes locales.",
+ "local_mode_label": "Local Mode",
+ "local_mode_on": "Sí",
+ "local_mode_off": "No",
+ "local_mode_hint": "Solo proveedores en tu propio hardware.",
+ "local_mode_title_on": "Local Mode está activo: solo se muestran los proveedores que funcionan en tu propio hardware. Haz clic para volver a ver todos.",
+ "local_mode_title_off": "Local Mode está desactivado: se muestran todos los proveedores. Haz clic para ver solo los que funcionan en tu propio hardware.",
+ "local_mode_notice": "Hay {0} proveedores en la nube ocultos.",
+ "local_mode_notice_active": "El proveedor en uso sigue visible para que siempre veas con qué funciona {name}.",
+ "local_mode_show_all": "Mostrar todos los proveedores",
"mode_pipeline": "Pipeline",
"mode_realtime": "Tiempo real",
"mode_active_badge": "Activo",
diff --git a/jarvis/ui/web/frontend/src/lib/localMode.test.ts b/jarvis/ui/web/frontend/src/lib/localMode.test.ts
new file mode 100644
index 0000000000..979fa244bd
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/localMode.test.ts
@@ -0,0 +1,137 @@
+/**
+ * The Local Mode filter rules.
+ *
+ * Two properties are load-bearing and pinned here because breaking either one
+ * turns a helpful filter into a confusing one:
+ *
+ * - OFF is the identity function. The switch must be a pure addition; with it
+ * off, the provider console has to behave exactly as it did before it
+ * existed.
+ * - The ACTIVE provider is never hidden. A tier whose running provider is a
+ * hosted account still has to show that card, or the screen answers "what am
+ * I running on?" with an empty space.
+ */
+import { beforeEach, describe, expect, it } from "vitest";
+import type { ProviderDescriptor } from "@/hooks/useProviders";
+import {
+ DEFAULT_LOCAL_MODE,
+ LOCAL_MODE_KEY,
+ filterForLocalMode,
+ getLocalMode,
+ parseLocalMode,
+ readLocalMode,
+ runsOnOwnHardware,
+ setLocalMode,
+ writeLocalMode,
+} from "@/lib/localMode";
+
+function card(
+ id: string,
+ billing: ProviderDescriptor["billing"],
+ active = false,
+): ProviderDescriptor {
+ return {
+ id,
+ label: id,
+ tier: "brain",
+ auth_mode: billing === "local" ? "none" : "api_key",
+ secret_keys: [],
+ secrets_set: {},
+ dashboard_url: null,
+ login_cli: null,
+ install_hint: null,
+ credential_path_hint: null,
+ configured: true,
+ active,
+ cli_installed: null,
+ credential_help: null,
+ signup_url: null,
+ billing,
+ alt_credential: null,
+ };
+}
+
+beforeEach(() => {
+ window.localStorage.clear();
+ setLocalMode(DEFAULT_LOCAL_MODE);
+});
+
+describe("localMode preference", () => {
+ it("defaults to off so a first visit sees the full catalog", () => {
+ expect(DEFAULT_LOCAL_MODE).toBe(false);
+ expect(readLocalMode()).toBe(false);
+ });
+
+ it("round-trips through localStorage", () => {
+ writeLocalMode(true);
+ expect(window.localStorage.getItem(LOCAL_MODE_KEY)).toBe("1");
+ expect(readLocalMode()).toBe(true);
+ writeLocalMode(false);
+ expect(readLocalMode()).toBe(false);
+ });
+
+ it("treats an unknown stored value as unset rather than as on", () => {
+ expect(parseLocalMode("yes")).toBeNull();
+ expect(parseLocalMode(null)).toBeNull();
+ window.localStorage.setItem(LOCAL_MODE_KEY, "banana");
+ expect(readLocalMode()).toBe(DEFAULT_LOCAL_MODE);
+ });
+
+ it("exposes the store imperatively for onboarding and tests", () => {
+ setLocalMode(true);
+ expect(getLocalMode()).toBe(true);
+ setLocalMode(false);
+ expect(getLocalMode()).toBe(false);
+ });
+});
+
+describe("runsOnOwnHardware", () => {
+ it("follows the backend billing field, never a provider id", () => {
+ expect(runsOnOwnHardware(card("ollama", "local"))).toBe(true);
+ // A hosted provider whose id merely *looks* local must not slip through —
+ // this is the AP-21 trap the billing field exists to avoid.
+ expect(runsOnOwnHardware(card("local-sounding-cloud", "api"))).toBe(false);
+ expect(runsOnOwnHardware(card("codex", "subscription"))).toBe(false);
+ expect(runsOnOwnHardware(card("gemini", "subscription_or_api"))).toBe(false);
+ });
+});
+
+describe("filterForLocalMode", () => {
+ const providers = [
+ card("openai", "api"),
+ card("ollama", "local"),
+ card("codex", "subscription"),
+ card("local-openai", "local"),
+ ];
+
+ it("is the identity function while it is off", () => {
+ const result = filterForLocalMode(providers, false);
+ expect(result.visible).toBe(providers);
+ expect(result.hiddenCount).toBe(0);
+ expect(result.keptActiveHosted).toBe(false);
+ });
+
+ it("keeps only own-hardware cards and counts what it hid", () => {
+ const result = filterForLocalMode(providers, true);
+ expect(result.visible.map((p) => p.id)).toEqual(["ollama", "local-openai"]);
+ expect(result.hiddenCount).toBe(2);
+ expect(result.keptActiveHosted).toBe(false);
+ });
+
+ it("never hides the provider the tier is actually running on", () => {
+ const withActiveCloud = [card("openai", "api", true), card("ollama", "local")];
+ const result = filterForLocalMode(withActiveCloud, true);
+ expect(result.visible.map((p) => p.id)).toEqual(["openai", "ollama"]);
+ expect(result.hiddenCount).toBe(0);
+ expect(result.keptActiveHosted).toBe(true);
+ });
+
+ it("does not claim a kept hosted card when the active one is local anyway", () => {
+ const result = filterForLocalMode(
+ [card("openai", "api"), card("ollama", "local", true)],
+ true,
+ );
+ expect(result.keptActiveHosted).toBe(false);
+ expect(result.hiddenCount).toBe(1);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/localMode.ts b/jarvis/ui/web/frontend/src/lib/localMode.ts
new file mode 100644
index 0000000000..1caa7552d2
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/localMode.ts
@@ -0,0 +1,146 @@
+/**
+ * Local Mode: show only the providers that run on the user's own hardware.
+ *
+ * A meaningful share of downloaders never enter a cloud credential — the local
+ * cards are the whole point of that path, and `provider_spec.py` guarantees
+ * every tier has one. For those installs the hosted cards are pure noise: a
+ * wall of key forms the user will never fill in, buried among the two or three
+ * cards that matter. Local Mode hides them.
+ *
+ * Three properties this switch deliberately has:
+ *
+ * 1. **Capability-driven, never name-driven.** "Local" is the backend's own
+ * `billing === "local"`, derived from `auth_mode == "none"` in
+ * `provider_billing()`. Adding a keyless provider makes it appear here with
+ * no change to this file (AP-21).
+ * 2. **Presentation only.** Nothing here switches a provider, writes config, or
+ * gates a runtime path. Flipping it off restores the full catalog and
+ * changes nothing about what the app is actually running.
+ * 3. **The active provider is never hidden.** Filtering away the card that is
+ * powering a tier right now would answer "what am I running on?" with
+ * silence. A hosted card that is active stays visible, and the notice above
+ * the list says why.
+ *
+ * "Local" here means *your own hardware*, which includes an Ollama server on
+ * another box in the house — the honest line for the badge is "runs on your own
+ * machines", not "on-device". A view preference of this machine, so it lives in
+ * localStorage next to `jarvis.wiki.graphDimension` and `jarvis.ui.sound`
+ * rather than in `jarvis.toml`.
+ *
+ * Pure apart from the small store at the bottom, so the filter rules are
+ * unit-testable without a renderer.
+ */
+import { create } from "zustand";
+import type { ProviderDescriptor } from "@/hooks/useProviders";
+
+/** Where the preference is stored, per machine. */
+export const LOCAL_MODE_KEY = "jarvis.providers.localMode";
+
+/** Off by default: the full catalog is what a first-time visitor expects. */
+export const DEFAULT_LOCAL_MODE = false;
+
+/** Narrow an arbitrary stored string; anything else is treated as unset. */
+export function parseLocalMode(raw: string | null): boolean | null {
+ return raw === "1" ? true : raw === "0" ? false : null;
+}
+
+/** The stored preference, or the default when storage is unavailable/empty. */
+export function readLocalMode(): boolean {
+ try {
+ return parseLocalMode(window.localStorage.getItem(LOCAL_MODE_KEY)) ?? DEFAULT_LOCAL_MODE;
+ } catch {
+ // Private mode / storage disabled — a view preference is never worth
+ // taking the provider console down for.
+ return DEFAULT_LOCAL_MODE;
+ }
+}
+
+/** Persist the preference; a storage failure only costs the memory of it. */
+export function writeLocalMode(value: boolean): void {
+ try {
+ window.localStorage.setItem(LOCAL_MODE_KEY, value ? "1" : "0");
+ } catch {
+ // Same reasoning as readLocalMode: never fatal.
+ }
+}
+
+/**
+ * Whether this provider runs on hardware the user controls.
+ *
+ * The backend already answers this: a card with no credential slot bills as
+ * `"local"`. Reading that field keeps the definition in ONE place — the moment
+ * a new keyless card ships, it shows up in Local Mode without a code change
+ * here, and a hosted card can never sneak in by being named "local-something".
+ */
+export function runsOnOwnHardware(provider: ProviderDescriptor): boolean {
+ return provider.billing === "local";
+}
+
+export interface LocalModeFilter {
+ /** The cards to render, in the order they came in. */
+ visible: ProviderDescriptor[];
+ /** How many hosted cards Local Mode took off the screen. */
+ hiddenCount: number;
+ /** True when a hosted card was kept because it is the ACTIVE one. */
+ keptActiveHosted: boolean;
+}
+
+/**
+ * Apply Local Mode to one tier's card list.
+ *
+ * Disabled, this is the identity function — the exact same array comes back, so
+ * the off state cannot differ from the pre-feature behaviour in any way.
+ */
+export function filterForLocalMode(
+ providers: ProviderDescriptor[],
+ enabled: boolean,
+): LocalModeFilter {
+ if (!enabled) {
+ return { visible: providers, hiddenCount: 0, keptActiveHosted: false };
+ }
+ const visible = providers.filter((p) => runsOnOwnHardware(p) || p.active);
+ return {
+ visible,
+ hiddenCount: providers.length - visible.length,
+ keptActiveHosted: visible.some((p) => p.active && !runsOnOwnHardware(p)),
+ };
+}
+
+interface LocalModeStore {
+ enabled: boolean;
+ setEnabled: (value: boolean) => void;
+}
+
+const useLocalModeStore = create<LocalModeStore>((set) => ({
+ enabled: readLocalMode(),
+ setEnabled: (value) => {
+ writeLocalMode(value);
+ set({ enabled: value });
+ },
+}));
+
+/**
+ * Set the preference from outside React — the same path the switch takes, so
+ * every mounted provider list reacts. Used by onboarding's local path (picking
+ * the local brain there turns the mode on) and by tests.
+ */
+export function setLocalMode(value: boolean): void {
+ useLocalModeStore.getState().setEnabled(value);
+}
+
+/** Read the preference outside React (tests, imperative callers). */
+export function getLocalMode(): boolean {
+ return useLocalModeStore.getState().enabled;
+}
+
+export interface LocalModeHandle {
+ localMode: boolean;
+ setLocalMode: (value: boolean) => void;
+}
+
+/** The switch state, shared by every provider list on screen. */
+export function useLocalMode(): LocalModeHandle {
+ const localMode = useLocalModeStore((s) => s.enabled);
+ const setEnabled = useLocalModeStore((s) => s.setEnabled);
+ return { localMode, setLocalMode: setEnabled };
+}
diff --git a/jarvis/ui/web/frontend/src/views/ApiKeysView.local-mode.test.tsx b/jarvis/ui/web/frontend/src/views/ApiKeysView.local-mode.test.tsx
new file mode 100644
index 0000000000..f0d49189e3
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/ApiKeysView.local-mode.test.tsx
@@ -0,0 +1,172 @@
+/**
+ * Component tests for the Local Mode switch on the API-Keys screen.
+ *
+ * The switch answers a specific complaint: an install that went down the local
+ * path landed in a console full of hosted cards, with no obvious, reversible
+ * control over that. So the tests pin the reversibility as hard as the
+ * filtering — the header control has to be present, readable, and able to put
+ * every card back with one click.
+ */
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import type { ProviderDescriptor } from "@/hooks/useProviders";
+
+function card(
+ id: string,
+ label: string,
+ billing: ProviderDescriptor["billing"],
+ active = false,
+): ProviderDescriptor {
+ return {
+ id,
+ label,
+ tier: "brain",
+ auth_mode: billing === "local" ? "none" : "api_key",
+ secret_keys: billing === "local" ? [] : [`${id}_api_key`],
+ secrets_set: {},
+ dashboard_url: null,
+ login_cli: null,
+ install_hint: null,
+ credential_path_hint: null,
+ configured: false,
+ active,
+ cli_installed: null,
+ credential_help: null,
+ signup_url: null,
+ billing,
+ alt_credential: null,
+ };
+}
+
+let mockProviders: ProviderDescriptor[] = [];
+
+vi.mock("@/hooks/useProviders", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@/hooks/useProviders")>();
+ return {
+ ...actual,
+ useProviders: () => ({
+ providers: mockProviders,
+ loading: false,
+ error: null,
+ refetch: vi.fn(),
+ setActiveOptimistic: vi.fn(),
+ }),
+ useSectionHealth: () => ({ health: {}, reload: vi.fn() }),
+ };
+});
+
+vi.mock("@/hooks/useVoiceMode", () => ({
+ useVoiceMode: () => ({
+ mode: "pipeline",
+ realtimeAvailable: true,
+ statusKnown: true,
+ connecting: false,
+ requiresWebRtcOffer: false,
+ transportOfferReady: null,
+ transportOfferDetail: "",
+ transportIssue: null,
+ sessionActive: false,
+ activeSessionMode: null,
+ activeSessionProvider: "",
+ activeSessionModel: "",
+ transitioning: false,
+ setMode: vi.fn(),
+ isLoading: false,
+ isSaving: false,
+ }),
+}));
+
+import { setLocalMode } from "@/lib/localMode";
+import { ApiKeysView } from "@/views/ApiKeysView";
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+ setLocalMode(false);
+ window.localStorage.clear();
+ mockProviders = [];
+});
+
+describe("ApiKeysView local mode", () => {
+ it("sits in the header next to the engine switch and starts off", () => {
+ render(<ApiKeysView />);
+
+ const control = screen.getByTestId("local-mode-switch");
+ expect(control.closest("header")).not.toBeNull();
+ expect(control.getAttribute("aria-pressed")).toBe("false");
+ expect(screen.getByTestId("voice-engine-header-control")).toBeTruthy();
+ expect(screen.queryByTestId("local-mode-notice")).toBeNull();
+ });
+
+ it("hides hosted provider cards when switched on, and restores them when off", () => {
+ mockProviders = [
+ card("openai", "OpenAI", "api"),
+ card("ollama", "Ollama", "local"),
+ ];
+ render(<ApiKeysView />);
+
+ expect(screen.getByText("OpenAI")).toBeTruthy();
+
+ fireEvent.click(screen.getByTestId("local-mode-switch"));
+
+ expect(screen.queryByText("OpenAI")).toBeNull();
+ expect(screen.getByText("Ollama")).toBeTruthy();
+ expect(screen.getByTestId("local-mode-switch").getAttribute("aria-pressed")).toBe(
+ "true",
+ );
+
+ fireEvent.click(screen.getByTestId("local-mode-switch"));
+
+ expect(screen.getByText("OpenAI")).toBeTruthy();
+ expect(screen.queryByTestId("local-mode-notice")).toBeNull();
+ });
+
+ it("says how many cards it hid and offers a way back to all of them", () => {
+ mockProviders = [
+ card("openai", "OpenAI", "api"),
+ card("gemini", "Gemini", "api"),
+ card("ollama", "Ollama", "local"),
+ ];
+ render(<ApiKeysView />);
+
+ fireEvent.click(screen.getByTestId("local-mode-switch"));
+
+ const notice = screen.getByTestId("local-mode-notice");
+ expect(notice.textContent).toContain("2");
+
+ fireEvent.click(screen.getByText("Show all providers"));
+
+ expect(screen.getByText("OpenAI")).toBeTruthy();
+ expect(screen.queryByTestId("local-mode-notice")).toBeNull();
+ });
+
+ it("keeps the running hosted provider visible so the tier is never blank", () => {
+ mockProviders = [
+ card("openai", "OpenAI", "api", true),
+ card("ollama", "Ollama", "local"),
+ ];
+ render(<ApiKeysView />);
+
+ fireEvent.click(screen.getByTestId("local-mode-switch"));
+
+ expect(screen.getByText("OpenAI")).toBeTruthy();
+ // Nothing was hidden, so there is nothing to explain.
+ expect(screen.queryByTestId("local-mode-notice")).toBeNull();
+ });
+
+ it("survives a remount, because it is a stored preference", () => {
+ mockProviders = [
+ card("openai", "OpenAI", "api"),
+ card("ollama", "Ollama", "local"),
+ ];
+ const first = render(<ApiKeysView />);
+ fireEvent.click(screen.getByTestId("local-mode-switch"));
+ first.unmount();
+
+ render(<ApiKeysView />);
+ expect(screen.getByTestId("local-mode-switch").getAttribute("aria-pressed")).toBe(
+ "true",
+ );
+ expect(screen.queryByText("OpenAI")).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx b/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx
index 16b36798b7..dbf1e03af8 100644
--- a/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx
+++ b/jarvis/ui/web/frontend/src/views/ApiKeysView.tsx
@@ -13,6 +13,7 @@ import {
CategoryHero,
EngineModeSwitch,
GuidancePanel,
+ LocalModeSwitch,
makeProviderCategories,
ProviderCategory,
useTierHealth,
@@ -29,6 +30,7 @@ import {
useProviders,
} from "@/hooks/useProviders";
import { useVoiceMode } from "@/hooks/useVoiceMode";
+import { useLocalMode } from "@/lib/localMode";
import { cn } from "@/lib/utils";
import { useT } from "@/i18n";
@@ -97,6 +99,10 @@ export function ApiKeysView() {
setMode: setVoiceMode,
isLoading: liveModeLoading,
} = useVoiceMode();
+ // Show only providers that run on the user's own hardware. A per-machine view
+ // preference (localStorage), deliberately NOT a config switch: it hides cards,
+ // it never changes what the app runs on. See lib/localMode.ts.
+ const { localMode, setLocalMode } = useLocalMode();
// Reset the selected tab to the mode's first tab whenever the mode changes,
// so switching Pipeline→Realtime never leaves `active` pointing at a tab
@@ -132,13 +138,16 @@ export function ApiKeysView() {
title={t("apikeys_view.title")}
subtitle={t("apikeys_view.subtitle")}
right={
- <EngineModeSwitch
- mode={engineMode}
- liveMode={liveMode}
- realtimeAvailable={realtimeAvailable}
- onSelect={setEngineMode}
- onSetVoiceMode={setVoiceMode}
- />
+ <div className="flex items-start gap-2">
+ <LocalModeSwitch enabled={localMode} onToggle={setLocalMode} />
+ <EngineModeSwitch
+ mode={engineMode}
+ liveMode={liveMode}
+ realtimeAvailable={realtimeAvailable}
+ onSelect={setEngineMode}
+ onSetVoiceMode={setVoiceMode}
+ />
+ </div>
}
/>
@@ -183,6 +192,8 @@ export function ApiKeysView() {
onChanged={refetch}
onActivateOptimistic={setActiveOptimistic}
health={health[active]}
+ localMode={localMode}
+ onDisableLocalMode={() => setLocalMode(false)}
/>
)}
{active === "realtime" && (
@@ -194,6 +205,8 @@ export function ApiKeysView() {
onChanged={refetch}
onActivateOptimistic={setActiveOptimistic}
health={health.realtime}
+ localMode={localMode}
+ onDisableLocalMode={() => setLocalMode(false)}
/>
)}
{active === "computer-use" && (
@@ -205,6 +218,8 @@ export function ApiKeysView() {
onChanged={refetch}
onActivateOptimistic={setActiveOptimistic}
health={health["computer-use"]}
+ localMode={localMode}
+ onDisableLocalMode={() => setLocalMode(false)}
/>
)}
{active === "subagents" && <SubagentCategory />}
@@ -397,6 +412,8 @@ function RealtimeCategory({
onChanged,
onActivateOptimistic,
health,
+ localMode = false,
+ onDisableLocalMode,
}: {
meta: CategoryMeta;
providers: ProviderDescriptor[];
@@ -405,6 +422,8 @@ function RealtimeCategory({
onChanged: () => void;
onActivateOptimistic: (tier: ProviderTier, id: string) => void;
health?: SectionHealth;
+ localMode?: boolean;
+ onDisableLocalMode?: () => void;
}) {
const t = useT();
return (
@@ -417,6 +436,8 @@ function RealtimeCategory({
onChanged={onChanged}
onActivateOptimistic={onActivateOptimistic}
health={health}
+ localMode={localMode}
+ onDisableLocalMode={onDisableLocalMode}
intro={
<GuidancePanel
title={t("apikeys_view.guide_realtime_title")}
@@ -450,6 +471,8 @@ function ComputerUseCategory({
onChanged,
onActivateOptimistic,
health,
+ localMode = false,
+ onDisableLocalMode,
}: {
meta: CategoryMeta;
providers: ProviderDescriptor[];
@@ -458,6 +481,8 @@ function ComputerUseCategory({
onChanged: () => void;
onActivateOptimistic: (tier: ProviderTier, id: string) => void;
health?: SectionHealth;
+ localMode?: boolean;
+ onDisableLocalMode?: () => void;
}) {
const t = useT();
const cuProviders: ProviderDescriptor[] = providers
@@ -474,6 +499,8 @@ function ComputerUseCategory({
onChanged={onChanged}
onActivateOptimistic={onActivateOptimistic}
health={health}
+ localMode={localMode}
+ onDisableLocalMode={onDisableLocalMode}
intro={
<GuidancePanel
title={t("apikeys_view.guide_computer_use_title")}