fix(chat): do not delete the answer when regenerating without a selected model

regenerateResponse removed the previous answer before checking for a model and then returned silently, leaving the conversation without a reply. It now checks first and explains that a model is required, like sendMessage. The duplicated streaming code in sendMessage and regenerateResponse is now a single streamAnswer helper.
This commit is contained in:
evandro committed 2026-10-10 04:31:21 -03:00
1 parent b441339bb4
commit 1a3ce9ccec
3 files changed
+76 -106

No files matched your search

+19 -7
View File
@@ -177,22 +177,34 @@ describe('regenerateResponse', () => {
expect(state().isStreaming).toBe(true);
});
it('does nothing without a user message, while streaming, or without a model', async () => {
it('keeps the current answer and asks for a model when none is selected', async () => {
state().addMessage({ role: 'user', content: 'q' });
state().addMessage({ role: 'assistant', content: 'a' });
useAppStore.setState({ activeModelId: '' });
const { result } = renderHook(() => useLMStudio());
await act(async () => {
await result.current.regenerateResponse();
});
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
expect(state().messages.map((m) => m.content)).toEqual([
'q',
'a',
expect.stringContaining('No model selected'),
]);
});
it('does nothing without a user message or while streaming', async () => {
const { result, rerender } = renderHook(() => useLMStudio());
await act(async () => {
await result.current.regenerateResponse();
});
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
expect(state().messages).toEqual([]);
act(() => {
state().addMessage({ role: 'user', content: 'q' });
useAppStore.setState({ activeModelId: '' });
});
await act(async () => {
await result.current.regenerateResponse();
});
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
act(() => {
useAppStore.setState({ activeModelId: 'model-a', isStreaming: true });
});