Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat(desktop): Mercury Cloud card first, live status, sign in again in-app

Salman Qureshica7f59f67838
diff --git a/apps/desktop/src/api/models.ts b/apps/desktop/src/api/models.ts
index 91abe1e7..f33b7f46 100644
--- a/apps/desktop/src/api/models.ts
+++ b/apps/desktop/src/api/models.ts
@@ -106,3 +106,29 @@ export function fieldApplies(f: VoiceField, values: Record<string, unknown>): bo
return Array.isArray(want) ? want.includes(v) : v === String(want);
}));
}
+
+/** GET /api/cloud/status: is Mercury Cloud working, and what to do if not. */
+export interface CloudStatus {
+ paired: boolean;
+ enabled: boolean;
+ isDefault: boolean;
+ tier: string | null;
+ model: string;
+ modelOk: boolean;
+ chat: { ok: boolean; models: string[]; error: string | null };
+ /** The agent's live connection to Cloud. */
+ session: "online" | "offline" | "signed-out" | "off";
+ sessionError: string | null;
+ /** Has the long-lived key that renews an expired session by itself. */
+ selfRecovers: boolean;
+ action: "sign-in" | "pick-model" | null;
+ signin: CloudSignIn | null;
+}
+export interface CloudSignIn { code: string; pairingUrl: string; status: "pending" | "done" | "failed"; error: string | null; upgradeUrl: string | null }
+
+export const cloudApi = {
+ status: (fresh = false) => http.get<CloudStatus>(`/api/cloud/status${fresh ? "?fresh=1" : ""}`),
+ startSignIn: () => http.post<CloudSignIn>("/api/cloud/signin"),
+ signIn: () => http.get<CloudSignIn | { status: "none" }>("/api/cloud/signin"),
+ cancelSignIn: () => http.delete<{ ok: boolean }>("/api/cloud/signin"),
+};
diff --git a/apps/desktop/src/app/store.ts b/apps/desktop/src/app/store.ts
index 9361b4b7..a3dc394a 100644
--- a/apps/desktop/src/app/store.ts
+++ b/apps/desktop/src/app/store.ts
@@ -20,6 +20,10 @@ interface UiState {
setVoiceOpen(open: boolean): void;
sidebar: boolean;
toggleSidebar(): void;
+ /** A Settings section to open next (e.g. "models" from the Cloud banner); Settings consumes it. */
+ settingsSection: string | null;
+ openSettings(section: string): void;
+ clearSettingsSection(): void;
}
export const useUi = create<UiState>((set) => ({
@@ -29,6 +33,9 @@ export const useUi = create<UiState>((set) => ({
setVoiceOpen: (voiceOpen) => set({ voiceOpen }),
sidebar: true,
toggleSidebar: () => set((s) => ({ sidebar: !s.sidebar })),
+ settingsSection: null,
+ openSettings: (section) => set({ view: "settings", settingsSection: section }),
+ clearSettingsSection: () => set({ settingsSection: null }),
}));
interface RuntimeState {
diff --git a/apps/desktop/src/layout/Workspace.tsx b/apps/desktop/src/layout/Workspace.tsx
index a5a2010c..0860bc99 100644
--- a/apps/desktop/src/layout/Workspace.tsx
+++ b/apps/desktop/src/layout/Workspace.tsx
@@ -18,6 +18,7 @@ import { SkillsView } from "~/views/skills/SkillsView";
import { SettingsView } from "~/views/settings/SettingsView";
import { BrainView } from "~/views/brain/BrainView";
import { ErrorBoundary } from "~/components/ErrorBoundary";
+import { CloudBanner } from "~/views/settings/Cloud";
registerBuiltinStatusItems();
@@ -43,6 +44,7 @@ export function Workspace({ connection, health, onSwitchConnection }: { connecti
return (
<div className="flex h-full w-full flex-col overflow-hidden bg-bg">
<EnvironmentBar connection={connection} health={health} />
+ <CloudBanner supported={!!health.features?.includes("cloud.signin")} />
<div className="flex min-h-0 flex-1">
<Rail connectionName={connection.name} />
<main className="relative flex min-w-0 flex-1 flex-col">
diff --git a/apps/desktop/src/shell/FirstModel.tsx b/apps/desktop/src/shell/FirstModel.tsx
index 33b12cd7..a84637ab 100644
--- a/apps/desktop/src/shell/FirstModel.tsx
+++ b/apps/desktop/src/shell/FirstModel.tsx
@@ -5,6 +5,8 @@ import { Wordmark } from "~/components/Logo";
import { Badge, Spinner } from "~/components/ui/bits";
import { IconTile } from "~/components/ui/kit";
import { ProviderEditor, errorText } from "~/views/settings/Models";
+import { CloudSignInFlow } from "~/views/settings/Cloud";
+import { Sparkles } from "lucide-react";
/**
* First run, after Mercury is installed: it can't think until a model is
@@ -19,6 +21,7 @@ export function FirstModel({ onReady, onSwitch }: { onReady: () => void; onSwitc
const [picked, setPicked] = useState<ProviderInfo | null>(null);
const [all, setAll] = useState(false);
const [starting, setStarting] = useState<string | null>(null);
+ const [cloud, setCloud] = useState<"idle" | "signing-in" | null>("idle");
useEffect(() => { modelsApi.settings().then(setData).catch((e) => setError(errorText(e))); }, []);
// After the restart, reconnect; the workspace takes over once Mercury is up.
@@ -44,8 +47,24 @@ export function FirstModel({ onReady, onSwitch }: { onReady: () => void; onSwitc
{error && !starting && <p className="text-center text-sm text-red">Couldn't reach Mercury: {error}</p>}
{!data && !error && <div className="flex justify-center text-ink3"><Spinner size={18} /></div>}
+ {data && !starting && !picked && cloud && (
+ <div className="flex flex-col gap-3 rounded-xl border border-accent/40 bg-accent/[0.05] p-4">
+ <div className="flex items-start gap-3">
+ <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent"><Sparkles size={18} /></div>
+ <div className="min-w-0 flex-1">
+ <div className="flex items-center gap-2"><span className="text-base font-medium text-ink">Mercury Cloud</span><Badge tone="cyan">recommended</Badge></div>
+ <div className="text-xs text-ink3">The quick start: sign in and chat. No API keys.</div>
+ </div>
+ </div>
+ {cloud === "signing-in"
+ ? <CloudSignInFlow onDone={() => setStarting("Mercury Cloud")} onCancel={() => setCloud("idle")} />
+ : <div><button onClick={() => setCloud("signing-in")} className="rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-on-accent hover:bg-accent/90">Sign in to Mercury Cloud</button></div>}
+ </div>
+ )}
+
{data && !starting && !picked && (
<div className="flex flex-col gap-2">
+ <div className="text-xs text-ink4">Or bring your own key</div>
{featured.map((p) => <Choice key={p.id} p={p} onPick={() => setPicked(p)} />)}
{all && others.map((p) => <Choice key={p.id} p={p} onPick={() => setPicked(p)} />)}
{!all && <button className="self-center text-xs text-ink3 hover:text-ink hover:underline" onClick={() => setAll(true)}>More providers ({others.length})</button>}
diff --git a/apps/desktop/src/views/settings/Cloud.tsx b/apps/desktop/src/views/settings/Cloud.tsx
new file mode 100644
index 00000000..d3c7ee18
--- /dev/null
+++ b/apps/desktop/src/views/settings/Cloud.tsx
@@ -0,0 +1,223 @@
+import { CheckCircle2, CircleAlert, CircleDashed, ExternalLink, LogIn, RefreshCw, Sparkles, TriangleAlert, X } from "lucide-react";
+import { useCallback, useEffect, useRef, useState } from "react";
+import { cloudApi, modelsApi, type CloudSignIn, type CloudStatus } from "~/api/models";
+import { useUi } from "~/app/store";
+import { ModelPicker } from "~/components/ModelPicker";
+import { Button } from "~/components/ui/Button";
+import { Badge, Spinner } from "~/components/ui/bits";
+import { desktop } from "~/shell/tauri";
+import { cx } from "~/lib/cx";
+
+/**
+ * Mercury Cloud: the quick start (sign in, chat, no API keys). Always first.
+ * Shows whether it really works right now (the chat key, the agent's live
+ * session), and signs in again from the app when the session has expired.
+ */
+
+function errorText(e: unknown): string {
+ return e instanceof Error ? e.message : String(e);
+}
+
+export function useCloudStatus(enabled = true): { status: CloudStatus | null; error: string | null; checking: boolean; refresh: (fresh?: boolean) => Promise<void> } {
+ const [status, setStatus] = useState<CloudStatus | null>(null);
+ const [error, setError] = useState<string | null>(null);
+ const [checking, setChecking] = useState(false);
+ const refresh = useCallback(async (fresh = false) => {
+ setChecking(true);
+ try { setStatus(await cloudApi.status(fresh)); setError(null); } catch (e) { setError(errorText(e)); } finally { setChecking(false); }
+ }, []);
+ useEffect(() => { if (enabled) void refresh(); }, [enabled, refresh]);
+ return { status, error, checking, refresh };
+}
+
+export function CloudCard({ onChanged }: { onChanged: () => void }) {
+ const { status, error, checking, refresh } = useCloudStatus();
+ const [signingIn, setSigningIn] = useState(false);
+ const [model, setModel] = useState("");
+ const [saving, setSaving] = useState(false);
+ const [note, setNote] = useState<string | null>(null);
+ useEffect(() => { if (status) setModel(status.modelOk ? status.model : status.chat.models[0] ?? ""); }, [status?.model, status?.modelOk]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ async function saveModel(makeDefault: boolean) {
+ setSaving(true);
+ setNote(null);
+ try {
+ await modelsApi.save("mercuryCloud", { model, enabled: true });
+ if (makeDefault) await modelsApi.roles({ default: { provider: "mercuryCloud", model } });
+ setNote(makeDefault ? "Mercury Cloud is now the default." : "Saved.");
+ await refresh(true);
+ onChanged();
+ } catch (e) { setNote(errorText(e)); } finally { setSaving(false); }
+ }
+
+ const connected = !!status && status.chat.ok;
+ return (
+ <div className={cx("flex flex-col gap-4 rounded-xl border p-4", status?.action === "sign-in" && status.paired ? "border-amber/50 bg-amber/[0.04]" : "border-accent/40 bg-accent/[0.04]")}>
+ <div className="flex items-start gap-3">
+ <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent"><Sparkles size={18} /></div>
+ <div className="min-w-0 flex-1">
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="text-base font-medium text-ink">Mercury Cloud</span>
+ <Badge tone="cyan">recommended</Badge>
+ {status?.isDefault && connected && <Badge tone="accent">default</Badge>}
+ {status?.tier && status.paired && <Badge>{status.tier}</Badge>}
+ </div>
+ <p className="text-xs text-ink3">The quick start: sign in and chat. No API keys; models from every major lab on one account.</p>
+ </div>
+ <Button size="sm" variant="ghost" icon onClick={() => void refresh(true)} loading={checking} aria-label="Check Mercury Cloud now" title="Check now"><RefreshCw size={14} /></Button>
+ </div>
+
+ {error && <p className="text-sm text-red">Couldn't check Mercury Cloud: {error}</p>}
+ {!status && !error && <Spinner size={14} />}
+
+ {status && (status.paired || status.chat.ok) && (
+ <div className="grid grid-cols-1 gap-1.5 rounded-lg border border-line bg-surface p-3 text-sm sm:grid-cols-3">
+ <Check ok={status.chat.ok} label="Chat" detail={status.chat.ok ? `${status.chat.models.length} models` : status.chat.error ?? "not working"} />
+ <Check ok={status.session === "online"} warn={status.session === "offline"} label="Agent connection"
+ detail={status.session === "online" ? "online" : status.session === "offline" ? "reconnecting" : status.session === "signed-out" ? "signed out" : "off"} />
+ <Check ok={status.selfRecovers} warn={!status.selfRecovers} label="Stays signed in"
+ detail={status.selfRecovers ? "renews by itself" : "sign in again to turn on"} />
+ </div>
+ )}
+
+ {status?.action === "sign-in" && status.paired && !signingIn && (
+ <p className="flex items-start gap-2 text-sm text-ink2">
+ <TriangleAlert size={15} className="mt-0.5 shrink-0 text-amber" />
+ {status.chat.ok
+ ? "Your session with Mercury Cloud expired and couldn't renew itself. Chat still works, but the agent is offline for the Cloud dashboard and phone. Sign in again to fix it for good."
+ : "Mercury Cloud no longer accepts this sign-in. Sign in again to keep chatting."}
+ </p>
+ )}
+
+ {signingIn ? (
+ <CloudSignInFlow onDone={() => { setSigningIn(false); onChanged(); }} onCancel={() => setSigningIn(false)} />
+ ) : (status?.action === "sign-in" || !status?.paired) && status ? (
+ <div><Button variant="primary" onClick={() => setSigningIn(true)}><LogIn size={14} /> {status.paired ? "Sign in again" : "Sign in to Mercury Cloud"}</Button></div>
+ ) : null}
+
+ {status && status.chat.ok && !signingIn && (
+ <div className="flex flex-col gap-2">
+ {!status.modelOk && <p className="text-xs text-amber">The saved model ({status.model}) can't chat or isn't on your plan. Pick one below.</p>}
+ <div className="flex flex-wrap items-center gap-2">
+ <div className="min-w-[240px] flex-1"><ModelPicker value={model} models={status.chat.models} onChange={setModel} /></div>
+ {(model !== status.model || !status.modelOk) && <Button size="md" variant="outline" loading={saving} disabled={!model} onClick={() => void saveModel(false)}>Save model</Button>}
+ {!status.isDefault && <Button size="md" variant="primary" loading={saving} disabled={!model} onClick={() => void saveModel(true)}>Make default</Button>}
+ </div>
+ {note && <p className="text-xs text-ink3">{note}</p>}
+ </div>
+ )}
+ </div>
+ );
+}
+
+function Check({ ok, warn, label, detail }: { ok: boolean; warn?: boolean; label: string; detail: string }) {
+ return (
+ <div className="flex items-center gap-2">
+ {ok ? <CheckCircle2 size={14} className="shrink-0 text-accent" /> : warn ? <CircleDashed size={14} className="shrink-0 text-amber" /> : <CircleAlert size={14} className="shrink-0 text-red" />}
+ <span className="text-ink">{label}</span>
+ <span className="truncate text-xs text-ink3">{detail}</span>
+ </div>
+ );
+}
+
+/**
+ * Sign in: Mercury asks Cloud for a pairing code, the browser opens to
+ * approve it, and Mercury waits. When approved, Mercury saves the new
+ * session and restarts itself; the app reconnects on its own.
+ */
+export function CloudSignInFlow({ onDone, onCancel }: { onDone: () => void; onCancel?: () => void }) {
+ const [state, setState] = useState<CloudSignIn | null>(null);
+ const [error, setError] = useState<string | null>(null);
+ const [restarting, setRestarting] = useState(false);
+ const opened = useRef(false);
+
+ useEffect(() => {
+ let live = true;
+ let timer: ReturnType<typeof setTimeout> | null = null;
+ async function begin() {
+ try {
+ const s = await cloudApi.startSignIn();
+ if (!live) return;
+ setState(s);
+ if (!opened.current) { opened.current = true; void desktop.openExternal(s.pairingUrl); }
+ poll();
+ } catch (e) { if (live) setError(errorText(e)); }
+ }
+ function poll() {
+ timer = setTimeout(async () => {
+ try {
+ const s = await cloudApi.signIn();
+ if (!live) return;
+ if ("code" in s) {
+ setState(s);
+ if (s.status === "done") { setRestarting(true); setTimeout(() => { if (live) onDone(); }, 6000); return; }
+ if (s.status === "failed") return;
+ }
+ } catch { /* Mercury may be restarting; keep waiting */ }
+ if (live) poll();
+ }, 1500);
+ }
+ void begin();
+ return () => { live = false; if (timer) clearTimeout(timer); };
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
+
+ if (error) return (
+ <div className="flex flex-col gap-2">
+ <p className="text-sm text-red">{error}</p>
+ {onCancel && <div><Button size="sm" variant="ghost" onClick={onCancel}>Close</Button></div>}
+ </div>
+ );
+ if (restarting) return <p className="flex items-center gap-2 text-sm text-ink2"><Spinner size={13} /> Signed in. Mercury is restarting with the new session…</p>;
+ if (!state) return <p className="flex items-center gap-2 text-sm text-ink3"><Spinner size={13} /> Starting sign-in…</p>;
+ if (state.status === "failed") return (
+ <div className="flex flex-col gap-2">
+ <p className="text-sm text-red">{state.error}</p>
+ <div className="flex gap-2">
+ {state.upgradeUrl && <Button size="sm" variant="primary" onClick={() => void desktop.openExternal(state.upgradeUrl!)}>Upgrade plan <ExternalLink size={12} /></Button>}
+ {onCancel && <Button size="sm" variant="ghost" onClick={onCancel}>Close</Button>}
+ </div>
+ </div>
+ );
+ return (
+ <div className="flex flex-col gap-3 rounded-lg border border-line bg-surface p-4">
+ <p className="text-sm text-ink2">Approve this computer in your browser. Waiting for you…</p>
+ <div className="flex items-center gap-3">
+ <span className="rounded-md bg-ink/[0.06] px-3 py-1.5 font-mono text-base tracking-widest text-ink">{state.code}</span>
+ <Spinner size={14} />
+ </div>
+ <div className="flex flex-wrap gap-2">
+ <Button size="sm" variant="outline" onClick={() => void desktop.openExternal(state.pairingUrl)}>Open the browser again <ExternalLink size={12} /></Button>
+ {onCancel && <Button size="sm" variant="ghost" onClick={() => { void cloudApi.cancelSignIn().catch(() => {}); onCancel(); }}>Cancel</Button>}
+ </div>
+ </div>
+ );
+}
+
+/**
+ * A thin bar across the app when Mercury Cloud is the default and its
+ * session is gone: it says what still works and fixes it in one click.
+ * Checked on start, every 10 minutes, and whenever the window comes back.
+ */
+export function CloudBanner({ supported }: { supported: boolean }) {
+ const { status, refresh } = useCloudStatus(supported);
+ const [hidden, setHidden] = useState(false);
+ const openSettings = useUi((s) => s.openSettings);
+ useEffect(() => {
+ if (!supported) return;
+ const t = setInterval(() => void refresh(), 10 * 60_000);
+ const onFocus = () => void refresh();
+ window.addEventListener("focus", onFocus);
+ return () => { clearInterval(t); window.removeEventListener("focus", onFocus); };
+ }, [supported, refresh]);
+ if (!supported || hidden || !status || !status.paired || !status.isDefault || status.action !== "sign-in") return null;
+ return (
+ <div className="flex items-center gap-3 border-b border-amber/30 bg-amber/[0.08] px-4 py-1.5 text-xs text-ink2">
+ <TriangleAlert size={13} className="shrink-0 text-amber" />
+ <span className="min-w-0 flex-1 truncate">
+ {status.chat.ok ? "Mercury Cloud signed out: chat works, but the agent is offline for the Cloud dashboard and phone." : "Mercury Cloud signed out: chat won't work until you sign in again."}
+ </span>
+ <Button size="sm" variant="primary" onClick={() => openSettings("models")}><LogIn size={12} /> Sign in again</Button>
+ <button onClick={() => setHidden(true)} className="text-ink4 hover:text-ink" aria-label="Hide for now"><X size={13} /></button>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/views/settings/Models.tsx b/apps/desktop/src/views/settings/Models.tsx
index 57212cfa..ec1086ea 100644
--- a/apps/desktop/src/views/settings/Models.tsx
+++ b/apps/desktop/src/views/settings/Models.tsx
@@ -9,6 +9,7 @@ import { Field, Input } from "~/components/ui/Input";
import { Badge, Spinner } from "~/components/ui/bits";
import { ConfirmButton, IconTile } from "~/components/ui/kit";
import { desktop } from "~/shell/tauri";
+import { CloudCard } from "./Cloud";
import { cx } from "~/lib/cx";
/**
@@ -45,8 +46,11 @@ export function ModelsSettings() {
if (error) return <p className="text-sm text-red">Couldn't load providers: {error}</p>;
if (!data) return <Spinner size={16} />;
- const connected = data.providers.filter((p) => p.configured);
- const rest = data.providers.filter((p) => !p.configured);
+ // Mercury Cloud has its own card, always first.
+ const others = data.providers.filter((p) => p.id !== "mercuryCloud");
+ const connected = others.filter((p) => p.configured);
+ const rest = others.filter((p) => !p.configured);
+ const anyConnected = data.providers.some((p) => p.configured);
return (
<section className="flex flex-col gap-6">
@@ -56,9 +60,11 @@ export function ModelsSettings() {
</div>
)}
- {connected.length === 0
- ? <EmptyState />
- : <Defaults data={data} onSaved={(r) => saved(r, "Saved")} />}
+ <CloudCard onChanged={() => void load()} />
+
+ {anyConnected
+ ? <Defaults data={data} onSaved={(r) => saved(r, "Saved")} />
+ : <EmptyState />}
{connected.length > 0 && (
<div className="flex flex-col gap-2">
@@ -111,7 +117,7 @@ function EmptyState() {
<TriangleAlert size={16} className="mt-0.5 shrink-0 text-amber" />
<div className="text-sm text-ink2">
<div className="font-medium text-ink">No model connected yet</div>
- Mercury needs at least one. A gateway like AI/ML API gives you models from every major lab on one key; Ollama runs free models on this computer.
+ Mercury needs at least one. Mercury Cloud is the quickest: sign in, no keys. Or bring your own key below; Ollama runs free models on this computer.
</div>
</div>
);
diff --git a/apps/desktop/src/views/settings/SettingsView.tsx b/apps/desktop/src/views/settings/SettingsView.tsx
index 9996ca57..2e93a3b6 100644
--- a/apps/desktop/src/views/settings/SettingsView.tsx
+++ b/apps/desktop/src/views/settings/SettingsView.tsx
@@ -1,6 +1,7 @@
import { Activity, Boxes, Info, Mic, PanelBottom, Palette, Power, Server, Smartphone, UserRound } from "lucide-react";
import { useEffect, useState } from "react";
import { cx } from "~/lib/cx";
+import { useUi } from "~/app/store";
import * as api from "~/api/mercury";
import type { DeviceSummary, HealthInfo } from "~/api/types";
import { TINTS, useTheme, type ThemeMode } from "~/app/theme";
@@ -39,6 +40,13 @@ const SECTIONS: Array<{ id: Section; label: string; icon: typeof Palette }> = [
export function SettingsView({ connection, health, onSwitchConnection }: { connection: Connection; health: HealthInfo; onSwitchConnection: () => void }) {
const [section, setSection] = useState<Section>("appearance");
+ // Another screen asked for a section (the Cloud banner opens Models).
+ const wanted = useUi((s) => s.settingsSection);
+ const clearWanted = useUi((s) => s.clearSettingsSection);
+ useEffect(() => {
+ if (wanted && SECTIONS.some((x) => x.id === wanted)) setSection(wanted as Section);
+ if (wanted) clearWanted();
+ }, [wanted, clearWanted]);
return (
<div className="flex h-full min-h-0">
<aside className="flex w-[240px] shrink-0 flex-col border-r border-line bg-soft">