fix(cli): remove side-effect from agent:end state updater (#133) (#147)
Some checks failed
ci/woodpecker/push/ci Pipeline failed

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #147.
This commit is contained in:
2026-03-15 19:09:13 +00:00
committed by jason.woltje
parent c4850fe6c1
commit 76abf11eba
4 changed files with 293 additions and 31 deletions

View File

@@ -52,6 +52,7 @@ export function TuiApp({
const [availableModels, setAvailableModels] = useState<ModelInfo[]>([]);
const socketRef = useRef<Socket | null>(null);
const currentStreamTextRef = useRef('');
// Fetch available models on mount
useEffect(() => {
@@ -102,20 +103,22 @@ export function TuiApp({
socket.on('agent:start', () => {
setIsStreaming(true);
currentStreamTextRef.current = '';
setCurrentStreamText('');
});
socket.on('agent:text', (data: { text: string }) => {
setCurrentStreamText((prev) => prev + data.text);
currentStreamTextRef.current += data.text;
setCurrentStreamText(currentStreamTextRef.current);
});
socket.on('agent:end', () => {
setCurrentStreamText((prev) => {
if (prev) {
setMessages((msgs) => [...msgs, { role: 'assistant', content: prev }]);
}
return '';
});
const finalText = currentStreamTextRef.current;
currentStreamTextRef.current = '';
setCurrentStreamText('');
if (finalText) {
setMessages((msgs) => [...msgs, { role: 'assistant', content: finalText }]);
}
setIsStreaming(false);
});