refactor(chat): split ChatScreen and reuse regenerateResponse after editing a message

The edit path duplicated the streaming flow with inline require() calls; it now reuses regenerateResponse, which also fixes:
- edited conversations were never saved to History
- the answer generated after an edit could not be stopped (no abort handle kept)
Stopping a stream now saves the partial conversation, like finishing or failing does.
Adds characterization tests for ChatScreen and useLMStudio.
This commit is contained in:
evandro committed 2026-10-10 04:16:29 -03:00
1 parent 808cb1610b
commit cb6eda0562
8 files changed
+678 -176

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import type { ChatMessage } from '../store/useAppStore';
/** Id of the most recent assistant message, or null when there is none. */
export function findLastAssistantId(messages: ChatMessage[]): string | null {
for (let i = messages.length - 1; i >= 0; i--) {
if (messages[i].role === 'assistant') return messages[i].id;
}
return null;
}
/** True while the model has been asked to answer but has not produced any text yet. */
export function shouldShowTypingIndicator(messages: ChatMessage[], isStreaming: boolean): boolean {
if (!isStreaming) return false;
const last = messages[messages.length - 1];
return last?.role === 'assistant' && last.content === '';
}