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.
17 lines
696 B
TypeScript
17 lines
696 B
TypeScript
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 === '';
|
|
}
|