Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(chat): show welcome when active provider is selected but disconnected
Etienne Lescotee16b425a865
diff --git a/src/components/ai-edition/LeftPanel.tsx b/src/components/ai-edition/LeftPanel.tsxindex 0884f29f4..9c2631d96 100644--- a/src/components/ai-edition/LeftPanel.tsx+++ b/src/components/ai-edition/LeftPanel.tsx@@ -22,6 +22,7 @@ import {type ReasoningEffort,} from "../../../electron/ai-edition/provider-registry";import { ChatWelcome } from "./ChatWelcome";+import { canSendChat } from "./chatAvailability";import { computeBudget } from "./chatBudget";import { ChatHistoryModal, SourceTranscriptModal } from "./Modals";import styles from "./NewEditorShell.module.css";@@ -674,6 +675,13 @@ function ChatStripPanel() {} | null>(null);const [reasoningBusy, setReasoningBusy] = useState(false);const [connectedProviders, setConnectedProviders] = useState<string[]>([]);+ // Derive "can the user actually chat right now?" once, then use it+ // everywhere. A stale active config that points at a provider with no+ // credentials still counts as not-ready — the welcome view + disabled+ // composer are the right surface. See chatAvailability.ts for the truth+ // table; the empty-string provider case is what you get immediately+ // after `llmDisconnect` writes its reset.+ const canChat = canSendChat(llmConfig, connectedProviders);const [modelPopoverOpen, setModelPopoverOpen] = useState(false);const modelButtonRef = useRef<HTMLButtonElement | null>(null);const [modelPopoverRect, setModelPopoverRect] = useState<{@@ -776,7 +784,7 @@ function ChatStripPanel() {// surfacing a generic LLM error. The composer is also disabled in this// state, but Enter-to-send could still slip through (e.g. focus// restored via shortcut), so the check lives here too.- if (connectedProviders.length === 0) {+ if (!canChat) {setSettingsOpen(true);return;}@@ -1415,7 +1423,7 @@ function ChatStripPanel() {</div><div className={styles.panelBody} ref={scrollRef}>- {connectedProviders.length === 0 ? (+ {!canChat ? (<ChatWelcome onOpenProviderSettings={() => setSettingsOpen(true)} />) : messages.length === 0 ? (<p@@ -1581,12 +1589,10 @@ function ChatStripPanel() {<div className={styles.chatInput}><textareaplaceholder={- connectedProviders.length === 0- ? t("chat.composerDisabledNoProvider")- : t("chat.composerPlaceholder")+ canChat ? t("chat.composerPlaceholder") : t("chat.composerDisabledNoProvider")}value={input}- disabled={connectedProviders.length === 0}+ disabled={!canChat}onChange={(e) => setInput(e.target.value)}onKeyDown={(e) => {if (e.key === "Enter" && !e.shiftKey) {@@ -1698,14 +1704,10 @@ function ChatStripPanel() {<buttontype="button"className={styles.sendBtn}- title={- connectedProviders.length === 0- ? t("chat.composerDisabledNoProvider")- : t("chat.sendTitle")- }+ title={canChat ? t("chat.sendTitle") : t("chat.composerDisabledNoProvider")}aria-label={t("chat.send")}onClick={() => void send()}- disabled={busy || !input.trim() || connectedProviders.length === 0}+ disabled={busy || !input.trim() || !canChat}><svgwidth={14}diff --git a/src/components/ai-edition/chatAvailability.test.ts b/src/components/ai-edition/chatAvailability.test.tsnew file mode 100644index 000000000..c1a9d8521--- /dev/null+++ b/src/components/ai-edition/chatAvailability.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vitest";+import type { AiEditionLlmConfig } from "@/native/contracts";+import { canSendChat } from "./chatAvailability";++function cfg(provider: string, model = "gpt-4o-mini"): AiEditionLlmConfig {+ return { provider, model };+}++describe("canSendChat", () => {+ it("returns false when there is no config at all", () => {+ expect(canSendChat(null, [])).toBe(false);+ });++ it("returns false when the config is the post-disconnect reset (provider: '')", () => {+ // The disconnect flow in aiEditionService.llmDisconnect writes an+ // empty-string provider to the active config. We treat that the same+ // as "nothing selected" so the welcome view shows immediately.+ expect(canSendChat(cfg(""), ["minimax"])).toBe(false);+ });++ it("returns false when the active provider has no credentials", () => {+ // The user selected MiniMax-M3 then disconnected it. `connectedProviders`+ // is empty but the stale config still references minimax.+ expect(canSendChat(cfg("minimax"), [])).toBe(false);+ });++ it("returns false when other providers are connected but not the active one", () => {+ // Active config points at openai; only anthropic has credentials.+ // The user needs to switch the active provider via the model picker+ // (or reconnect openai) before they can chat.+ expect(canSendChat(cfg("openai"), ["anthropic"])).toBe(false);+ });++ it("returns true when the active provider is in the connected list", () => {+ expect(canSendChat(cfg("minimax"), ["minimax"])).toBe(true);+ expect(canSendChat(cfg("openai"), ["openai", "anthropic"])).toBe(true);+ });+});diff --git a/src/components/ai-edition/chatAvailability.ts b/src/components/ai-edition/chatAvailability.tsnew file mode 100644index 000000000..b8e8d0e6f--- /dev/null+++ b/src/components/ai-edition/chatAvailability.ts@@ -0,0 +1,22 @@+// "Can the user actually send a chat message right now?"+//+// Both inputs come from the `aiEdition.llmGetSnapshot` IPC: the selected+// LLM config (may be null, or carry an empty-string provider after a+// disconnect) and the list of providers that currently have valid+// credentials. The chat composer is usable only when those two agree — a+// stale config that points at a provider with no credentials should look+// the same as "nothing set up yet" to the UI.+//+// Kept as a tiny pure function so the welcome-vs-composer gating in+// <LeftPanel /> can be tested in isolation.++import type { AiEditionLlmConfig } from "@/native/contracts";++export function canSendChat(+ llmConfig: AiEditionLlmConfig | null,+ connectedProviders: string[],+): boolean {+ if (llmConfig === null) return false;+ if (llmConfig.provider === "") return false;+ return connectedProviders.includes(llmConfig.provider);+}