fix(cli): remove side-effect from agent:end state updater (#133) (#147)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
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:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user