diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index 894dd25cf7..eb3776e603 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -2740,6 +2740,8 @@ class LlamaCppBackend: tool_msg["tool_call_id"] = tool_call_id conversation.append(tool_msg) + # Clear tool status badge before next generation iteration + yield {"type": "status", "text": ""} # Continue the loop to let model respond with context continue diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx index d688822815..aae027c74b 100644 --- a/studio/frontend/src/components/assistant-ui/thread.tsx +++ b/studio/frontend/src/components/assistant-ui/thread.tsx @@ -437,21 +437,40 @@ const CodeToolsToggle: FC = () => { const ToolStatusDisplay: FC = () => { const toolStatus = useChatRuntimeStore((s) => s.toolStatus); + const isThreadRunning = useAuiState(({ thread }) => thread.isRunning); const [elapsed, setElapsed] = useState(0); + const [visible, setVisible] = useState(false); useEffect(() => { if (!toolStatus) { setElapsed(0); + if (!isThreadRunning) { + setVisible(false); + } return; } + setElapsed(0); + + // Debounce badge visibility by 300ms when the badge is not + // already on screen. Once visible from a prior tool, consecutive + // tools show immediately so the badge does not flicker. Fast + // tool calls that all complete under 300ms never show the badge. + let showTimer: ReturnType | undefined; + if (!visible) { + showTimer = setTimeout(() => setVisible(true), 300); + } + const interval = setInterval(() => { setElapsed((prev) => prev + 1); }, 1000); - return () => clearInterval(interval); - }, [toolStatus]); + return () => { + clearInterval(interval); + if (showTimer) clearTimeout(showTimer); + }; + }, [toolStatus, isThreadRunning]); - if (!toolStatus) return null; + if (!toolStatus || !visible) return null; const isRunning = toolStatus.startsWith("Running"); const StatusIcon = isRunning ? TerminalIcon : GlobeIcon; return (