fix: 修复 TUI 界面 API Key 配置和消息处理问题

1. 修复配置保存问题:config_section.py 现在正确发送 API 配置和工具限制两个消息
2. 修复代理环境变量问题:graph_client.py 自动修正缺少 scheme 前缀的代理 URL
3. 修复响应解析问题:app.py 正确从 data 字段获取 content 和 tool_calls
4. 添加操作日志更新:app.py 处理工具调用信息并更新操作日志

🤖 Generated with CodeArts Agent
This commit is contained in:
2026-04-14 23:46:21 +08:00
parent 8d15624b56
commit ddc84382fd
7 changed files with 38 additions and 326 deletions

View File

@ -128,6 +128,9 @@ class GraphMemoryApp(App):
async def _process(self, user_input: str) -> None:
from .widgets.message_history import MessageHistory
from .widgets.status_bar import StatusBar
from .widgets.right_panel import RightPanel
from .models.log_entry import LogEntry
from datetime import datetime
history = self.query_one(MessageHistory)
status_bar = self.query_one(StatusBar)
@ -138,8 +141,29 @@ class GraphMemoryApp(App):
)
if result.get("success"):
content = result.get("content", "(无回复)")
# 响应结构: {"success": True, "data": {"content": "...", "tool_calls": [...], ...}, "error": None}
data = result.get("data", {})
content = data.get("content", "(无回复)")
history.update_latest_message(content)
# 处理工具调用信息,更新操作日志
tool_calls = data.get("tool_calls", [])
if tool_calls:
try:
right_panel = self.query_one(RightPanel)
operation_log = right_panel.get_operation_log()
for tool_call in tool_calls:
entry = LogEntry(
timestamp=datetime.now(),
tool_name=tool_call.get("name", "unknown"),
arguments=tool_call.get("arguments", {}),
result=str(tool_call.get("result", "")),
duration=0.0 # 后端没有返回耗时信息
)
operation_log.add_log(entry)
except Exception:
pass # 忽略操作日志更新失败
else:
error = result.get("error", "未知错误")
history.update_latest_message(f"❌ 错误: {error}")

View File

@ -141,6 +141,9 @@ class ConfigSection(Vertical):
memory_update_max=int(memory_update.value or 10),
)
# 先发送 API 配置更新is_tool_limits=False
self.post_message(self.ConfigChanged(self._config, is_tool_limits=False))
# 再发送工具限制更新is_tool_limits=True
self.post_message(self.ConfigChanged(self._config, is_tool_limits=True))
except Exception:
pass