"""显示输出""" import sys try: from colorama import Fore, Style, init init() except ImportError: class _D: CYAN = GREEN = YELLOW = RED = LIGHTBLACK_EX = RESET_ALL = '' Fore = Style = _D() class Display: def text(self, text, is_continue=False): if text: print(text) def thinking(self, text): if text: t = text[:500] + "..." if len(text) > 500 else text print(f"{Style.LIGHTBLACK_EX if hasattr(Style,'LIGHTBLACK_EX') else Fore.LIGHTBLACK_EX}[深度思考: {t}]{Style.RESET_ALL}") def tool_start(self, tc): args = tc.args[:80] + "..." if len(tc.args) > 80 else tc.args print(f" {Fore.GREEN}OK 工具:{Fore.RESET_ALL if hasattr(Fore,'RESET_ALL') else Style.RESET_ALL} {tc.name}") print(f" {Fore.CYAN}参数:{Style.RESET_ALL} {args}") def tool_result(self, tc, result): text = result.data if result.data is not None else result.error_message if text: s = str(text) if len(s) > 2000: lines = s.split("\n") if len(lines) > 30: s = "\n".join(lines[:30]) + f"\n... (共{len(lines)}行)" print(f" {Fore.CYAN}结果:{Style.RESET_ALL}") for line in s.split("\n"): print(f" {line}") def info(self, msg): print(f"{Fore.YELLOW}{msg}{Style.RESET_ALL}") def error(self, msg): print(f"{Fore.RED}{msg}{Style.RESET_ALL}")