release: v6.1.0 - TUI 体验全面升级 + 背景自定义
TUI 界面改进: - 全面中文化: CommandPalette/HelpPanel/Footer/Chatbox 边框标题等所有用户可见英文汉化 - 辅助中心 (Ctrl+P/F9): 原"设置"重命名, 含 6 项可切换设置 - 独立帮助浮层 (? 键): 重写帮助页面逻辑, 全中文, 带滑入淡入动画 - 背景切换: 辅助中心 [5] 预设背景, [6] 自定义背景; 新增 /bg 命令支持图片提取主色调 - 换行修复: Ctrl+J 作为主推换行键 (Windows 终端不区分 Shift+Enter) - 引擎切换修复: 解决 call_from_thread 在主线程崩溃的 RuntimeError 技术改进: - 文本工具调用解析: 检测模型用 <tool_call> 标签返回的工具调用 - 网络工具优化: network_tools.py 和 ai_search.py 改进请求头/重试/编码 - 流式输出修复: append_chunk 的 refresh 改为 layout=True - 取消响应修复: 引擎层 _cancelled 标志 + TUI 层 worker 身份跟踪 融合 v6.0.0 工作: - 保留 terminal 模拟器/operit 桥接/深度思考/工作模式/记忆模式等 v6.0.0 全部功能 - 在此基础上叠加本会话的 TUI 改进
This commit is contained in:
1 parent
b5f638cffc
commit
de15b54b19
30 files changed
+3267
-934
No files matched your search
+49
-48
@@ -1,60 +1,61 @@
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
from colorama import Fore, Style
|
||||
|
||||
|
||||
class HistoryMixin:
|
||||
"""聊天记录管理相关方法"""
|
||||
"""聊天记录管理 — 统一委托给 MemoryManager"""
|
||||
|
||||
def save_chat_history(self, name):
|
||||
"""保存当前聊天记录到文件"""
|
||||
try:
|
||||
chat_data = {
|
||||
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"conversation": self.shared_conversation_history.copy()
|
||||
}
|
||||
file_path = os.path.join(self.chat_history_dir, f"{name}.json")
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(chat_data, f, ensure_ascii=False, indent=2, default=str)
|
||||
print(f"{Fore.GREEN}聊天记录已保存为: {name}{Style.RESET_ALL}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"{Fore.RED}保存聊天记录失败: {e}{Style.RESET_ALL}")
|
||||
"""保存当前聊天记录"""
|
||||
if not hasattr(self, 'memory_manager') or not self.memory_manager:
|
||||
print(f"{Fore.RED}记忆系统未初始化{Style.RESET_ALL}")
|
||||
return False
|
||||
self.memory_manager.auto_save_chat(
|
||||
self.shared_conversation_history,
|
||||
label=name
|
||||
)
|
||||
print(f"{Fore.GREEN}聊天记录已保存: {name}{Style.RESET_ALL}")
|
||||
return True
|
||||
|
||||
def list_chat_history(self):
|
||||
"""列出所有已保存的聊天记录"""
|
||||
try:
|
||||
chat_files = [f for f in os.listdir(self.chat_history_dir) if f.endswith('.json')]
|
||||
if not chat_files:
|
||||
print(f"{Fore.YELLOW}没有已保存的聊天记录{Style.RESET_ALL}")
|
||||
return
|
||||
print(f"{Fore.GREEN}已保存的聊天记录:{Style.RESET_ALL}")
|
||||
for i, file in enumerate(chat_files, 1):
|
||||
file_path = os.path.join(self.chat_history_dir, file)
|
||||
mod_time = os.path.getmtime(file_path)
|
||||
mod_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(mod_time))
|
||||
chat_name = file[:-5]
|
||||
print(f"{Fore.GREEN}{i}. {chat_name} (保存时间: {mod_time_str}){Style.RESET_ALL}")
|
||||
except Exception as e:
|
||||
print(f"{Fore.RED}列出聊天记录失败: {e}{Style.RESET_ALL}")
|
||||
"""列出所有聊天记录"""
|
||||
if not hasattr(self, 'memory_manager') or not self.memory_manager:
|
||||
print(f"{Fore.RED}记忆系统未初始化{Style.RESET_ALL}")
|
||||
return
|
||||
chats = self.memory_manager.list_chats(limit=30)
|
||||
if not chats:
|
||||
print(f"{Fore.YELLOW}没有已保存的聊天记录{Style.RESET_ALL}")
|
||||
return
|
||||
print(f"{Fore.GREEN}已保存的聊天记录:{Style.RESET_ALL}")
|
||||
for i, c in enumerate(chats, 1):
|
||||
print(f"{Fore.GREEN}{i}. {c['name']} ({c['time']}, {c['size_kb']}KB){Style.RESET_ALL}")
|
||||
|
||||
def load_chat_history(self, name):
|
||||
"""加载指定的聊天记录"""
|
||||
try:
|
||||
file_path = os.path.join(self.chat_history_dir, f"{name}.json")
|
||||
if not os.path.exists(file_path):
|
||||
print(f"{Fore.RED}聊天记录 '{name}' 不存在{Style.RESET_ALL}")
|
||||
return False
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
chat_data = json.load(f)
|
||||
self.shared_conversation_history = chat_data.get("conversation", [])
|
||||
self._set_shared_conversation_history()
|
||||
print(f"{Fore.GREEN}已加载聊天记录: {name}{Style.RESET_ALL}")
|
||||
if self.shared_conversation_history:
|
||||
print(f"{Fore.CYAN}加载了 {len(self.shared_conversation_history)} 条对话记录{Style.RESET_ALL}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"{Fore.RED}加载聊天记录失败: {e}{Style.RESET_ALL}")
|
||||
"""加载聊天记录(支持序号或文件名)"""
|
||||
if not hasattr(self, 'memory_manager') or not self.memory_manager:
|
||||
print(f"{Fore.RED}记忆系统未初始化{Style.RESET_ALL}")
|
||||
return False
|
||||
|
||||
# 支持序号加载
|
||||
if name.isdigit():
|
||||
chats = self.memory_manager.list_chats(limit=50)
|
||||
idx = int(name) - 1
|
||||
if 0 <= idx < len(chats):
|
||||
name = chats[idx]['name'].replace('.json', '')
|
||||
else:
|
||||
print(f"{Fore.RED}序号 {name} 超出范围{Style.RESET_ALL}")
|
||||
return False
|
||||
|
||||
conversation = self.memory_manager.load_chat(name)
|
||||
if conversation is None:
|
||||
# 尝试加 .json 后缀
|
||||
if not name.endswith('.json'):
|
||||
conversation = self.memory_manager.load_chat(name + '.json')
|
||||
if conversation is None:
|
||||
print(f"{Fore.RED}聊天记录 '{name}' 不存在{Style.RESET_ALL}")
|
||||
return False
|
||||
|
||||
self.shared_conversation_history = conversation
|
||||
self._set_shared_conversation_history()
|
||||
print(f"{Fore.GREEN}已加载聊天记录: {name}{Style.RESET_ALL}")
|
||||
print(f"{Fore.CYAN}加载了 {len(conversation)} 条对话记录{Style.RESET_ALL}")
|
||||
return True
|
||||
Reference in new issue
Block a user