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(chat): show why a vendor session cannot launch
vastsa7e71a01157d7
diff --git a/apps/desktop/src/components/ChatSurface.tsx b/apps/desktop/src/components/ChatSurface.tsxindex 70b3e293e..92ef4476a 100644--- a/apps/desktop/src/components/ChatSurface.tsx+++ b/apps/desktop/src/components/ChatSurface.tsx@@ -1,5 +1,9 @@-import { memo, useMemo } from "react";+import { memo, useMemo, useState } from "react";import { useTranslation } from "react-i18next";+import {+ messageHasTranscriptContent,+ vendorAccountOmitsSessionModel,+} from "../lib/chat-launch-error";import { Composer } from "./Composer";import { HomeMascotLogo } from "./HomeMascotLogo";import { HomeProjectSwitcher } from "./HomeProjectSwitcher";@@ -53,6 +57,10 @@ export const ChatSurface = memo(function ChatSurface() {const error = useAppStore((state) => state.error);const errorCode = useAppStore((state) => state.errorCode);const errorRetriable = useAppStore((state) => state.errorRetriable);+ const [hiddenVendorModelKey, setHiddenVendorModelKey] = useState<string | null>(+ null,+ );+ const providers = useAppStore((state) => state.providers);const activeSession = useAppStore((state) =>state.activeSessionId? state.sessions.find((session) => session.id === state.activeSessionId)@@ -107,19 +115,28 @@ export const ChatSurface = memo(function ChatSurface() {const hasTranscript =Boolean(activePermission) ||askPending ||- messages.some((message) => {- const hasContent = Boolean((message.content || "").trim());- const hasThinking =- typeof message.thinking === "string" &&- Boolean(message.thinking.trim());- if (message.role === "assistant") return hasContent || hasThinking;- return hasContent || message.role === "tool";- });+ messages.some((message) => messageHasTranscriptContent(message));// The empty state belongs to the session on screen. While a cold switch is// still resolving, the visible pane keeps its own transcript, so the hero must// not take over just because the destination projection is still empty.const showEmptyState =!hasTranscript && (!visibleSessionId || visibleSessionId === activeSessionId);+ const vendorModelMissing = vendorAccountOmitsSessionModel(+ activeSession,+ providers,+ );+ const vendorModelKey = vendorModelMissing+ ? `${activeSession?.providerId ?? ""}:${activeSession?.modelId ?? ""}`+ : null;+ const showVendorModelError =+ vendorModelKey !== null && hiddenVendorModelKey !== vendorModelKey;+ const noticeError =+ error ?? (showVendorModelError ? t("errors.MODEL_NOT_CONFIGURED") : null);+ const noticeCode = error+ ? errorCode+ : showVendorModelError+ ? "MODEL_NOT_CONFIGURED"+ : null;return (<divclassName={`chat-surface route-surface${sessionSwitching ? " session-switching" : ""}`}@@ -185,17 +202,23 @@ export const ChatSurface = memo(function ChatSurface() {</>)}- {error ? (+ {noticeError ? (<div className="chat-error-layer"><div className="chat-error-notice">- <span title={error ?? undefined}>- {errorCode && i18nHasError(t, errorCode)- ? t(`errors.${errorCode}`)- : error}+ <span title={noticeError}>+ {noticeCode && i18nHasError(t, noticeCode)+ ? t(`errors.${noticeCode}`)+ : noticeError}+ {showVendorModelError && !error && activeSession?.modelId ? (+ <>+ {" "}+ <code>{activeSession.modelId}</code>+ </>+ ) : null}</span>- {(errorCode === "MODEL_NOT_CONFIGURED" ||- errorCode === "PROVIDER_SECRET_MISSING" ||- errorCode === "PROVIDER_UNAUTHORIZED") && (+ {(noticeCode === "MODEL_NOT_CONFIGURED" ||+ noticeCode === "PROVIDER_SECRET_MISSING" ||+ noticeCode === "PROVIDER_UNAUTHORIZED") && (<buttontype="button"className="chat-error-action"@@ -224,7 +247,13 @@ export const ChatSurface = memo(function ChatSurface() {tooltip={t("errors.action.dismiss")}ariaLabel={t("errors.action.dismiss")}className="chat-error-dismiss"- onClick={() => useAppStore.getState().clearError()}+ onClick={() => {+ if (error) {+ useAppStore.getState().clearError();+ return;+ }+ if (vendorModelKey) setHiddenVendorModelKey(vendorModelKey);+ }}><IconX size={13} /></TooltipButton>diff --git a/apps/desktop/src/lib/chat-launch-error.ts b/apps/desktop/src/lib/chat-launch-error.tsnew file mode 100644index 000000000..2803554ca--- /dev/null+++ b/apps/desktop/src/lib/chat-launch-error.ts@@ -0,0 +1,49 @@+import { modelIdsMatch, OAUTH_AUTH_KIND } from "@pi-desktop/shared";++type TranscriptMessage = {+ role: string;+ content?: string;+ thinking?: string;+ error?: unknown;+};++/** An assistant row that only carries a launch error is still the conversation. */+export function messageHasTranscriptContent(message: TranscriptMessage): boolean {+ const hasContent = Boolean((message.content || "").trim());+ const hasThinking =+ typeof message.thinking === "string" && Boolean(message.thinking.trim());+ if (message.role === "assistant") {+ return hasContent || hasThinking || Boolean(message.error);+ }+ return hasContent || message.role === "tool";+}++type VendorSessionModel = {+ providerId?: string | null;+ modelId?: string | null;+};++type VendorModelProvider = {+ id: string;+ authKind?: string;+ models?: ReadonlyArray<{ id: string }>;+};++/**+ * Vendor accounts refuse a session model the account list did not return.+ * An empty list means the catalog has not loaded, not that the account+ * offers nothing, so it must not turn a normal empty chat into an error.+ */+export function vendorAccountOmitsSessionModel(+ session: VendorSessionModel | null | undefined,+ providers: readonly VendorModelProvider[],+): boolean {+ const providerId = session?.providerId?.trim();+ const modelId = session?.modelId?.trim();+ if (!providerId || !modelId) return false;+ const provider = providers.find((item) => item.id === providerId);+ if (!provider || provider.authKind !== OAUTH_AUTH_KIND) return false;+ const models = provider.models ?? [];+ if (models.length === 0) return false;+ return !models.some((model) => modelIdsMatch(model.id, modelId));+}diff --git a/apps/desktop/test/chat-launch-error.test.mjs b/apps/desktop/test/chat-launch-error.test.mjsnew file mode 100644index 000000000..008fe1f04--- /dev/null+++ b/apps/desktop/test/chat-launch-error.test.mjs@@ -0,0 +1,59 @@+import assert from "node:assert/strict";+import test from "node:test";++import {+ messageHasTranscriptContent,+ vendorAccountOmitsSessionModel,+} from "../src/lib/chat-launch-error.ts";++const oauth = (models) => [{ id: "chatgpt", authKind: "oauth", models }];++test("a launch error with no assistant text still counts as a transcript", () => {+ assert.equal(+ messageHasTranscriptContent({+ role: "assistant",+ content: "",+ error: { code: "MODEL_NOT_CONFIGURED", message: "missing" },+ }),+ true,+ );+ assert.equal(+ messageHasTranscriptContent({ role: "assistant", content: " " }),+ false,+ );+ assert.equal(+ messageHasTranscriptContent({ role: "user", content: "hello" }),+ true,+ );+});++test("an empty vendor chat names a model the account did not return", () => {+ const session = { providerId: "chatgpt", modelId: "gpt-6-luna" };+ assert.equal(+ vendorAccountOmitsSessionModel(session, oauth([{ id: "gpt-5.6-luna" }])),+ true,+ );+ assert.equal(+ vendorAccountOmitsSessionModel(session, oauth([{ id: "openai/gpt-6-luna" }])),+ false,+ );+ assert.equal(vendorAccountOmitsSessionModel(session, oauth([])), false);+ assert.equal(+ vendorAccountOmitsSessionModel(session, [+ { id: "chatgpt", authKind: "api_key", models: [{ id: "gpt-5.6-luna" }] },+ ]),+ false,+ );+});++test("the chat surface shows that omission instead of an empty page", async () => {+ const { readFile } = await import("node:fs/promises");+ const surface = await readFile(+ new URL("../src/components/ChatSurface.tsx", import.meta.url),+ "utf8",+ );+ assert.match(surface, /messageHasTranscriptContent\(message\)/);+ assert.match(surface, /vendorAccountOmitsSessionModel\(/);+ assert.match(surface, /activeSession\.modelId/);+ assert.match(surface, /noticeError \?/);+});