Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(chat): Senden und Stop gelten je Unterhaltung statt app-weit

purple01edd941855e
diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx
index 7f1e4046..fa616778 100644
--- a/src/components/chat/ChatInput.tsx
+++ b/src/components/chat/ChatInput.tsx
@@ -22,7 +22,15 @@ import { MONOGRAM, MONOGRAM_INVERT } from '../layout/brand'
interface Props {
onSend: (content: string, images?: ImageAttachment[]) => void
onStop: () => void
+ /** THIS conversation is answering: the slot shows Stop. */
isGenerating: boolean
+ /**
+ * Another conversation is answering. The slot used to read one app-wide
+ * flag, so every other chat silently lost its Send button and grew a Stop
+ * that killed the foreign run (T1 nebenfund 4). Send stays where it is now
+ * and the composer says in one line why it is waiting.
+ */
+ busyElsewhere?: boolean
pendingApproval?: AgentToolCall | null
onApprove?: () => void
onReject?: () => void
@@ -90,7 +98,7 @@ function fileToImageAttachment(file: File): Promise<ImageAttachment> {
})
}
-export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApprove, onReject, disabled, slashCommands, onAttachDocs, composerModel, composerActions, composerAbove }: Props) {
+export function ChatInput({ onSend, onStop, isGenerating, busyElsewhere, pendingApproval, onApprove, onReject, disabled, slashCommands, onAttachDocs, composerModel, composerActions, composerAbove }: Props) {
const [input, setInput] = useState('')
const [images, setImages] = useState<ImageAttachment[]>([])
const [isDragOver, setIsDragOver] = useState(false)
@@ -269,7 +277,7 @@ export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApp
const sendLockRef = useRef(0)
const handleSend = () => {
const trimmed = input.trim()
- if ((!trimmed && images.length === 0) || isGenerating || disabled) return
+ if ((!trimmed && images.length === 0) || isGenerating || busyElsewhere || disabled) return
if (!passSendLock(sendLockRef)) return
onSend(trimmed || '(image)', images.length > 0 ? images : undefined)
setInput('')
@@ -433,6 +441,19 @@ export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApp
{/* Prompt area: hints, image previews, then the textarea (buttons live
in the action bar below, web-parity two-row composer). */}
<div className="px-3 pt-2.5">
+ {/* Another chat is answering. Saying so beats what this composer did
+ before, which was to drop the Send button without a word and put a
+ Stop button there that aborted the OTHER chat's run. One answer at
+ a time is what the app really does today: the local engine runs a
+ single slot, and the streaming buffers behind the composer are
+ shared. Whoever lifts that lifts this line with it. */}
+ {busyElsewhere && (
+ <div role="status" className={`${HINWEIS_ZEILE} ${HINWEIS_TEXT.ruhig} mb-1.5 px-1`} data-testid="composer-busy-elsewhere">
+ <span className="flex-1 min-w-0">
+ Another chat is still answering. This app runs one answer at a time, so wait for it to finish or stop it in that chat.
+ </span>
+ </div>
+ )}
{/* Non-image attach hint (GH #69). The clip is images-only; PDFs, Word,
and text files go through the Documents panel so the model can read them. */}
{docHint && (
@@ -676,7 +697,7 @@ export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApp
) : (
<button
onClick={handleSend}
- disabled={(!input.trim() && images.length === 0) || isTranscribing}
+ disabled={(!input.trim() && images.length === 0) || isTranscribing || !!busyElsewhere}
className="lu-control lu-control--icon lu-primary w-full h-full"
aria-label="Send message"
>
diff --git a/src/components/chat/ChatView.tsx b/src/components/chat/ChatView.tsx
index 0d9105ef..b3ec9697 100644
--- a/src/components/chat/ChatView.tsx
+++ b/src/components/chat/ChatView.tsx
@@ -41,6 +41,7 @@ import { PermissionOverrideBar } from './PermissionOverrideBar'
import { CodexView } from './CodexView'
import { useCodexStore } from '../../stores/codexStore'
import { useGenerationStore } from '../../stores/generationStore'
+import { composerBusy } from '../../lib/composer-busy'
import { useRemoteStore } from '../../stores/remoteStore'
import { displayModelName } from '../../api/providers'
import { MONOGRAM, MONOGRAM_INVERT } from '../layout/brand'
@@ -113,11 +114,15 @@ export function ChatView() {
// Per-conversation generating flag (David 2026-06-12): the typing indicator
// + realtime counter must show ONLY in the chat that is actually generating,
- // not in every other chat the user switches to. `isGenerating` from the hook
- // is global (and stays so for the input, where it guards shared stream refs);
- // the visual indicators below read this conversation-scoped map instead.
+ // not in every other chat the user switches to.
+ //
+ // Since T1 point 4 the COMPOSER reads it too. It used to read the hook's
+ // app-wide `isGenerating`, so every other conversation lost its Send button
+ // and got a Stop button that aborted the foreign run. `composerBusy` splits
+ // the one flag into the two questions the composer actually has.
const generatingMap = useGenerationStore((s) => s.generating)
const activeGenerating = !!activeConversationId && !!generatingMap[activeConversationId]
+ const busy = composerBusy(isGenerating, generatingMap, activeConversationId)
const docCount = useRAGStore((s) =>
activeConversationId ? (s.documents[activeConversationId] || []).length : 0
@@ -625,7 +630,8 @@ export function ChatView() {
<ChatInput
onSend={sendMessage}
onStop={stopGeneration}
- isGenerating={isGenerating}
+ isGenerating={busy.thisChat}
+ busyElsewhere={busy.otherChat}
pendingApproval={pendingApproval}
onApprove={approveToolCall}
onReject={rejectToolCall}
diff --git a/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx b/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
new file mode 100644
index 00000000..5de75f6f
--- /dev/null
+++ b/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
@@ -0,0 +1,146 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * Senden und Stop gehoeren der Unterhaltung, nicht der App.
+ *
+ * Befund T1 (Box, 11.09.2026), Punkt 4 und Nebenfund 4: "Der Sendeknopf
+ * verschwindet global, solange irgendwo eine Antwort laeuft. In jedem anderen
+ * Chat steht dort der Stopp-Knopf, der die fremde Erzeugung abbricht." Der
+ * Komposer las eine einzige app-weite Fahne (`useChat().isGenerating`),
+ * obwohl der generationStore die Wahrheit seit 22f76b04 je Unterhaltung
+ * fuehrt und die Schreibanzeige sie auch schon las.
+ *
+ * Warum hier nur die halbe Strecke steht: ein vollstaendiges "jede
+ * Unterhaltung darf gleichzeitig senden" haengt an den geteilten
+ * Stream-Puffern in useChat.ts (contentRef, thinkingRef, abortRef) und
+ * useAgentChat.ts, rund 110 Zugriffe, und daran, dass `runInLane` aus
+ * lib/run-slot.ts bis heute keinen Aufrufer in der Produktion hat: ohne
+ * Warteschlange liefen zwei lokale Laeufe gegen einen llama-server mit einem
+ * einzigen Slot. Das ist mehr als eine Stunde Arbeit und gehoert in einen
+ * eigenen Auftrag. Was hier steht, ist das, was ohne diese Entflechtung
+ * richtig wird: der laufende Chat behaelt Stop und bricht nur sich selbst ab,
+ * der andere behaelt seinen Sendeknopf und bekommt einen englischen Satz
+ * statt eines stummen Tauschs.
+ *
+ * Run: npx vitest run src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
+import { dirname, resolve } from 'node:path'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { ChatInput } from '../ChatInput'
+import { composerBusy } from '../../../lib/composer-busy'
+
+const src = (rel: string) =>
+ readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), rel), 'utf8')
+
+const sendButton = () => screen.queryByRole('button', { name: 'Send message' }) as HTMLButtonElement | null
+const stopButton = () => screen.queryByRole('button', { name: 'Stop generation' })
+
+beforeEach(() => cleanup())
+
+describe('the composer of a chat that is NOT the one answering', () => {
+ /** What ChatView hands down while conversation `b` is the one generating. */
+ const asSeenFromA = composerBusy(true, { b: true }, 'a')
+
+ it('keeps its Send button instead of losing it to a foreign run', () => {
+ render(
+ <ChatInput
+ onSend={() => {}}
+ onStop={() => { throw new Error('a foreign run must not be stoppable from here') }}
+ isGenerating={asSeenFromA.thisChat}
+ busyElsewhere={asSeenFromA.otherChat}
+ />,
+ )
+ expect(sendButton()).toBeTruthy()
+ expect(stopButton()).toBeNull()
+ })
+
+ it('says in English why it is waiting, instead of going quiet', () => {
+ render(
+ <ChatInput onSend={() => {}} onStop={() => {}} isGenerating={asSeenFromA.thisChat} busyElsewhere={asSeenFromA.otherChat} />,
+ )
+ const line = screen.getByTestId('composer-busy-elsewhere')
+ expect(line.textContent).toContain('Another chat is still answering')
+ expect(line.textContent).toContain('one answer at a time')
+ // It has to tell the user what to do next, not just that something is off.
+ expect(line.textContent).toMatch(/wait for it to finish or stop it in that chat/)
+ expect(line.getAttribute('role')).toBe('status')
+ })
+
+ it('does not fire a send while another chat holds the engine', () => {
+ let sent = 0
+ render(
+ <ChatInput onSend={() => { sent += 1 }} onStop={() => {}} isGenerating={asSeenFromA.thisChat} busyElsewhere={asSeenFromA.otherChat} />,
+ )
+ const box = screen.getByRole('textbox')
+ fireEvent.change(box, { target: { value: 'hello' } })
+ expect(sendButton()!.disabled).toBe(true)
+ fireEvent.keyDown(box, { key: 'Enter' })
+ expect(sent).toBe(0)
+ })
+})
+
+describe('the composer of the chat that IS answering', () => {
+ const asSeenFromB = composerBusy(true, { b: true }, 'b')
+
+ it('shows Stop, and no waiting line', () => {
+ let stopped = 0
+ render(
+ <ChatInput onSend={() => {}} onStop={() => { stopped += 1 }} isGenerating={asSeenFromB.thisChat} busyElsewhere={asSeenFromB.otherChat} />,
+ )
+ expect(sendButton()).toBeNull()
+ expect(screen.queryByTestId('composer-busy-elsewhere')).toBeNull()
+ fireEvent.click(stopButton()!)
+ expect(stopped).toBe(1)
+ })
+
+ it('COUNTER-CHECK: an idle chat shows Send and says nothing', () => {
+ const idle = composerBusy(false, {}, 'b')
+ render(<ChatInput onSend={() => {}} onStop={() => {}} isGenerating={idle.thisChat} busyElsewhere={idle.otherChat} />)
+ expect(sendButton()).toBeTruthy()
+ expect(sendButton()!.disabled).toBe(true) // empty box, not a busy engine
+ expect(screen.queryByTestId('composer-busy-elsewhere')).toBeNull()
+ })
+})
+
+/**
+ * Die zweite Haelfte des Befunds sitzt in zwei Hooks, deren Abbruchgriffe der
+ * Hook-INSTANZ gehoeren und nicht der Unterhaltung. Ein echter Lauf mit zwei
+ * gleichzeitigen Unterhaltungen ist von hier aus nicht zu fahren, deshalb
+ * steht hier der Quelltext-Waechter auf die Bedingung. Nachgemessen werden
+ * muss das an der laufenden App (siehe Bericht).
+ */
+describe('Stop bricht nur die eigene Erzeugung ab', () => {
+ it('useChat abortet den Controller der Instanz nur fuer die eigene Unterhaltung', () => {
+ const chat = src('../../../hooks/useChat.ts')
+ expect(chat).toMatch(/const abortConvRef = useRef<string \| null>\(null\)/)
+ expect(chat).toMatch(/if \(abortConvRef\.current === convId\) \{\s*\n\s*abortRef\.current\?\.abort\(\)/)
+ // Und der Ref wird auch wirklich gesetzt, sonst bricht Stop nie etwas ab.
+ expect(chat.match(/abortConvRef\.current = convId/g)?.length).toBe(2)
+ })
+
+ it('useAgentChat beendet den Agentenlauf nur fuer die eigene Unterhaltung', () => {
+ const agent = src('../../../hooks/useAgentChat.ts')
+ expect(agent).toMatch(/if \(abortConvRef\.current === stoppedConvId\) \{/)
+ expect(agent).toMatch(/abortConvRef\.current = convId/)
+ // setIsAgentRunning(false) darf NICHT mehr unbedingt am Ende stehen: das
+ // war die Zeile, die den fremden Lauf aus der Oberflaeche loeschte.
+ expect(agent).not.toMatch(/drainApprovals\(stoppedConvId\)\s*\n\s*setIsAgentRunning\(false\)/)
+ })
+
+ it('der Komposer liest nicht mehr die app-weite Fahne', () => {
+ const view = src('../ChatView.tsx')
+ const composer = view.slice(view.indexOf('<ChatInput'), view.indexOf('composerActions='))
+ expect(composer).toContain('isGenerating={busy.thisChat}')
+ expect(composer).toContain('busyElsewhere={busy.otherChat}')
+ expect(composer).not.toContain('isGenerating={isGenerating}')
+ // Die MessageList behaelt die app-weite Fahne mit Absicht: Regenerate und
+ // Edit STARTEN einen Lauf, und solange die Stream-Puffer geteilt sind,
+ // darf ein zweiter Lauf nirgends anfangen. Genau deshalb sagt der
+ // Komposer den Grund, statt den Knopf wegzunehmen.
+ expect(view).toContain('isGenerating={isGenerating}')
+ expect(view).toContain('isThisChatGenerating={activeGenerating}')
+ })
+})
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index a8914e6d..d5af3ce6 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -123,6 +123,13 @@ export function useAgentChat() {
const [pendingApproval, setPendingApproval] = useState<AgentToolCall | null>(null)
const abortRef = useRef<AbortController | null>(null)
+ /**
+ * Welche Unterhaltung der Lauf oben gehoert. Siehe useChat.ts: `abortRef`,
+ * `runningRef` und `isAgentRunning` gibt es einmal je Hook-Instanz, nicht je
+ * Unterhaltung, und Stop nahm sie unbesehen. Damit brach Stop in einer
+ * zweiten Unterhaltung den Agentenlauf der ersten ab (T1 Punkt 4).
+ */
+ const abortConvRef = useRef<string | null>(null)
// "The user pressed stop" lives in lib/run-stop, keyed by conversation, NOT
// in a ref of this hook instance — for the same reason agentLoopTimer above
// is module scope. It was also never RESET: one stop anywhere in the session
@@ -699,6 +706,7 @@ export function useAgentChat() {
// Setup
const abort = new AbortController()
abortRef.current = abort
+ abortConvRef.current = convId
// Hand Stop to everything this run starts, including the nested ReAct loop
// a delegate_task sub-agent runs (audit AGT-1). Assigned here rather than
// in beginAgentRun because the controller does not exist that early.
@@ -2480,6 +2488,7 @@ export function useAgentChat() {
useGenerationStore.getState().clearAborter(convId)
runningRef.current = false
abortRef.current = null
+ abortConvRef.current = null
// Chat-tools artifact mode: attach any files the model "wrote" (captured
// in-memory, NOT on disk) to the assistant message so they render inline
// with a preview + Download button. takeChatArtifacts drains this run's
@@ -2606,15 +2615,23 @@ export function useAgentChat() {
agentLoopTimer = null
}
useAgentLoopStore.getState().clear()
- runningRef.current = false
- abortRef.current?.abort()
- abortRef.current = null
+ // NUR den eigenen Lauf. `runningRef`, `abortRef` und `isAgentRunning`
+ // gehoeren der Hook-Instanz, nicht der Unterhaltung; ohne diese Bedingung
+ // beendete Stop in einer zweiten Unterhaltung den Agentenlauf der ersten
+ // (T1 Punkt 4). Laeuft der Agent woanders, hat `stopRun` oben den Stopp
+ // fuer DIESE Unterhaltung vermerkt und mehr ist hier nicht zu tun.
+ if (abortConvRef.current === stoppedConvId) {
+ runningRef.current = false
+ abortRef.current?.abort()
+ abortRef.current = null
+ abortConvRef.current = null
+ setIsAgentRunning(false)
+ }
// Interrupt any in-flight ComfyUI gen too — the main Stop button only aborted
// the agent loop before, so a running image/video kept burning unless the user
// happened to click the small in-chat tool Stop. Now both Stops agree.
requestGenerationCancel()
drainApprovals(stoppedConvId)
- setIsAgentRunning(false)
}, [])
return {
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index 303bea7a..4457cddb 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -278,6 +278,16 @@ export function useChat() {
const [isGenerating, setIsGenerating] = useState(false)
const [isLoadingModel, setIsLoadingModel] = useState(false)
const abortRef = useRef<AbortController | null>(null)
+ /**
+ * Welche Unterhaltung der Controller oben gehoert.
+ *
+ * `abortRef` ist EINER je Hook-Instanz, nicht je Unterhaltung. Stop nahm ihn
+ * bisher unbesehen und brach damit die Erzeugung der anderen Unterhaltung ab
+ * (T1 Punkt 4, auf der Box gemessen). Der Griff je Unterhaltung liegt im
+ * generationStore und macht die Arbeit; dieser Ref sagt nur noch, ob der
+ * Griff dieser Instanz ueberhaupt zur genannten Unterhaltung gehoert.
+ */
+ const abortConvRef = useRef<string | null>(null)
const contentRef = useRef("")
const thinkingRef = useRef("")
const isThinkingRef = useRef(false)
@@ -332,6 +342,7 @@ export function useChat() {
const abort = new AbortController()
abortRef.current = abort
+ abortConvRef.current = convId
useGenerationStore.getState().registerAborter(convId, () => abort.abort())
setIsGenerating(true)
useGenerationStore.getState().setGenerating(convId, true)
@@ -343,6 +354,7 @@ export function useChat() {
} finally {
useGenerationStore.getState().clearAborter(convId)
abortRef.current = null
+ abortConvRef.current = null
// The round is over, so it goes on disk BEFORE the app says so. Same
// contract as the single-model turn below and as the Agent and Coding
// runs — see stores/durability.ts for the measurement that made the
@@ -761,6 +773,7 @@ export function useChat() {
const abort = new AbortController()
abortRef.current = abort
+ abortConvRef.current = convId
// Register so deleting/closing this chat aborts the in-flight stream (Bug C).
// Also requestGenerationCancel so a running ComfyUI job is interrupted when
// the chat goes away mid-generation (the _activeHandoffs gate makes it a
@@ -1149,6 +1162,7 @@ export function useChat() {
setIsLoadingModel(false)
useModelStore.getState().setIsModelLoading(false)
abortRef.current = null
+ abortConvRef.current = null
// The turn is done, so it goes on disk — and only then does the app say
// it is done. Persistence is coalesced while tokens stream (2.6.3 — see
@@ -1228,9 +1242,17 @@ export function useChat() {
* - `abortRef` der einfache Chat-Stream dieser Instanz.
*/
const stopGeneration = useCallback(() => {
+ const convId = useChatStore.getState().activeConversationId
stopAgent()
- useGenerationStore.getState().abortConversation(useChatStore.getState().activeConversationId)
- abortRef.current?.abort()
+ useGenerationStore.getState().abortConversation(convId)
+ // NUR wenn der Controller dieser Instanz auch zu DIESER Unterhaltung
+ // gehoert. Ohne die Bedingung brach Stop in Unterhaltung B die Erzeugung
+ // in A ab, weil `abortRef` den zuletzt gestarteten Lauf haelt, egal wo
+ // (T1 Punkt 4). Gehoert er woanders hin, hat `abortConversation` oben
+ // schon den richtigen Griff gezogen.
+ if (abortConvRef.current === convId) {
+ abortRef.current?.abort()
+ }
// Also interrupt an in-flight ComfyUI image/video gen, not just the JS loop —
// otherwise the main Stop button leaves ComfyUI burning (only the in-chat
// tool Stop did this before; now both affordances agree).
diff --git a/src/lib/__tests__/composer-busy.test.ts b/src/lib/__tests__/composer-busy.test.ts
new file mode 100644
index 00000000..007770bf
--- /dev/null
+++ b/src/lib/__tests__/composer-busy.test.ts
@@ -0,0 +1,47 @@
+/**
+ * Senden und Stop gelten je Unterhaltung.
+ *
+ * Befund T1 (Box, 11.09.2026), Punkt 4 und Nebenfund 4: solange irgendwo eine
+ * Antwort lief, verschwand der Sendeknopf in JEDER Unterhaltung, und der
+ * Stop-Knopf in der zweiten brach die Erzeugung der ersten ab. Der Komposer
+ * las eine einzige app-weite Fahne. Diese Datei nagelt die Aufteilung fest.
+ *
+ * Run: npx vitest run src/lib/__tests__/composer-busy.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { composerBusy } from '../composer-busy'
+
+describe('composerBusy', () => {
+ it('gives Stop to the chat that is answering and leaves the other one Send', () => {
+ const map = { a: true }
+ expect(composerBusy(true, map, 'a')).toEqual({ thisChat: true, otherChat: false })
+ expect(composerBusy(true, map, 'b')).toEqual({ thisChat: false, otherChat: true })
+ })
+
+ it('says nothing at all while nothing runs', () => {
+ expect(composerBusy(false, {}, 'a')).toEqual({ thisChat: false, otherChat: false })
+ expect(composerBusy(false, { a: false }, 'a')).toEqual({ thisChat: false, otherChat: false })
+ })
+
+ it('keeps Stop on a run the map does not know about, rather than losing it', () => {
+ // An orphaned run picked up after a reload, or the window between starting
+ // a stream and registering it: the hook knows, the map does not yet. The
+ // chat on screen keeps Stop, because a run nobody can stop is worse than a
+ // Stop button one click too early.
+ expect(composerBusy(true, {}, 'a')).toEqual({ thisChat: true, otherChat: false })
+ })
+
+ it('does not hand the chat on screen a Stop for a run that is somewhere else', () => {
+ // The counter-case to the one above, and the whole point of the split.
+ expect(composerBusy(true, { b: true }, 'a').thisChat).toBe(false)
+ })
+
+ it('lets a chat that is answering itself stay Stop while another one also runs', () => {
+ expect(composerBusy(true, { a: true, b: true }, 'a')).toEqual({ thisChat: true, otherChat: false })
+ })
+
+ it('survives a chat list with no conversation open', () => {
+ expect(composerBusy(true, { b: true }, null)).toEqual({ thisChat: false, otherChat: true })
+ expect(composerBusy(false, {}, null)).toEqual({ thisChat: false, otherChat: false })
+ })
+})
diff --git a/src/lib/composer-busy.ts b/src/lib/composer-busy.ts
new file mode 100644
index 00000000..fc4af577
--- /dev/null
+++ b/src/lib/composer-busy.ts
@@ -0,0 +1,37 @@
+/**
+ * Who is busy: this chat, or another one.
+ *
+ * The composer used to read ONE boolean, `useChat().isGenerating`, which is
+ * true while anything anywhere is answering. So every other conversation lost
+ * its Send button and grew a Stop button that aborted the foreign run
+ * (measured on the box, T1 nebenfund 4 and T1 point 4). The per-conversation
+ * truth already existed in `generationStore.generating`; only the composer
+ * never asked it.
+ *
+ * `hookGenerating` stays in the answer on purpose. It is wider than the map:
+ * it also covers a run this app instance did not register, an orphaned run
+ * picked up after a reload, and the window between starting a stream and
+ * registering it. When it is true and no OTHER conversation owns a run, the
+ * run belongs to the chat on screen, and that chat keeps its Stop button. The
+ * rule never turns a Stop into a bare Send, so nothing becomes unstoppable.
+ */
+export interface ComposerBusy {
+ /** The conversation on screen is answering: it shows Stop. */
+ thisChat: boolean
+ /** Some OTHER conversation is answering: this one says so instead of going quiet. */
+ otherChat: boolean
+}
+
+export function composerBusy(
+ hookGenerating: boolean,
+ generatingMap: Record<string, boolean>,
+ activeConversationId: string | null,
+): ComposerBusy {
+ const otherChat = Object.entries(generatingMap)
+ .some(([id, on]) => on && id !== activeConversationId)
+ const own = !!activeConversationId && !!generatingMap[activeConversationId]
+ return {
+ thisChat: own || (hookGenerating && !otherChat),
+ otherChat: otherChat && !own,
+ }
+}