From c8158ed74786ac1956dd499920fc4135d5c2241d Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Thu, 30 Jul 2026 09:54:46 +0700 Subject: [PATCH] Error message --- interfaces/tui/agent.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/interfaces/tui/agent.py b/interfaces/tui/agent.py index b52973d..c5ac602 100644 --- a/interfaces/tui/agent.py +++ b/interfaces/tui/agent.py @@ -130,6 +130,30 @@ def _agent_loop(app): if response.warning: log(app, "system", f" {response.warning}") + # Cek apakah response adalah error dari LLM client + content = response.content + is_error = isinstance(content, str) and (content.startswith("Error:") or content.startswith("HTTP Error:")) + + if is_error: + # Hapus "Thinking..." log dan placeholder + for i in range(len(app.log) - 1, -1, -1): + if app.log[i].get('role') == 'system' and 'Thinking' in app.log[i].get('text', ''): + app.log.pop(i) + break + if placeholder_marker is not None: + for i in range(len(app.log) - 1, -1, -1): + if app.log[i].get('role') == 'ai': + text = app.log[i].get('text', '') + if placeholder_marker in text or text == "" or text == "...": + app.log.pop(i) + break + log(app, "error", content) + _add_msg(app, "assistant", content) + log(app, "sep", "") + ntro.end(stamp) + app.agent_done.set() + return + # Cek apakah ada tool_calls has_tool_calls = bool(response.tool_calls)