diff --git a/README.md b/README.md index de5b2e28..e7d45287 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ ## 🔥 更新和安装 -**最新版本: v0.11.5** ([更新日志](changelogs/changelog.md)) +**最新版本: v0.11.6** ([更新日志](changelogs/changelog.md)) 可前往 [Release](https://github.com/MaiM-with-u/MaiBot/releases/) 页面下载最新版本 @@ -71,16 +71,21 @@ **技术交流群:** [麦麦脑电图](https://qm.qq.com/q/RzmCiRtHEW) | - [麦麦脑磁图](https://qm.qq.com/q/wlH5eT8OmQ) | [麦麦大脑磁共振](https://qm.qq.com/q/VQ3XZrWgMs) | - [麦麦要当VTB](https://qm.qq.com/q/wGePTl1UyY) + [麦麦要当VTB](https://qm.qq.com/q/wGePTl1UyY) | + + 为了维持技术交流和互帮互助的氛围,请不要在技术交流群讨论过多无关内容~ **聊天吹水群:** - [麦麦之闲聊群](https://qm.qq.com/q/JxvHZnxyec) + 麦麦相关闲聊群 + **插件开发/测试版讨论群:** - [插件开发群](https://qm.qq.com/q/1036092828) + 进阶内容,包括插件开发,测试版使用等等 + ## 📚 文档 **部分内容可能更新不够及时,请注意版本对应** diff --git a/changelogs/changelog.md b/changelogs/changelog.md index 5f2c733f..c12e726b 100644 --- a/changelogs/changelog.md +++ b/changelogs/changelog.md @@ -1,17 +1,52 @@ # Changelog -## [0.11.5] - 2025-11-26 -### 主要功能更改 - - +## [0.11.6] - 2025-12-2 +### 🌟 重大更新 +- 大幅提高记忆检索能力,略微提高token消耗 +- 重构历史消息概括器,更好的主题记忆 +- 日志查看器性能革命性优化 +- 支持可视化查看麦麦LPMM知识图谱 +- 支持根据不同的模型提供商/模板/URL自动获取模型,可以不用手动输入模型了 +- 新增Baka引导系统,使用React-JoyTour实现很棒的用户引导系统(让Baka也能看懂!) +- 本地聊天室功能!!你可以直接在WebUI网页和麦麦聊天!! +- 使用cookie模式替换原有的LocalStorage Token存储,可能需要重新手动输入一遍Token +- WebUI本地聊天室支持用户模拟和平台模拟的功能! +- WebUI新增黑话管理 & 编辑界面 ### 细节功能更改 +- 可选记忆识别中是否启用jargon - 解耦表情包识别和图片识别 - 修复部分破损json的解析问题 - 黑话更高的提取效率,增加提取准确性 - 升级jargon,更快更精准 - 新增Lpmm可视化 +### webui细节更新 +- 修复侧边栏收起、UI及表格横向滚动等问题,优化Toast动画 +- 修复适配器配置、插件克隆、表情包注册等相关BUG +- 新增适配器/模型预设模式及模板,自动填写URL和类型 +- 支持模型任务列表拖拽排序 +- 更新重启弹窗和首次引导内容 +- 多处界面命名及标题优化,如模型配置相关菜单重命名和描述更新 +- 修复聊天配置“提及回复”相关开关命名错误 +- 调试配置新增“显示记忆/Planner/LPMM Prompt”选项 +- 新增卡片尺寸、排序、字号、行间距等个性化功能 +- 聊天ID及群聊选择优化,显示可读名称 +- 聊天编辑界面精简字段,新增后端聊天列表API支持 +- 默认行间距减小,显示更紧凑 +- 修复页面滚动、表情包排序、发言频率为0等问题 +- 新增React异常Traceback界面及模型列表搜索 +- 更新WebUI Icon,修复适配器docker路径等问题 +- 插件配置可视化编辑,表单控件/元数据/布局类型扩展 +- 新增插件API与开发文档 +- 新增机器人状态卡片和快速操作按钮 +- 调整饼图显示、颜色算法,修复部分统计及解析错误 +- 新增缓存、WebSocket配置 +- 表情包支持上传和缩略图 +- 修复首页极端加载、重启后CtrlC失效、主程序配置移动端适配等问题 +- 新增表达反思设置和WebUI聊天室“思考中”占位组件 +- 细节如移除部分字段或UI控件、优化按钮/弹窗/编辑逻辑等 + ## [0.11.5] - 2025-11-21 ### 🌟 重大更新 - WebUI 现支持手动重启麦麦,曲线救国版“热重载” diff --git a/src/chat/frequency_control/frequency_control.py b/src/chat/frequency_control/frequency_control.py index 78041ae7..897a92cc 100644 --- a/src/chat/frequency_control/frequency_control.py +++ b/src/chat/frequency_control/frequency_control.py @@ -1,5 +1,6 @@ from datetime import datetime import time +import asyncio from typing import Dict from src.chat.utils.chat_message_builder import ( @@ -46,6 +47,8 @@ class FrequencyControl: self.frequency_model = LLMRequest( model_set=model_config.model_task_config.utils_small, request_type="frequency.adjust" ) + # 频率调整锁,防止并发执行 + self._adjust_lock = asyncio.Lock() def get_talk_frequency_adjust(self) -> float: """获取发言频率调整值""" @@ -56,68 +59,78 @@ class FrequencyControl: self.talk_frequency_adjust = max(0.1, min(5.0, value)) async def trigger_frequency_adjust(self) -> None: - msg_list = get_raw_msg_by_timestamp_with_chat( - chat_id=self.chat_id, - timestamp_start=self.last_frequency_adjust_time, - timestamp_end=time.time(), - ) - - if time.time() - self.last_frequency_adjust_time < 160 or len(msg_list) <= 20: - return - else: - new_msg_list = get_raw_msg_by_timestamp_with_chat( + # 使用异步锁防止并发执行 + async with self._adjust_lock: + # 在锁内检查,避免并发触发 + current_time = time.time() + previous_adjust_time = self.last_frequency_adjust_time + + msg_list = get_raw_msg_by_timestamp_with_chat( chat_id=self.chat_id, - timestamp_start=self.last_frequency_adjust_time, - timestamp_end=time.time(), - limit=20, - limit_mode="latest", + timestamp_start=previous_adjust_time, + timestamp_end=current_time, ) - message_str = build_readable_messages( - new_msg_list, - replace_bot_name=True, - timestamp_mode="relative", - read_mark=0.0, - show_actions=False, - ) - time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" - bot_name = global_config.bot.nickname - bot_nickname = ( - f",也有人叫你{','.join(global_config.bot.alias_names)}" if global_config.bot.alias_names else "" - ) - name_block = f"你的名字是{bot_name}{bot_nickname},请注意哪些是你自己的发言。" + if current_time - previous_adjust_time < 160 or len(msg_list) <= 20: + return - prompt = await global_prompt_manager.format_prompt( - "frequency_adjust_prompt", - name_block=name_block, - time_block=time_block, - message_str=message_str, - ) - response, (reasoning_content, _, _) = await self.frequency_model.generate_response_async( - prompt, - ) + # 立即更新调整时间,防止并发触发 + self.last_frequency_adjust_time = current_time - # logger.info(f"频率调整 prompt: {prompt}") - # logger.info(f"频率调整 response: {response}") + try: + new_msg_list = get_raw_msg_by_timestamp_with_chat( + chat_id=self.chat_id, + timestamp_start=previous_adjust_time, + timestamp_end=current_time, + limit=20, + limit_mode="latest", + ) - if global_config.debug.show_prompt: - logger.info(f"频率调整 prompt: {prompt}") - logger.info(f"频率调整 response: {response}") - logger.info(f"频率调整 reasoning_content: {reasoning_content}") + message_str = build_readable_messages( + new_msg_list, + replace_bot_name=True, + timestamp_mode="relative", + read_mark=0.0, + show_actions=False, + ) + time_block = f"当前时间:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" + bot_name = global_config.bot.nickname + bot_nickname = ( + f",也有人叫你{','.join(global_config.bot.alias_names)}" if global_config.bot.alias_names else "" + ) + name_block = f"你的名字是{bot_name}{bot_nickname},请注意哪些是你自己的发言。" - final_value_by_api = frequency_api.get_current_talk_value(self.chat_id) + prompt = await global_prompt_manager.format_prompt( + "frequency_adjust_prompt", + name_block=name_block, + time_block=time_block, + message_str=message_str, + ) + response, (reasoning_content, _, _) = await self.frequency_model.generate_response_async( + prompt, + ) - # LLM依然输出过多内容时取消本次调整。合法最多4个字,但有的模型可能会输出一些markdown换行符等,需要长度宽限 - if len(response) < 20: - if "过于频繁" in response: - logger.info(f"频率调整: 过于频繁,调整值到{final_value_by_api}") - self.talk_frequency_adjust = max(0.1, min(1.5, self.talk_frequency_adjust * 0.8)) - elif "过少" in response: - logger.info(f"频率调整: 过少,调整值到{final_value_by_api}") - self.talk_frequency_adjust = max(0.1, min(1.5, self.talk_frequency_adjust * 1.2)) - self.last_frequency_adjust_time = time.time() - else: - logger.info("频率调整:response不符合要求,取消本次调整") + # logger.info(f"频率调整 prompt: {prompt}") + # logger.info(f"频率调整 response: {response}") + + if global_config.debug.show_prompt: + logger.info(f"频率调整 prompt: {prompt}") + logger.info(f"频率调整 response: {response}") + logger.info(f"频率调整 reasoning_content: {reasoning_content}") + + final_value_by_api = frequency_api.get_current_talk_value(self.chat_id) + + # LLM依然输出过多内容时取消本次调整。合法最多4个字,但有的模型可能会输出一些markdown换行符等,需要长度宽限 + if len(response) < 20: + if "过于频繁" in response: + logger.info(f"频率调整: 过于频繁,调整值到{final_value_by_api}") + self.talk_frequency_adjust = max(0.1, min(1.5, self.talk_frequency_adjust * 0.8)) + elif "过少" in response: + logger.info(f"频率调整: 过少,调整值到{final_value_by_api}") + self.talk_frequency_adjust = max(0.1, min(1.5, self.talk_frequency_adjust * 1.2)) + except Exception as e: + logger.error(f"频率调整失败: {e}") + # 即使失败也保持时间戳更新,避免频繁重试 class FrequencyControlManager: diff --git a/src/express/expression_learner.py b/src/express/expression_learner.py index 76cc8408..af69cad6 100644 --- a/src/express/expression_learner.py +++ b/src/express/expression_learner.py @@ -2,6 +2,7 @@ import time import json import os import re +import asyncio from typing import List, Optional, Tuple import traceback from src.common.logger import get_logger @@ -91,6 +92,9 @@ class ExpressionLearner: # 维护每个chat的上次学习时间 self.last_learning_time: float = time.time() + # 学习锁,防止并发执行学习任务 + self._learning_lock = asyncio.Lock() + # 学习参数 _, self.enable_learning, self.learning_intensity = global_config.expression.get_expression_config_for_chat( self.chat_id @@ -139,32 +143,45 @@ class ExpressionLearner: Returns: bool: 是否成功触发学习 """ - if not self.should_trigger_learning(): - return + # 使用异步锁防止并发执行 + async with self._learning_lock: + # 在锁内检查,避免并发触发 + # 如果锁被持有,其他协程会等待,但等待期间条件可能已变化,所以需要再次检查 + if not self.should_trigger_learning(): + return - try: - logger.info(f"在聊天流 {self.chat_name} 学习表达方式") - # 学习语言风格 - learnt_style = await self.learn_and_store(num=25) + # 保存学习开始前的时间戳,用于获取消息范围 + learning_start_timestamp = time.time() + previous_learning_time = self.last_learning_time + + # 立即更新学习时间,防止并发触发 + self.last_learning_time = learning_start_timestamp - # 更新学习时间 - self.last_learning_time = time.time() + try: + logger.info(f"在聊天流 {self.chat_name} 学习表达方式") + # 学习语言风格,传递学习开始前的时间戳 + learnt_style = await self.learn_and_store(num=25, timestamp_start=previous_learning_time) - if learnt_style: - logger.info(f"聊天流 {self.chat_name} 表达学习完成") - else: - logger.warning(f"聊天流 {self.chat_name} 表达学习未获得有效结果") + if learnt_style: + logger.info(f"聊天流 {self.chat_name} 表达学习完成") + else: + logger.warning(f"聊天流 {self.chat_name} 表达学习未获得有效结果") - except Exception as e: - logger.error(f"为聊天流 {self.chat_name} 触发学习失败: {e}") - traceback.print_exc() - return + except Exception as e: + logger.error(f"为聊天流 {self.chat_name} 触发学习失败: {e}") + traceback.print_exc() + # 即使失败也保持时间戳更新,避免频繁重试 + return - async def learn_and_store(self, num: int = 10) -> List[Tuple[str, str, str]]: + async def learn_and_store(self, num: int = 10, timestamp_start: Optional[float] = None) -> List[Tuple[str, str, str]]: """ 学习并存储表达方式 + + Args: + num: 学习数量 + timestamp_start: 学习开始的时间戳,如果为None则使用self.last_learning_time """ - learnt_expressions = await self.learn_expression(num) + learnt_expressions = await self.learn_expression(num, timestamp_start=timestamp_start) if learnt_expressions is None: logger.info("没有学习到表达风格") @@ -374,18 +391,22 @@ class ExpressionLearner: return matched_expressions - async def learn_expression(self, num: int = 10) -> Optional[List[Tuple[str, str, str, str]]]: + async def learn_expression(self, num: int = 10, timestamp_start: Optional[float] = None) -> Optional[List[Tuple[str, str, str, str]]]: """从指定聊天流学习表达方式 Args: num: 学习数量 + timestamp_start: 学习开始的时间戳,如果为None则使用self.last_learning_time """ current_time = time.time() + + # 使用传入的时间戳,如果没有则使用self.last_learning_time + start_timestamp = timestamp_start if timestamp_start is not None else self.last_learning_time # 获取上次学习之后的消息 random_msg = get_raw_msg_by_timestamp_with_chat_inclusive( chat_id=self.chat_id, - timestamp_start=self.last_learning_time, + timestamp_start=start_timestamp, timestamp_end=current_time, limit=num, ) diff --git a/src/jargon/jargon_explainer.py b/src/jargon/jargon_explainer.py index 02595080..28122008 100644 --- a/src/jargon/jargon_explainer.py +++ b/src/jargon/jargon_explainer.py @@ -249,3 +249,112 @@ async def explain_jargon_in_context(chat_id: str, messages: List[Any], chat_cont """ explainer = JargonExplainer(chat_id) return await explainer.explain_jargon(messages, chat_context) + + +def match_jargon_from_text(chat_text: str, chat_id: str) -> List[str]: + """直接在聊天文本中匹配已知的jargon,返回出现过的黑话列表 + + Args: + chat_text: 要匹配的聊天文本 + chat_id: 聊天ID + + Returns: + List[str]: 匹配到的黑话列表 + """ + if not chat_text or not chat_text.strip(): + return [] + + query = Jargon.select().where((Jargon.meaning.is_null(False)) & (Jargon.meaning != "")) + if global_config.jargon.all_global: + query = query.where(Jargon.is_global) + + query = query.order_by(Jargon.count.desc()) + + matched: Dict[str, None] = {} + + for jargon in query: + content = (jargon.content or "").strip() + if not content: + continue + + if not global_config.jargon.all_global and not jargon.is_global: + chat_id_list = parse_chat_id_list(jargon.chat_id) + if not chat_id_list_contains(chat_id_list, chat_id): + continue + + pattern = re.escape(content) + if re.search(r"[\u4e00-\u9fff]", content): + search_pattern = pattern + else: + search_pattern = r"\b" + pattern + r"\b" + + if re.search(search_pattern, chat_text, re.IGNORECASE): + matched[content] = None + + logger.info(f"匹配到 {len(matched)} 个黑话") + + return list(matched.keys()) + + +async def retrieve_concepts_with_jargon(concepts: List[str], chat_id: str) -> str: + """对概念列表进行jargon检索 + + Args: + concepts: 概念列表 + chat_id: 聊天ID + + Returns: + str: 检索结果字符串 + """ + if not concepts: + return "" + + results = [] + exact_matches = [] # 收集所有精确匹配的概念 + for concept in concepts: + concept = concept.strip() + if not concept: + continue + + # 先尝试精确匹配 + jargon_results = search_jargon(keyword=concept, chat_id=chat_id, limit=10, case_sensitive=False, fuzzy=False) + + is_fuzzy_match = False + + # 如果精确匹配未找到,尝试模糊搜索 + if not jargon_results: + jargon_results = search_jargon(keyword=concept, chat_id=chat_id, limit=10, case_sensitive=False, fuzzy=True) + is_fuzzy_match = True + + if jargon_results: + # 找到结果 + if is_fuzzy_match: + # 模糊匹配 + output_parts = [f"未精确匹配到'{concept}'"] + for result in jargon_results: + found_content = result.get("content", "").strip() + meaning = result.get("meaning", "").strip() + if found_content and meaning: + output_parts.append(f"找到 '{found_content}' 的含义为:{meaning}") + results.append(",".join(output_parts)) + logger.info(f"在jargon库中找到匹配(模糊搜索): {concept},找到{len(jargon_results)}条结果") + else: + # 精确匹配 + output_parts = [] + for result in jargon_results: + meaning = result.get("meaning", "").strip() + if meaning: + output_parts.append(f"'{concept}' 为黑话或者网络简写,含义为:{meaning}") + results.append(";".join(output_parts) if len(output_parts) > 1 else output_parts[0]) + exact_matches.append(concept) # 收集精确匹配的概念,稍后统一打印 + else: + # 未找到,不返回占位信息,只记录日志 + logger.info(f"在jargon库中未找到匹配: {concept}") + + # 合并所有精确匹配的日志 + if exact_matches: + logger.info(f"找到黑话: {', '.join(exact_matches)},共找到{len(exact_matches)}条结果") + + if results: + return "【概念检索结果】\n" + "\n".join(results) + "\n" + return "" \ No newline at end of file diff --git a/src/jargon/jargon_miner.py b/src/jargon/jargon_miner.py index 77cb15ce..b7f6c857 100644 --- a/src/jargon/jargon_miner.py +++ b/src/jargon/jargon_miner.py @@ -182,6 +182,9 @@ class JargonMiner: self.stream_name = stream_name if stream_name else self.chat_id self.cache_limit = 100 self.cache: OrderedDict[str, None] = OrderedDict() + + # 黑话提取锁,防止并发执行 + self._extraction_lock = asyncio.Lock() def _add_to_cache(self, content: str) -> None: """将提取到的黑话加入缓存,保持LRU语义""" @@ -436,261 +439,265 @@ class JargonMiner: return bool(recent_messages and len(recent_messages) >= self.min_messages_for_learning) async def run_once(self) -> None: - try: - if not self.should_trigger(): - return - - chat_stream = get_chat_manager().get_stream(self.chat_id) - if not chat_stream: - return - - # 记录本次提取的时间窗口,避免重复提取 - extraction_start_time = self.last_learning_time - extraction_end_time = time.time() - - # 拉取学习窗口内的消息 - messages = get_raw_msg_by_timestamp_with_chat_inclusive( - chat_id=self.chat_id, - timestamp_start=extraction_start_time, - timestamp_end=extraction_end_time, - limit=20, - ) - if not messages: - return - - # 按时间排序,确保编号与上下文一致 - messages = sorted(messages, key=lambda msg: msg.time or 0) - - chat_str, message_id_list = build_readable_messages_with_id( - messages=messages, - replace_bot_name=True, - timestamp_mode="relative", - truncate=False, - show_actions=False, - show_pic=True, - pic_single=True, - ) - if not chat_str.strip(): - return - - msg_id_to_index: Dict[str, int] = {} - for idx, (msg_id, _msg) in enumerate(message_id_list or []): - if not msg_id: - continue - msg_id_to_index[msg_id] = idx - if not msg_id_to_index: - logger.warning("未能生成消息ID映射,跳过本次提取") - return - - prompt: str = await global_prompt_manager.format_prompt( - "extract_jargon_prompt", - bot_name=global_config.bot.nickname, - chat_str=chat_str, - ) - - response, _ = await self.llm.generate_response_async(prompt, temperature=0.2) - if not response: - return - - if global_config.debug.show_jargon_prompt: - logger.info(f"jargon提取提示词: {prompt}") - logger.info(f"jargon提取结果: {response}") - - # 解析为JSON - entries: List[dict] = [] + # 使用异步锁防止并发执行 + async with self._extraction_lock: try: - resp = response.strip() - parsed = None - if resp.startswith("[") and resp.endswith("]"): - parsed = json.loads(resp) - else: - repaired = repair_json(resp) - if isinstance(repaired, str): - parsed = json.loads(repaired) - else: - parsed = repaired - - if isinstance(parsed, dict): - parsed = [parsed] - - if not isinstance(parsed, list): + # 在锁内检查,避免并发触发 + if not self.should_trigger(): return - for item in parsed: - if not isinstance(item, dict): - continue + chat_stream = get_chat_manager().get_stream(self.chat_id) + if not chat_stream: + return - content = str(item.get("content", "")).strip() - msg_id_value = item.get("msg_id") - - if not content: - continue - - if contains_bot_self_name(content): - logger.info(f"解析阶段跳过包含机器人昵称/别名的词条: {content}") - continue - - msg_id_str = str(msg_id_value or "").strip() - if not msg_id_str: - logger.warning(f"解析jargon失败:msg_id缺失,content={content}") - continue - - msg_index = msg_id_to_index.get(msg_id_str) - if msg_index is None: - logger.warning(f"解析jargon失败:msg_id未找到,content={content}, msg_id={msg_id_str}") - continue - - target_msg = messages[msg_index] - if is_bot_message(target_msg): - logger.info(f"解析阶段跳过引用机器人自身消息的词条: content={content}, msg_id={msg_id_str}") - continue - - context_paragraph = build_context_paragraph(messages, msg_index) - if not context_paragraph: - logger.warning(f"解析jargon失败:上下文为空,content={content}, msg_id={msg_id_str}") - continue - - entries.append({"content": content, "raw_content": [context_paragraph]}) - cached_entries = self._collect_cached_entries(messages) - if cached_entries: - entries.extend(cached_entries) - except Exception as e: - logger.error(f"解析jargon JSON失败: {e}; 原始: {response}") - return - - if not entries: - return - - # 去重并合并raw_content(按 content 聚合) - merged_entries: OrderedDict[str, Dict[str, List[str]]] = OrderedDict() - for entry in entries: - content_key = entry["content"] - raw_list = entry.get("raw_content", []) or [] - if content_key in merged_entries: - merged_entries[content_key]["raw_content"].extend(raw_list) - else: - merged_entries[content_key] = { - "content": content_key, - "raw_content": list(raw_list), - } - - uniq_entries = [] - for merged_entry in merged_entries.values(): - raw_content_list = merged_entry["raw_content"] - if raw_content_list: - merged_entry["raw_content"] = list(dict.fromkeys(raw_content_list)) - uniq_entries.append(merged_entry) - - saved = 0 - updated = 0 - for entry in uniq_entries: - content = entry["content"] - raw_content_list = entry["raw_content"] # 已经是列表 - - try: - # 查询所有content匹配的记录 - query = Jargon.select().where(Jargon.content == content) - - # 查找匹配的记录 - matched_obj = None - for obj in query: - if global_config.jargon.all_global: - # 开启all_global:所有content匹配的记录都可以 - matched_obj = obj - break - else: - # 关闭all_global:需要检查chat_id列表是否包含目标chat_id - chat_id_list = parse_chat_id_list(obj.chat_id) - if chat_id_list_contains(chat_id_list, self.chat_id): - matched_obj = obj - break - - if matched_obj: - obj = matched_obj - try: - obj.count = (obj.count or 0) + 1 - except Exception: - obj.count = 1 - - # 合并raw_content列表:读取现有列表,追加新值,去重 - existing_raw_content = [] - if obj.raw_content: - try: - existing_raw_content = ( - json.loads(obj.raw_content) if isinstance(obj.raw_content, str) else obj.raw_content - ) - if not isinstance(existing_raw_content, list): - existing_raw_content = [existing_raw_content] if existing_raw_content else [] - except (json.JSONDecodeError, TypeError): - existing_raw_content = [obj.raw_content] if obj.raw_content else [] - - # 合并并去重 - merged_list = list(dict.fromkeys(existing_raw_content + raw_content_list)) - obj.raw_content = json.dumps(merged_list, ensure_ascii=False) - - # 更新chat_id列表:增加当前chat_id的计数 - chat_id_list = parse_chat_id_list(obj.chat_id) - updated_chat_id_list = update_chat_id_list(chat_id_list, self.chat_id, increment=1) - obj.chat_id = json.dumps(updated_chat_id_list, ensure_ascii=False) - - # 开启all_global时,确保记录标记为is_global=True - if global_config.jargon.all_global: - obj.is_global = True - # 关闭all_global时,保持原有is_global不变(不修改) - - obj.save() - - # 检查是否需要推断(达到阈值且超过上次判定值) - if _should_infer_meaning(obj): - # 异步触发推断,不阻塞主流程 - # 重新加载对象以确保数据最新 - jargon_id = obj.id - asyncio.create_task(self._infer_meaning_by_id(jargon_id)) - - updated += 1 - else: - # 没找到匹配记录,创建新记录 - if global_config.jargon.all_global: - # 开启all_global:新记录默认为is_global=True - is_global_new = True - else: - # 关闭all_global:新记录is_global=False - is_global_new = False - - # 使用新格式创建chat_id列表:[[chat_id, count]] - chat_id_list = [[self.chat_id, 1]] - chat_id_json = json.dumps(chat_id_list, ensure_ascii=False) - - Jargon.create( - content=content, - raw_content=json.dumps(raw_content_list, ensure_ascii=False), - chat_id=chat_id_json, - is_global=is_global_new, - count=1, - ) - saved += 1 - except Exception as e: - logger.error(f"保存jargon失败: chat_id={self.chat_id}, content={content}, err={e}") - continue - finally: - self._add_to_cache(content) - - # 固定输出提取的jargon结果,格式化为可读形式(只要有提取结果就输出) - if uniq_entries: - # 收集所有提取的jargon内容 - jargon_list = [entry["content"] for entry in uniq_entries] - jargon_str = ",".join(jargon_list) - - # 输出格式化的结果(使用logger.info会自动应用jargon模块的颜色) - logger.info(f"[{self.stream_name}]疑似黑话: {jargon_str}") - - # 更新为本次提取的结束时间,确保不会重复提取相同的消息窗口 + # 记录本次提取的时间窗口,避免重复提取 + extraction_start_time = self.last_learning_time + extraction_end_time = time.time() + + # 立即更新学习时间,防止并发触发 self.last_learning_time = extraction_end_time - if saved or updated: - logger.info(f"jargon写入: 新增 {saved} 条,更新 {updated} 条,chat_id={self.chat_id}") - except Exception as e: - logger.error(f"JargonMiner 运行失败: {e}") + # 拉取学习窗口内的消息 + messages = get_raw_msg_by_timestamp_with_chat_inclusive( + chat_id=self.chat_id, + timestamp_start=extraction_start_time, + timestamp_end=extraction_end_time, + limit=20, + ) + if not messages: + return + + # 按时间排序,确保编号与上下文一致 + messages = sorted(messages, key=lambda msg: msg.time or 0) + + chat_str, message_id_list = build_readable_messages_with_id( + messages=messages, + replace_bot_name=True, + timestamp_mode="relative", + truncate=False, + show_actions=False, + show_pic=True, + pic_single=True, + ) + if not chat_str.strip(): + return + + msg_id_to_index: Dict[str, int] = {} + for idx, (msg_id, _msg) in enumerate(message_id_list or []): + if not msg_id: + continue + msg_id_to_index[msg_id] = idx + if not msg_id_to_index: + logger.warning("未能生成消息ID映射,跳过本次提取") + return + + prompt: str = await global_prompt_manager.format_prompt( + "extract_jargon_prompt", + bot_name=global_config.bot.nickname, + chat_str=chat_str, + ) + + response, _ = await self.llm.generate_response_async(prompt, temperature=0.2) + if not response: + return + + if global_config.debug.show_jargon_prompt: + logger.info(f"jargon提取提示词: {prompt}") + logger.info(f"jargon提取结果: {response}") + + # 解析为JSON + entries: List[dict] = [] + try: + resp = response.strip() + parsed = None + if resp.startswith("[") and resp.endswith("]"): + parsed = json.loads(resp) + else: + repaired = repair_json(resp) + if isinstance(repaired, str): + parsed = json.loads(repaired) + else: + parsed = repaired + + if isinstance(parsed, dict): + parsed = [parsed] + + if not isinstance(parsed, list): + return + + for item in parsed: + if not isinstance(item, dict): + continue + + content = str(item.get("content", "")).strip() + msg_id_value = item.get("msg_id") + + if not content: + continue + + if contains_bot_self_name(content): + logger.info(f"解析阶段跳过包含机器人昵称/别名的词条: {content}") + continue + + msg_id_str = str(msg_id_value or "").strip() + if not msg_id_str: + logger.warning(f"解析jargon失败:msg_id缺失,content={content}") + continue + + msg_index = msg_id_to_index.get(msg_id_str) + if msg_index is None: + logger.warning(f"解析jargon失败:msg_id未找到,content={content}, msg_id={msg_id_str}") + continue + + target_msg = messages[msg_index] + if is_bot_message(target_msg): + logger.info(f"解析阶段跳过引用机器人自身消息的词条: content={content}, msg_id={msg_id_str}") + continue + + context_paragraph = build_context_paragraph(messages, msg_index) + if not context_paragraph: + logger.warning(f"解析jargon失败:上下文为空,content={content}, msg_id={msg_id_str}") + continue + + entries.append({"content": content, "raw_content": [context_paragraph]}) + cached_entries = self._collect_cached_entries(messages) + if cached_entries: + entries.extend(cached_entries) + except Exception as e: + logger.error(f"解析jargon JSON失败: {e}; 原始: {response}") + return + + if not entries: + return + + # 去重并合并raw_content(按 content 聚合) + merged_entries: OrderedDict[str, Dict[str, List[str]]] = OrderedDict() + for entry in entries: + content_key = entry["content"] + raw_list = entry.get("raw_content", []) or [] + if content_key in merged_entries: + merged_entries[content_key]["raw_content"].extend(raw_list) + else: + merged_entries[content_key] = { + "content": content_key, + "raw_content": list(raw_list), + } + + uniq_entries = [] + for merged_entry in merged_entries.values(): + raw_content_list = merged_entry["raw_content"] + if raw_content_list: + merged_entry["raw_content"] = list(dict.fromkeys(raw_content_list)) + uniq_entries.append(merged_entry) + + saved = 0 + updated = 0 + for entry in uniq_entries: + content = entry["content"] + raw_content_list = entry["raw_content"] # 已经是列表 + + try: + # 查询所有content匹配的记录 + query = Jargon.select().where(Jargon.content == content) + + # 查找匹配的记录 + matched_obj = None + for obj in query: + if global_config.jargon.all_global: + # 开启all_global:所有content匹配的记录都可以 + matched_obj = obj + break + else: + # 关闭all_global:需要检查chat_id列表是否包含目标chat_id + chat_id_list = parse_chat_id_list(obj.chat_id) + if chat_id_list_contains(chat_id_list, self.chat_id): + matched_obj = obj + break + + if matched_obj: + obj = matched_obj + try: + obj.count = (obj.count or 0) + 1 + except Exception: + obj.count = 1 + + # 合并raw_content列表:读取现有列表,追加新值,去重 + existing_raw_content = [] + if obj.raw_content: + try: + existing_raw_content = ( + json.loads(obj.raw_content) if isinstance(obj.raw_content, str) else obj.raw_content + ) + if not isinstance(existing_raw_content, list): + existing_raw_content = [existing_raw_content] if existing_raw_content else [] + except (json.JSONDecodeError, TypeError): + existing_raw_content = [obj.raw_content] if obj.raw_content else [] + + # 合并并去重 + merged_list = list(dict.fromkeys(existing_raw_content + raw_content_list)) + obj.raw_content = json.dumps(merged_list, ensure_ascii=False) + + # 更新chat_id列表:增加当前chat_id的计数 + chat_id_list = parse_chat_id_list(obj.chat_id) + updated_chat_id_list = update_chat_id_list(chat_id_list, self.chat_id, increment=1) + obj.chat_id = json.dumps(updated_chat_id_list, ensure_ascii=False) + + # 开启all_global时,确保记录标记为is_global=True + if global_config.jargon.all_global: + obj.is_global = True + # 关闭all_global时,保持原有is_global不变(不修改) + + obj.save() + + # 检查是否需要推断(达到阈值且超过上次判定值) + if _should_infer_meaning(obj): + # 异步触发推断,不阻塞主流程 + # 重新加载对象以确保数据最新 + jargon_id = obj.id + asyncio.create_task(self._infer_meaning_by_id(jargon_id)) + + updated += 1 + else: + # 没找到匹配记录,创建新记录 + if global_config.jargon.all_global: + # 开启all_global:新记录默认为is_global=True + is_global_new = True + else: + # 关闭all_global:新记录is_global=False + is_global_new = False + + # 使用新格式创建chat_id列表:[[chat_id, count]] + chat_id_list = [[self.chat_id, 1]] + chat_id_json = json.dumps(chat_id_list, ensure_ascii=False) + + Jargon.create( + content=content, + raw_content=json.dumps(raw_content_list, ensure_ascii=False), + chat_id=chat_id_json, + is_global=is_global_new, + count=1, + ) + saved += 1 + except Exception as e: + logger.error(f"保存jargon失败: chat_id={self.chat_id}, content={content}, err={e}") + continue + finally: + self._add_to_cache(content) + + # 固定输出提取的jargon结果,格式化为可读形式(只要有提取结果就输出) + if uniq_entries: + # 收集所有提取的jargon内容 + jargon_list = [entry["content"] for entry in uniq_entries] + jargon_str = ",".join(jargon_list) + + # 输出格式化的结果(使用logger.info会自动应用jargon模块的颜色) + logger.info(f"[{self.stream_name}]疑似黑话: {jargon_str}") + + if saved or updated: + logger.info(f"jargon写入: 新增 {saved} 条,更新 {updated} 条,chat_id={self.chat_id}") + except Exception as e: + logger.error(f"JargonMiner 运行失败: {e}") + # 即使失败也保持时间戳更新,避免频繁重试 class JargonMinerManager: diff --git a/src/memory_system/memory_retrieval.py b/src/memory_system/memory_retrieval.py index dc7755ea..2471c8fa 100644 --- a/src/memory_system/memory_retrieval.py +++ b/src/memory_system/memory_retrieval.py @@ -1,17 +1,16 @@ import time import json -import re import asyncio from typing import List, Dict, Any, Optional, Tuple, Set from src.common.logger import get_logger from src.config.config import global_config, model_config from src.chat.utils.prompt_builder import Prompt, global_prompt_manager from src.plugin_system.apis import llm_api -from src.common.database.database_model import ThinkingBack, Jargon -from json_repair import repair_json +from src.common.database.database_model import ThinkingBack from src.memory_system.retrieval_tools import get_tool_registry, init_all_tools +from src.memory_system.memory_utils import parse_questions_json from src.llm_models.payload_content.message import MessageBuilder, RoleType, Message -from src.jargon.jargon_utils import parse_chat_id_list, chat_id_list_contains +from src.jargon.jargon_explainer import match_jargon_from_text, retrieve_concepts_with_jargon logger = get_logger("memory_retrieval") @@ -101,10 +100,6 @@ def init_memory_retrieval_prompt(): Prompt( """你的名字是{bot_name}。现在是{time_now}。 你正在参与聊天,你需要搜集信息来回答问题,帮助你参与聊天。 - -**重要限制:** -- 思考要简短,直接切入要点 - 当前需要解答的问题:{question} 已收集的信息: {collected_info} @@ -113,11 +108,13 @@ def init_memory_retrieval_prompt(): - 如果涉及过往事件,或者查询某个过去可能提到过的概念,或者某段时间发生的事件。可以使用聊天记录查询工具查询过往事件 - 如果涉及人物,可以使用人物信息查询工具查询人物信息 - 如果没有可靠信息,且查询时间充足,或者不确定查询类别,也可以使用lpmm知识库查询,作为辅助信息 -- 如果信息不足需要使用tool,说明需要查询什么,并输出为纯文本说明,然后调用相应工具查询(可并行调用多个工具) +- **如果信息不足需要使用tool,说明需要查询什么,并输出为纯文本说明,然后调用相应工具查询(可并行调用多个工具)** +- **如果当前已收集的信息足够回答问题,且能找到明确答案,调用found_answer工具标记已找到答案** **思考** -- 你可以对查询思路给出简短的思考 -- 你必须给出使用什么工具进行查询 +- 你可以对查询思路给出简短的思考:思考要简短,直接切入要点 +- 如果信息不足,你必须给出使用什么工具进行查询 +- 如果信息足够,你必须调用found_answer工具 """, name="memory_retrieval_react_prompt_head", ) @@ -149,198 +146,40 @@ def init_memory_retrieval_prompt(): ) -def _parse_react_response(response: str) -> Optional[Dict[str, Any]]: - """解析ReAct Agent的响应 - - Args: - response: LLM返回的响应 - - Returns: - Dict[str, Any]: 解析后的动作信息,如果解析失败返回None - 格式: {"thought": str, "actions": List[Dict[str, Any]]} - 每个action格式: {"action_type": str, "action_params": dict} - """ - try: - # 尝试提取JSON(可能包含在```json代码块中) - json_pattern = r"```json\s*(.*?)\s*```" - matches = re.findall(json_pattern, response, re.DOTALL) - - if matches: - json_str = matches[0] - else: - # 尝试直接解析整个响应 - json_str = response.strip() - - # 修复可能的JSON错误 - repaired_json = repair_json(json_str) - - # 解析JSON - action_info = json.loads(repaired_json) - - if not isinstance(action_info, dict): - logger.warning(f"解析的JSON不是对象格式: {action_info}") - return None - - # 确保actions字段存在且为列表 - if "actions" not in action_info: - logger.warning(f"响应中缺少actions字段: {action_info}") - return None - - if not isinstance(action_info["actions"], list): - logger.warning(f"actions字段不是数组格式: {action_info['actions']}") - return None - - # 确保actions不为空 - if len(action_info["actions"]) == 0: - logger.warning("actions数组为空") - return None - - return action_info - - except Exception as e: - logger.error(f"解析ReAct响应失败: {e}, 响应内容: {response[:200]}...") - return None -async def _retrieve_concepts_with_jargon(concepts: List[str], chat_id: str) -> str: - """对概念列表进行jargon检索 - - Args: - concepts: 概念列表 - chat_id: 聊天ID - - Returns: - str: 检索结果字符串 - """ - if not concepts: - return "" - - from src.jargon.jargon_miner import search_jargon - - results = [] - exact_matches = [] # 收集所有精确匹配的概念 - for concept in concepts: - concept = concept.strip() - if not concept: - continue - - # 先尝试精确匹配 - jargon_results = search_jargon(keyword=concept, chat_id=chat_id, limit=10, case_sensitive=False, fuzzy=False) - - is_fuzzy_match = False - - # 如果精确匹配未找到,尝试模糊搜索 - if not jargon_results: - jargon_results = search_jargon(keyword=concept, chat_id=chat_id, limit=10, case_sensitive=False, fuzzy=True) - is_fuzzy_match = True - - if jargon_results: - # 找到结果 - if is_fuzzy_match: - # 模糊匹配 - output_parts = [f"未精确匹配到'{concept}'"] - for result in jargon_results: - found_content = result.get("content", "").strip() - meaning = result.get("meaning", "").strip() - if found_content and meaning: - output_parts.append(f"找到 '{found_content}' 的含义为:{meaning}") - results.append(",".join(output_parts)) - logger.info(f"在jargon库中找到匹配(模糊搜索): {concept},找到{len(jargon_results)}条结果") - else: - # 精确匹配 - output_parts = [] - for result in jargon_results: - meaning = result.get("meaning", "").strip() - if meaning: - output_parts.append(f"'{concept}' 为黑话或者网络简写,含义为:{meaning}") - results.append(";".join(output_parts) if len(output_parts) > 1 else output_parts[0]) - exact_matches.append(concept) # 收集精确匹配的概念,稍后统一打印 - else: - # 未找到,不返回占位信息,只记录日志 - logger.info(f"在jargon库中未找到匹配: {concept}") - - # 合并所有精确匹配的日志 - if exact_matches: - logger.info(f"找到黑话: {', '.join(exact_matches)},共找到{len(exact_matches)}条结果") - - if results: - return "【概念检索结果】\n" + "\n".join(results) + "\n" - return "" - - -def _match_jargon_from_text(chat_text: str, chat_id: str) -> List[str]: - """直接在聊天文本中匹配已知的jargon,返回出现过的黑话列表""" - # print(chat_text) - if not chat_text or not chat_text.strip(): - return [] - - start_time = time.time() - - query = Jargon.select().where((Jargon.meaning.is_null(False)) & (Jargon.meaning != "")) - if global_config.jargon.all_global: - query = query.where(Jargon.is_global) - - query = query.order_by(Jargon.count.desc()) - - query_time = time.time() - matched: Dict[str, None] = {} - - for jargon in query: - content = (jargon.content or "").strip() - if not content: - continue - - if not global_config.jargon.all_global and not jargon.is_global: - chat_id_list = parse_chat_id_list(jargon.chat_id) - if not chat_id_list_contains(chat_id_list, chat_id): - continue - - pattern = re.escape(content) - if re.search(r"[\u4e00-\u9fff]", content): - search_pattern = pattern - else: - search_pattern = r"\b" + pattern + r"\b" - - if re.search(search_pattern, chat_text, re.IGNORECASE): - matched[content] = None - - # end_time = time.time() - logger.info( - # f"记忆检索黑话匹配: 查询耗时 {(query_time - start_time):.3f}s, " - # f"匹配耗时 {(end_time - query_time):.3f}s, 总耗时 {(end_time - start_time):.3f}s, " - f"匹配到 {len(matched)} 个黑话" - ) - - return list(matched.keys()) - - -def _log_conversation_messages(conversation_messages: List[Message], head_prompt: Optional[str] = None) -> None: +def _log_conversation_messages( + conversation_messages: List[Message], + head_prompt: Optional[str] = None, + final_status: Optional[str] = None, +) -> None: """输出对话消息列表的日志 - + Args: conversation_messages: 对话消息列表 head_prompt: 第一条系统消息(head_prompt)的内容,可选 + final_status: 最终结果状态描述(例如:找到答案/未找到答案),可选 """ if not global_config.debug.show_memory_prompt: return - - log_lines = [] - + + log_lines: List[str] = [] + # 如果有head_prompt,先添加为第一条消息 if head_prompt: - msg_info = "\n[消息 1] 角色: System 内容类型: 文本\n========================================" + msg_info = "========================================\n[消息 1] 角色: System 内容类型: 文本\n-----------------------------" msg_info += f"\n{head_prompt}" log_lines.append(msg_info) start_idx = 2 else: start_idx = 1 - + if not conversation_messages and not head_prompt: return - + for idx, msg in enumerate(conversation_messages, start_idx): role_name = msg.role.value if hasattr(msg.role, "value") else str(msg.role) - + # 处理内容 - 显示完整内容,不截断 if isinstance(msg.content, str): full_content = msg.content @@ -353,25 +192,28 @@ def _log_conversation_messages(conversation_messages: List[Message], head_prompt else: full_content = str(msg.content) content_type = "未知" - + # 构建单条消息的日志信息 - msg_info = f"\n[消息 {idx}] 角色: {role_name} 内容类型: {content_type}\n========================================" - + msg_info = f"\n========================================\n[消息 {idx}] 角色: {role_name} 内容类型: {content_type}\n-----------------------------" + if full_content: msg_info += f"\n{full_content}" - + if msg.tool_calls: msg_info += f"\n 工具调用: {len(msg.tool_calls)}个" for tool_call in msg.tool_calls: msg_info += f"\n - {tool_call}" - + if msg.tool_call_id: msg_info += f"\n 工具调用ID: {msg.tool_call_id}" - + log_lines.append(msg_info) - + total_count = len(conversation_messages) + (1 if head_prompt else 0) - logger.info(f"消息列表 (共{total_count}条):{''.join(log_lines)}") + log_text = f"消息列表 (共{total_count}条):{''.join(log_lines)}" + if final_status: + log_text += f"\n\n[最终结果] {final_status}" + logger.info(log_text) async def _react_agent_solve_question( @@ -407,7 +249,7 @@ async def _react_agent_solve_question( thinking_steps = [] is_timeout = False conversation_messages: List[Message] = [] - last_head_prompt: Optional[str] = None # 保存最后一次使用的head_prompt + first_head_prompt: Optional[str] = None # 保存第一次使用的head_prompt(用于日志显示) for iteration in range(max_iterations): # 检查超时 @@ -430,40 +272,6 @@ async def _react_agent_solve_question( remaining_iterations = max_iterations - current_iteration is_final_iteration = current_iteration >= max_iterations - # 每次迭代开始时,先评估当前信息是否足够回答问题 - evaluation_prompt = await global_prompt_manager.format_prompt( - "memory_retrieval_react_final_prompt", - bot_name=bot_name, - time_now=time_now, - question=question, - collected_info=collected_info if collected_info else "暂无信息", - current_iteration=current_iteration, - remaining_iterations=remaining_iterations, - max_iterations=max_iterations, - ) - - # if global_config.debug.show_memory_prompt: - # logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 评估Prompt: {evaluation_prompt}") - - eval_success, eval_response, eval_reasoning_content, eval_model_name, eval_tool_calls = await llm_api.generate_with_model_with_tools( - evaluation_prompt, - model_config=model_config.model_task_config.tool_use, - tool_options=[], # 评估阶段不提供工具 - request_type="memory.react.eval", - ) - - if not eval_success: - logger.error(f"ReAct Agent 第 {iteration + 1} 次迭代 评估阶段 LLM调用失败: {eval_response}") - # 评估失败,如果还有剩余迭代次数,尝试继续查询 - if not is_final_iteration: - continue - else: - break - - logger.info( - f"ReAct Agent 第 {iteration + 1} 次迭代 评估响应: {eval_response}" - ) - # 提取函数调用中参数的值,支持单引号和双引号 def extract_quoted_content(text, func_name, param_name): """从文本中提取函数调用中参数的值,支持单引号和双引号 @@ -522,88 +330,132 @@ async def _react_agent_solve_question( return None - # 从评估响应中提取found_answer或not_enough_info - found_answer_content = None - not_enough_info_reason = None + # 如果是最后一次迭代,使用final_prompt进行总结 + if is_final_iteration: + evaluation_prompt = await global_prompt_manager.format_prompt( + "memory_retrieval_react_final_prompt", + bot_name=bot_name, + time_now=time_now, + question=question, + collected_info=collected_info if collected_info else "暂无信息", + current_iteration=current_iteration, + remaining_iterations=remaining_iterations, + max_iterations=max_iterations, + ) - if eval_response: - found_answer_content = extract_quoted_content(eval_response, "found_answer", "answer") - if not found_answer_content: - not_enough_info_reason = extract_quoted_content(eval_response, "not_enough_info", "reason") + if global_config.debug.show_memory_prompt: + logger.info(f"ReAct Agent 最终评估Prompt: {evaluation_prompt}") - # 如果找到答案,直接返回 - if found_answer_content: - eval_step = { - "iteration": iteration + 1, - "thought": f"[评估] {eval_response}", - "actions": [{"action_type": "found_answer", "action_params": {"answer": found_answer_content}}], - "observations": ["评估阶段检测到found_answer"] - } - thinking_steps.append(eval_step) - logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 评估阶段找到关于问题{question}的答案: {found_answer_content}") - - # React完成时输出消息列表 - _log_conversation_messages(conversation_messages, last_head_prompt) - - return True, found_answer_content, thinking_steps, False + eval_success, eval_response, eval_reasoning_content, eval_model_name, eval_tool_calls = await llm_api.generate_with_model_with_tools( + evaluation_prompt, + model_config=model_config.model_task_config.tool_use, + tool_options=[], # 最终评估阶段不提供工具 + request_type="memory.react.final", + ) - # 如果评估为not_enough_info,且是最终迭代,返回not_enough_info - if not_enough_info_reason: - if is_final_iteration: + if not eval_success: + logger.error(f"ReAct Agent 第 {iteration + 1} 次迭代 最终评估阶段 LLM调用失败: {eval_response}") + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status="未找到答案:最终评估阶段LLM调用失败", + ) + return False, "最终评估阶段LLM调用失败", thinking_steps, False + + logger.info( + f"ReAct Agent 第 {iteration + 1} 次迭代 最终评估响应: {eval_response}" + ) + + # 从最终评估响应中提取found_answer或not_enough_info + found_answer_content = None + not_enough_info_reason = None + + if eval_response: + found_answer_content = extract_quoted_content(eval_response, "found_answer", "answer") + if not found_answer_content: + not_enough_info_reason = extract_quoted_content(eval_response, "not_enough_info", "reason") + + # 如果找到答案,返回 + if found_answer_content: eval_step = { "iteration": iteration + 1, - "thought": f"[评估] {eval_response}", + "thought": f"[最终评估] {eval_response}", + "actions": [{"action_type": "found_answer", "action_params": {"answer": found_answer_content}}], + "observations": ["最终评估阶段检测到found_answer"] + } + thinking_steps.append(eval_step) + logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 最终评估阶段找到关于问题{question}的答案: {found_answer_content}") + + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status=f"找到答案:{found_answer_content}", + ) + + return True, found_answer_content, thinking_steps, False + + # 如果评估为not_enough_info,返回空字符串(不返回任何信息) + if not_enough_info_reason: + eval_step = { + "iteration": iteration + 1, + "thought": f"[最终评估] {eval_response}", "actions": [{"action_type": "not_enough_info", "action_params": {"reason": not_enough_info_reason}}], - "observations": ["评估阶段检测到not_enough_info"] + "observations": ["最终评估阶段检测到not_enough_info"] } thinking_steps.append(eval_step) logger.info( - f"ReAct Agent 第 {iteration + 1} 次迭代 评估阶段判断信息不足: {not_enough_info_reason}" + f"ReAct Agent 第 {iteration + 1} 次迭代 最终评估阶段判断信息不足: {not_enough_info_reason}" ) - # React完成时输出消息列表 - _log_conversation_messages(conversation_messages, last_head_prompt) - - return False, not_enough_info_reason, thinking_steps, False - else: - # 非最终迭代,信息不足,继续搜集信息 - logger.info( - f"ReAct Agent 第 {iteration + 1} 次迭代 评估阶段判断信息不足: {not_enough_info_reason},继续查询" + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status=f"未找到答案:{not_enough_info_reason}", ) + + return False, "", thinking_steps, False - # 如果是最终迭代但没有明确判断,视为not_enough_info - if is_final_iteration: + # 如果没有明确判断,视为not_enough_info,返回空字符串(不返回任何信息) eval_step = { "iteration": iteration + 1, - "thought": f"[评估] {eval_response}", + "thought": f"[最终评估] {eval_response}", "actions": [{"action_type": "not_enough_info", "action_params": {"reason": "已到达最后一次迭代,无法找到答案"}}], "observations": ["已到达最后一次迭代,无法找到答案"] } thinking_steps.append(eval_step) logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 已到达最后一次迭代,无法找到答案") - # React完成时输出消息列表 - _log_conversation_messages(conversation_messages, last_head_prompt) + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status="未找到答案:已到达最后一次迭代,无法找到答案", + ) - return False, "已到达最后一次迭代,无法找到答案", thinking_steps, False + return False, "", thinking_steps, False - # 非最终迭代且信息不足,使用head_prompt决定调用哪些工具 + # 前n-1次迭代,使用head_prompt决定调用哪些工具(包含found_answer工具) tool_definitions = tool_registry.get_tool_definitions() logger.info( f"ReAct Agent 第 {iteration + 1} 次迭代,问题: {question}|可用工具数量: {len(tool_definitions)}" ) - head_prompt = await global_prompt_manager.format_prompt( - "memory_retrieval_react_prompt_head", - bot_name=bot_name, - time_now=time_now, - question=question, - collected_info=collected_info if collected_info else "", - current_iteration=current_iteration, - remaining_iterations=remaining_iterations, - max_iterations=max_iterations, - ) - last_head_prompt = head_prompt # 保存最后一次使用的head_prompt + # head_prompt应该只构建一次,使用初始的collected_info,后续迭代都复用同一个 + if first_head_prompt is None: + # 第一次构建,使用初始的collected_info(即initial_info) + initial_collected_info = initial_info if initial_info else "" + first_head_prompt = await global_prompt_manager.format_prompt( + "memory_retrieval_react_prompt_head", + bot_name=bot_name, + time_now=time_now, + question=question, + collected_info=initial_collected_info, + current_iteration=current_iteration, + remaining_iterations=remaining_iterations, + max_iterations=max_iterations, + ) + + # 后续迭代都复用第一次构建的head_prompt + head_prompt = first_head_prompt def message_factory( _client, @@ -635,7 +487,7 @@ async def _react_agent_solve_question( request_type="memory.react", ) - logger.info( + logger.debug( f"ReAct Agent 第 {iteration + 1} 次迭代 模型: {model_name} ,调用工具数量: {len(tool_calls) if tool_calls else 0} ,调用工具响应: {response}" ) @@ -643,8 +495,7 @@ async def _react_agent_solve_question( logger.error(f"ReAct Agent LLM调用失败: {response}") break - # 注意:这里不检查found_answer或not_enough_info,这些只在评估阶段(memory_retrieval_react_final_prompt)检查 - # memory_retrieval_react_prompt_head只用于决定调用哪些工具来搜集信息 + # 注意:这里会检查found_answer工具调用,如果检测到found_answer工具,会直接返回答案 assistant_message: Optional[Message] = None if tool_calls: @@ -686,16 +537,42 @@ async def _react_agent_solve_question( continue # 处理工具调用 + # 首先检查是否有found_answer工具调用,如果有则立即返回,不再处理其他工具 + found_answer_from_tool = None + for tool_call in tool_calls: + tool_name = tool_call.func_name + tool_args = tool_call.args or {} + + if tool_name == "found_answer": + found_answer_from_tool = tool_args.get("answer", "") + if found_answer_from_tool: + step["actions"].append({"action_type": "found_answer", "action_params": {"answer": found_answer_from_tool}}) + step["observations"] = ["检测到found_answer工具调用"] + thinking_steps.append(step) + logger.debug(f"ReAct Agent 第 {iteration + 1} 次迭代 通过found_answer工具找到关于问题{question}的答案: {found_answer_from_tool}") + + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status=f"找到答案:{found_answer_from_tool}", + ) + + return True, found_answer_from_tool, thinking_steps, False + + # 如果没有found_answer工具调用,或者found_answer工具调用没有答案,继续处理其他工具 tool_tasks = [] - for i, tool_call in enumerate(tool_calls): tool_name = tool_call.func_name tool_args = tool_call.args or {} - logger.info( + logger.debug( f"ReAct Agent 第 {iteration + 1} 次迭代 工具调用 {i + 1}/{len(tool_calls)}: {tool_name}({tool_args})" ) + # 跳过found_answer工具调用(已经在上面处理过了) + if tool_name == "found_answer": + continue + # 普通工具调用 tool = tool_registry.get_tool(tool_name) if tool: @@ -740,15 +617,10 @@ async def _react_agent_solve_question( step["observations"].append(observation_text) collected_info += f"\n{observation_text}\n" if stripped_observation: - tool_builder = MessageBuilder() - tool_builder.set_role(RoleType.Tool) - tool_builder.add_text_content(observation_text) - tool_builder.add_tool_call(tool_call_item.call_id) - conversation_messages.append(tool_builder.build()) + # 检查工具输出中是否有新的jargon,如果有则追加到工具结果中 if enable_jargon_detection: - jargon_concepts = _match_jargon_from_text(stripped_observation, chat_id) + jargon_concepts = match_jargon_from_text(stripped_observation, chat_id) if jargon_concepts: - jargon_info = "" new_concepts = [] for concept in jargon_concepts: normalized_concept = concept.strip() @@ -756,10 +628,18 @@ async def _react_agent_solve_question( new_concepts.append(normalized_concept) seen_jargon_concepts.add(normalized_concept) if new_concepts: - jargon_info = await _retrieve_concepts_with_jargon(new_concepts, chat_id) - if jargon_info: - collected_info += f"\n{jargon_info}\n" - logger.info(f"工具输出触发黑话解析: {new_concepts}") + jargon_info = await retrieve_concepts_with_jargon(new_concepts, chat_id) + if jargon_info: + # 将jargon查询结果追加到工具结果中 + observation_text += f"\n\n{jargon_info}" + collected_info += f"\n{jargon_info}\n" + logger.info(f"工具输出触发黑话解析: {new_concepts}") + + tool_builder = MessageBuilder() + tool_builder.set_role(RoleType.Tool) + tool_builder.add_text_content(observation_text) + tool_builder.add_tool_call(tool_call_item.call_id) + conversation_messages.append(tool_builder.build()) thinking_steps.append(step) @@ -776,13 +656,18 @@ async def _react_agent_solve_question( logger.warning("ReAct Agent达到最大迭代次数,直接视为not_enough_info") # React完成时输出消息列表 - _log_conversation_messages(conversation_messages, last_head_prompt) + timeout_reason = "超时" if is_timeout else "达到最大迭代次数" + _log_conversation_messages( + conversation_messages, + head_prompt=first_head_prompt, + final_status=f"未找到答案:{timeout_reason}", + ) - return False, "未找到相关信息", thinking_steps, is_timeout + return False, "", thinking_steps, is_timeout -def _get_recent_query_history(chat_id: str, time_window_seconds: float = 300.0) -> str: - """获取最近一段时间内的查询历史 +def _get_recent_query_history(chat_id: str, time_window_seconds: float = 600.0) -> str: + """获取最近一段时间内的查询历史(用于避免重复查询) Args: chat_id: 聊天ID @@ -832,6 +717,49 @@ def _get_recent_query_history(chat_id: str, time_window_seconds: float = 300.0) return "" +def _get_recent_found_answers(chat_id: str, time_window_seconds: float = 600.0) -> List[str]: + """获取最近一段时间内已找到答案的查询记录(用于返回给 replyer) + + Args: + chat_id: 聊天ID + time_window_seconds: 时间窗口(秒),默认10分钟 + + Returns: + List[str]: 格式化的答案列表,每个元素格式为 "问题:xxx\n答案:xxx" + """ + try: + current_time = time.time() + start_time = current_time - time_window_seconds + + # 查询最近时间窗口内已找到答案的记录,按更新时间倒序 + records = ( + ThinkingBack.select() + .where( + (ThinkingBack.chat_id == chat_id) + & (ThinkingBack.update_time >= start_time) + & (ThinkingBack.found_answer == 1) + & (ThinkingBack.answer.is_null(False)) + & (ThinkingBack.answer != "") + ) + .order_by(ThinkingBack.update_time.desc()) + .limit(3) # 最多返回5条最近的记录 + ) + + if not records.exists(): + return [] + + found_answers = [] + for record in records: + if record.answer: + found_answers.append(f"问题:{record.question}\n答案:{record.answer}") + + return found_answers + + except Exception as e: + logger.error(f"获取最近已找到答案的记录失败: {e}") + return [] + + def _store_thinking_back( chat_id: str, question: str, context: str, found_answer: bool, answer: str, thinking_steps: List[Dict[str, Any]] ) -> None: @@ -969,8 +897,8 @@ async def build_memory_retrieval_prompt( bot_name = global_config.bot.nickname chat_id = chat_stream.stream_id - # 获取最近查询历史(最近1小时内的查询) - recent_query_history = _get_recent_query_history(chat_id, time_window_seconds=300.0) + # 获取最近查询历史(最近10分钟内的查询,用于避免重复查询) + recent_query_history = _get_recent_query_history(chat_id, time_window_seconds=600.0) if not recent_query_history: recent_query_history = "最近没有查询记录。" @@ -1000,7 +928,7 @@ async def build_memory_retrieval_prompt( return "" # 解析概念列表和问题列表 - _, questions = _parse_questions_json(response) + _, questions = parse_questions_json(response) if questions: logger.info(f"解析到 {len(questions)} 个问题: {questions}") @@ -1009,7 +937,7 @@ async def build_memory_retrieval_prompt( if enable_jargon_detection: # 使用匹配逻辑自动识别聊天中的黑话概念 - concepts = _match_jargon_from_text(message, chat_id) + concepts = match_jargon_from_text(message, chat_id) if concepts: logger.info(f"黑话匹配命中 {len(concepts)} 个概念: {concepts}") else: @@ -1020,12 +948,12 @@ async def build_memory_retrieval_prompt( # 对匹配到的概念进行jargon检索,作为初始信息 initial_info = "" if enable_jargon_detection and concepts: - concept_info = await _retrieve_concepts_with_jargon(concepts, chat_id) + concept_info = await retrieve_concepts_with_jargon(concepts, chat_id) if concept_info: initial_info += concept_info - logger.info(f"概念检索完成,结果: {concept_info}") + logger.debug(f"概念检索完成,结果: {concept_info}") else: - logger.info("概念检索未找到任何结果") + logger.debug("概念检索未找到任何结果") if not questions: logger.debug("模型认为不需要检索记忆或解析失败,不返回任何查询结果") @@ -1060,67 +988,47 @@ async def build_memory_retrieval_prompt( elif result is not None: question_results.append(result) + # 获取最近10分钟内已找到答案的缓存记录 + cached_answers = _get_recent_found_answers(chat_id, time_window_seconds=600.0) + + # 合并当前查询结果和缓存答案(去重:如果当前查询的问题在缓存中已存在,优先使用当前结果) + all_results = [] + + # 先添加当前查询的结果 + current_questions = set() + for result in question_results: + # 提取问题(格式为 "问题:xxx\n答案:xxx") + if result.startswith("问题:"): + question_end = result.find("\n答案:") + if question_end != -1: + current_questions.add(result[4:question_end]) + all_results.append(result) + + # 添加缓存答案(排除当前查询中已存在的问题) + for cached_answer in cached_answers: + if cached_answer.startswith("问题:"): + question_end = cached_answer.find("\n答案:") + if question_end != -1: + cached_question = cached_answer[4:question_end] + if cached_question not in current_questions: + all_results.append(cached_answer) + end_time = time.time() - if question_results: - retrieved_memory = "\n\n".join(question_results) - logger.info(f"记忆检索成功,耗时: {(end_time - start_time):.3f}秒,包含 {len(question_results)} 条记忆") + if all_results: + retrieved_memory = "\n\n".join(all_results) + current_count = len(question_results) + cached_count = len(all_results) - current_count + logger.info( + f"记忆检索成功,耗时: {(end_time - start_time):.3f}秒," + f"当前查询 {current_count} 条记忆,缓存 {cached_count} 条记忆,共 {len(all_results)} 条记忆" + ) return f"你回忆起了以下信息:\n{retrieved_memory}\n如果与回复内容相关,可以参考这些回忆的信息。\n" else: - logger.debug("所有问题均未找到答案") + logger.debug("所有问题均未找到答案,且无缓存答案") return "" except Exception as e: logger.error(f"记忆检索时发生异常: {str(e)}") return "" - -def _parse_questions_json(response: str) -> Tuple[List[str], List[str]]: - """解析问题JSON,返回概念列表和问题列表 - - Args: - response: LLM返回的响应 - - Returns: - Tuple[List[str], List[str]]: (概念列表, 问题列表) - """ - try: - # 尝试提取JSON(可能包含在```json代码块中) - json_pattern = r"```json\s*(.*?)\s*```" - matches = re.findall(json_pattern, response, re.DOTALL) - - if matches: - json_str = matches[0] - else: - # 尝试直接解析整个响应 - json_str = response.strip() - - # 修复可能的JSON错误 - repaired_json = repair_json(json_str) - - # 解析JSON - parsed = json.loads(repaired_json) - - # 只支持新格式:包含concepts和questions的对象 - if not isinstance(parsed, dict): - logger.warning(f"解析的JSON不是对象格式: {parsed}") - return [], [] - - concepts_raw = parsed.get("concepts", []) - questions_raw = parsed.get("questions", []) - - # 确保是列表 - if not isinstance(concepts_raw, list): - concepts_raw = [] - if not isinstance(questions_raw, list): - questions_raw = [] - - # 确保所有元素都是字符串 - concepts = [c for c in concepts_raw if isinstance(c, str) and c.strip()] - questions = [q for q in questions_raw if isinstance(q, str) and q.strip()] - - return concepts, questions - - except Exception as e: - logger.error(f"解析问题JSON失败: {e}, 响应内容: {response[:200]}...") - return [], [] diff --git a/src/memory_system/memory_utils.py b/src/memory_system/memory_utils.py index bff39f95..7aa33a52 100644 --- a/src/memory_system/memory_utils.py +++ b/src/memory_system/memory_utils.py @@ -8,7 +8,8 @@ import json import re from datetime import datetime from typing import Tuple -from difflib import SequenceMatcher +from typing import List +from json_repair import repair_json from src.common.logger import get_logger @@ -16,101 +17,56 @@ from src.common.logger import get_logger logger = get_logger("memory_utils") -def parse_md_json(json_text: str) -> list[str]: - """从Markdown格式的内容中提取JSON对象和推理内容""" - json_objects = [] - reasoning_content = "" - # 使用正则表达式查找```json包裹的JSON内容 - json_pattern = r"```json\s*(.*?)\s*```" - matches = re.findall(json_pattern, json_text, re.DOTALL) - - # 提取JSON之前的内容作为推理文本 - if matches: - # 找到第一个```json的位置 - first_json_pos = json_text.find("```json") - if first_json_pos > 0: - reasoning_content = json_text[:first_json_pos].strip() - # 清理推理内容中的注释标记 - reasoning_content = re.sub(r"^//\s*", "", reasoning_content, flags=re.MULTILINE) - reasoning_content = reasoning_content.strip() - - for match in matches: - try: - # 清理可能的注释和格式问题 - json_str = re.sub(r"//.*?\n", "\n", match) # 移除单行注释 - json_str = re.sub(r"/\*.*?\*/", "", json_str, flags=re.DOTALL) # 移除多行注释 - if json_str := json_str.strip(): - json_obj = json.loads(json_str) - if isinstance(json_obj, dict): - json_objects.append(json_obj) - elif isinstance(json_obj, list): - for item in json_obj: - if isinstance(item, dict): - json_objects.append(item) - except Exception as e: - logger.warning(f"解析JSON块失败: {e}, 块内容: {match[:100]}...") - continue - - return json_objects, reasoning_content - - -def calculate_similarity(text1: str, text2: str) -> float: - """ - 计算两个文本的相似度 +def parse_questions_json(response: str) -> Tuple[List[str], List[str]]: + """解析问题JSON,返回概念列表和问题列表 Args: - text1: 第一个文本 - text2: 第二个文本 + response: LLM返回的响应 Returns: - float: 相似度分数 (0-1) + Tuple[List[str], List[str]]: (概念列表, 问题列表) """ try: - # 预处理文本 - text1 = preprocess_text(text1) - text2 = preprocess_text(text2) + # 尝试提取JSON(可能包含在```json代码块中) + json_pattern = r"```json\s*(.*?)\s*```" + matches = re.findall(json_pattern, response, re.DOTALL) - # 使用SequenceMatcher计算相似度 - similarity = SequenceMatcher(None, text1, text2).ratio() + if matches: + json_str = matches[0] + else: + # 尝试直接解析整个响应 + json_str = response.strip() - # 如果其中一个文本包含另一个,提高相似度 - if text1 in text2 or text2 in text1: - similarity = max(similarity, 0.8) + # 修复可能的JSON错误 + repaired_json = repair_json(json_str) - return similarity + # 解析JSON + parsed = json.loads(repaired_json) + + # 只支持新格式:包含concepts和questions的对象 + if not isinstance(parsed, dict): + logger.warning(f"解析的JSON不是对象格式: {parsed}") + return [], [] + + concepts_raw = parsed.get("concepts", []) + questions_raw = parsed.get("questions", []) + + # 确保是列表 + if not isinstance(concepts_raw, list): + concepts_raw = [] + if not isinstance(questions_raw, list): + questions_raw = [] + + # 确保所有元素都是字符串 + concepts = [c for c in concepts_raw if isinstance(c, str) and c.strip()] + questions = [q for q in questions_raw if isinstance(q, str) and q.strip()] + + return concepts, questions except Exception as e: - logger.error(f"计算相似度时出错: {e}") - return 0.0 - - -def preprocess_text(text: str) -> str: - """ - 预处理文本,提高匹配准确性 - - Args: - text: 原始文本 - - Returns: - str: 预处理后的文本 - """ - try: - # 转换为小写 - text = text.lower() - - # 移除标点符号和特殊字符 - text = re.sub(r"[^\w\s]", "", text) - - # 移除多余空格 - text = re.sub(r"\s+", " ", text).strip() - - return text - - except Exception as e: - logger.error(f"预处理文本时出错: {e}") - return text - + logger.error(f"解析问题JSON失败: {e}, 响应内容: {response[:200]}...") + return [], [] def parse_datetime_to_timestamp(value: str) -> float: """ @@ -140,29 +96,3 @@ def parse_datetime_to_timestamp(value: str) -> float: except Exception as e: last_err = e raise ValueError(f"无法解析时间: {value} ({last_err})") - - -def parse_time_range(time_range: str) -> Tuple[float, float]: - """ - 解析时间范围字符串,返回开始和结束时间戳 - - Args: - time_range: 时间范围字符串,格式:"YYYY-MM-DD HH:MM:SS - YYYY-MM-DD HH:MM:SS" - - Returns: - Tuple[float, float]: (开始时间戳, 结束时间戳) - """ - if " - " not in time_range: - raise ValueError(f"时间范围格式错误,应为 '开始时间 - 结束时间': {time_range}") - - parts = time_range.split(" - ", 1) - if len(parts) != 2: - raise ValueError(f"时间范围格式错误: {time_range}") - - start_str = parts[0].strip() - end_str = parts[1].strip() - - start_timestamp = parse_datetime_to_timestamp(start_str) - end_timestamp = parse_datetime_to_timestamp(end_str) - - return start_timestamp, end_timestamp diff --git a/src/memory_system/retrieval_tools/__init__.py b/src/memory_system/retrieval_tools/__init__.py index 17c3effb..7832985f 100644 --- a/src/memory_system/retrieval_tools/__init__.py +++ b/src/memory_system/retrieval_tools/__init__.py @@ -14,6 +14,7 @@ from .tool_registry import ( from .query_chat_history import register_tool as register_query_chat_history from .query_lpmm_knowledge import register_tool as register_lpmm_knowledge from .query_person_info import register_tool as register_query_person_info +from .found_answer import register_tool as register_found_answer from src.config.config import global_config @@ -21,6 +22,7 @@ def init_all_tools(): """初始化并注册所有记忆检索工具""" register_query_chat_history() register_query_person_info() + register_found_answer() # 注册found_answer工具 if global_config.lpmm_knowledge.lpmm_mode == "agent": register_lpmm_knowledge() diff --git a/src/memory_system/retrieval_tools/found_answer.py b/src/memory_system/retrieval_tools/found_answer.py new file mode 100644 index 00000000..0efd02be --- /dev/null +++ b/src/memory_system/retrieval_tools/found_answer.py @@ -0,0 +1,40 @@ +""" +found_answer工具 - 用于在记忆检索过程中标记找到答案 +""" + +from src.common.logger import get_logger +from .tool_registry import register_memory_retrieval_tool + +logger = get_logger("memory_retrieval_tools") + + +async def found_answer(answer: str) -> str: + """标记已找到问题的答案 + + Args: + answer: 找到的答案内容 + + Returns: + str: 确认信息 + """ + # 这个工具主要用于标记,实际答案会通过返回值传递 + logger.info(f"找到答案: {answer}") + return f"已确认找到答案: {answer}" + + +def register_tool(): + """注册found_answer工具""" + register_memory_retrieval_tool( + name="found_answer", + description="当你在已收集的信息中找到了问题的明确答案时,调用此工具标记已找到答案。只有在检索到明确、具体的答案时才使用此工具,不要编造信息。", + parameters=[ + { + "name": "answer", + "type": "string", + "description": "找到的答案内容,必须基于已收集的信息,不要编造", + "required": True, + }, + ], + execute_func=found_answer, + ) + diff --git a/src/memory_system/retrieval_tools/query_chat_history.py b/src/memory_system/retrieval_tools/query_chat_history.py index 478ccb97..097632c4 100644 --- a/src/memory_system/retrieval_tools/query_chat_history.py +++ b/src/memory_system/retrieval_tools/query_chat_history.py @@ -275,10 +275,6 @@ async def get_chat_history_detail(chat_id: str, memory_ids: str) -> str: except (json.JSONDecodeError, TypeError, ValueError): pass - # 添加原文内容 - if record.original_text: - result_parts.append(f"原文内容:\n{record.original_text}") - results.append("\n".join(result_parts)) if not results: @@ -318,7 +314,7 @@ def register_tool(): # 注册工具2:获取记忆详情 register_memory_retrieval_tool( name="get_chat_history_detail", - description="根据记忆ID,展示某条或某几条记忆的具体内容。包括主题、时间、参与人、关键词、概括、关键信息点和原文内容等详细信息。需要先使用search_chat_history工具获取记忆ID。", + description="根据记忆ID,展示某条或某几条记忆的具体内容。包括主题、时间、参与人、关键词、概括和关键信息点等详细信息。需要先使用search_chat_history工具获取记忆ID。", parameters=[ { "name": "memory_ids", diff --git a/src/webui/expression_routes.py b/src/webui/expression_routes.py index f92219ab..bef93b30 100644 --- a/src/webui/expression_routes.py +++ b/src/webui/expression_routes.py @@ -5,7 +5,6 @@ from pydantic import BaseModel from typing import Optional, List, Dict from src.common.logger import get_logger from src.common.database.database_model import Expression, ChatStreams -from .token_manager import get_token_manager from .auth import verify_auth_token_from_cookie_or_header import time diff --git a/src/webui/jargon_routes.py b/src/webui/jargon_routes.py index 51012267..318912e8 100644 --- a/src/webui/jargon_routes.py +++ b/src/webui/jargon_routes.py @@ -1,7 +1,7 @@ """黑话(俚语)管理路由""" import json -from typing import Optional, List +from typing import Optional, List, Annotated from fastapi import APIRouter, HTTPException, Query from pydantic import BaseModel, Field from peewee import fn @@ -331,19 +331,19 @@ async def get_jargon_stats(): total = Jargon.select().count() # 已确认是黑话的数量 - confirmed_jargon = Jargon.select().where(Jargon.is_jargon == True).count() + confirmed_jargon = Jargon.select().where(Jargon.is_jargon).count() # 已确认不是黑话的数量 - confirmed_not_jargon = Jargon.select().where(Jargon.is_jargon == False).count() + confirmed_not_jargon = Jargon.select().where(~Jargon.is_jargon).count() # 未判定的数量 pending = Jargon.select().where(Jargon.is_jargon.is_null()).count() # 全局黑话数量 - global_count = Jargon.select().where(Jargon.is_global == True).count() + global_count = Jargon.select().where(Jargon.is_global).count() # 已完成推断的数量 - complete_count = Jargon.select().where(Jargon.is_complete == True).count() + complete_count = Jargon.select().where(Jargon.is_complete).count() # 关联的聊天数量 chat_count = ( @@ -519,8 +519,8 @@ async def batch_delete_jargons(request: BatchDeleteRequest): @router.post("/batch/set-jargon", response_model=JargonUpdateResponse) async def batch_set_jargon_status( - ids: List[int] = Query(..., description="黑话ID列表"), - is_jargon: bool = Query(..., description="是否是黑话"), + ids: Annotated[List[int], Query(description="黑话ID列表")], + is_jargon: Annotated[bool, Query(description="是否是黑话")], ): """批量设置黑话状态""" try: diff --git a/src/webui/person_routes.py b/src/webui/person_routes.py index 0b70a3a2..5c039371 100644 --- a/src/webui/person_routes.py +++ b/src/webui/person_routes.py @@ -5,7 +5,6 @@ from pydantic import BaseModel from typing import Optional, List, Dict from src.common.logger import get_logger from src.common.database.database_model import PersonInfo -from .token_manager import get_token_manager from .auth import verify_auth_token_from_cookie_or_header import json import time diff --git a/src/webui/routers/system.py b/src/webui/routers/system.py index 7499c06d..d6932896 100644 --- a/src/webui/routers/system.py +++ b/src/webui/routers/system.py @@ -5,7 +5,6 @@ """ import os -import sys import time from datetime import datetime from fastapi import APIRouter, HTTPException diff --git a/webui/dist/assets/index-DuFwC87p.js b/webui/dist/assets/index-DJb_iiTR.js similarity index 92% rename from webui/dist/assets/index-DuFwC87p.js rename to webui/dist/assets/index-DJb_iiTR.js index ee71a6a6..886bc66f 100644 --- a/webui/dist/assets/index-DuFwC87p.js +++ b/webui/dist/assets/index-DJb_iiTR.js @@ -12,7 +12,7 @@ ${c.map(([x,f])=>{const j=f.theme?.[d]||f.color;return j?` --color-${x}: ${j};` `)} } `).join(` -`)}}):null},ir=UN,ti=u.forwardRef(({active:n,payload:i,className:c,indicator:d="dot",hideLabel:h=!1,hideIndicator:x=!1,label:f,labelFormatter:j,labelClassName:p,formatter:w,color:v,nameKey:y,labelKey:S},C)=>{const{config:M}=vg(),F=u.useMemo(()=>{if(h||!i?.length)return null;const[O]=i,K=`${S||O?.dataKey||O?.name||"value"}`,H=Lu(M,O,K),A=!S&&typeof f=="string"?M[f]?.label||f:H?.label;return j?e.jsx("div",{className:$("font-medium",p),children:j(A,i)}):A?e.jsx("div",{className:$("font-medium",p),children:A}):null},[f,j,i,h,p,M,S]);if(!n||!i?.length)return null;const U=i.length===1&&d!=="dot";return e.jsxs("div",{ref:C,className:$("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",c),children:[U?null:F,e.jsx("div",{className:"grid gap-1.5",children:i.filter(O=>O.type!=="none").map((O,K)=>{const H=`${y||O.name||O.dataKey||"value"}`,A=Lu(M,O,H),V=v||O.payload.fill||O.color;return e.jsx("div",{className:$("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",d==="dot"&&"items-center"),children:w&&O?.value!==void 0&&O.name?w(O.value,O.name,O,K,O.payload):e.jsxs(e.Fragment,{children:[A?.icon?e.jsx(A.icon,{}):!x&&e.jsx("div",{className:$("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":d==="dot","w-1":d==="line","w-0 border-[1.5px] border-dashed bg-transparent":d==="dashed","my-0.5":U&&d==="dashed"}),style:{"--color-bg":V,"--color-border":V}}),e.jsxs("div",{className:$("flex flex-1 justify-between leading-none",U?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[U?F:null,e.jsx("span",{className:"text-muted-foreground",children:A?.label||O.name})]}),O.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:O.value.toLocaleString()})]})]})},O.dataKey)})})]})});ti.displayName="ChartTooltip";const ky=BN,Ng=u.forwardRef(({className:n,hideIcon:i=!1,payload:c,verticalAlign:d="bottom",nameKey:h},x)=>{const{config:f}=vg();return c?.length?e.jsx("div",{ref:x,className:$("flex items-center justify-center gap-4",d==="top"?"pb-3":"pt-3",n),children:c.filter(j=>j.type!=="none").map(j=>{const p=`${h||j.dataKey||"value"}`,w=Lu(f,j,p);return e.jsxs("div",{className:$("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[w?.icon&&!i?e.jsx(w.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:j.color}}),w?.label]},j.value)})}):null});Ng.displayName="ChartLegend";function Lu(n,i,c){if(typeof i!="object"||i===null)return;const d="payload"in i&&typeof i.payload=="object"&&i.payload!==null?i.payload:void 0;let h=c;return c in i&&typeof i[c]=="string"?h=i[c]:d&&c in d&&typeof d[c]=="string"&&(h=d[c]),h in n?n[h]:n[c]}const gr=ci("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),N=u.forwardRef(({className:n,variant:i,size:c,asChild:d=!1,...h},x)=>{const f=d?$N:"button";return e.jsx(f,{className:$(gr({variant:i,size:c,className:n})),ref:x,...h})});N.displayName="Button";const Ty=ci("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ye({className:n,variant:i,...c}){return e.jsx("div",{className:$(Ty({variant:i}),n),...c})}const Ey=5,zy=5e3;let ku=0;function Ay(){return ku=(ku+1)%Number.MAX_SAFE_INTEGER,ku.toString()}const Tu=new Map,ep=n=>{if(Tu.has(n))return;const i=setTimeout(()=>{Tu.delete(n),hr({type:"REMOVE_TOAST",toastId:n})},zy);Tu.set(n,i)},My=(n,i)=>{switch(i.type){case"ADD_TOAST":return{...n,toasts:[i.toast,...n.toasts].slice(0,Ey)};case"UPDATE_TOAST":return{...n,toasts:n.toasts.map(c=>c.id===i.toast.id?{...c,...i.toast}:c)};case"DISMISS_TOAST":{const{toastId:c}=i;return c?ep(c):n.toasts.forEach(d=>{ep(d.id)}),{...n,toasts:n.toasts.map(d=>d.id===c||c===void 0?{...d,open:!1}:d)}}case"REMOVE_TOAST":return i.toastId===void 0?{...n,toasts:[]}:{...n,toasts:n.toasts.filter(c=>c.id!==i.toastId)}}},Kc=[];let Jc={toasts:[]};function hr(n){Jc=My(Jc,n),Kc.forEach(i=>{i(Jc)})}function Dy({...n}){const i=Ay(),c=h=>hr({type:"UPDATE_TOAST",toast:{...h,id:i}}),d=()=>hr({type:"DISMISS_TOAST",toastId:i});return hr({type:"ADD_TOAST",toast:{...n,id:i,open:!0,onOpenChange:h=>{h||d()}}}),{id:i,dismiss:d,update:c}}function Gs(){const[n,i]=u.useState(Jc);return u.useEffect(()=>(Kc.push(i),()=>{const c=Kc.indexOf(i);c>-1&&Kc.splice(c,1)}),[n]),{...n,toast:Dy,dismiss:c=>hr({type:"DISMISS_TOAST",toastId:c})}}const Oy=n=>{const i=[];for(let c=0;c{try{C(!0);const k=await Bc.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");y({hitokoto:k.data.hitokoto,from:k.data.from||k.data.from_who||"未知"})}catch(k){console.error("获取一言失败:",k),y({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{C(!1)}},[]),A=u.useCallback(async()=>{try{const k=localStorage.getItem("access-token"),se=await Bc.get("/api/webui/system/status",{headers:{Authorization:`Bearer ${k}`}});F(se.data)}catch(k){console.error("获取机器人状态失败:",k),F(null)}},[]),V=async()=>{if(!U)try{O(!0);const k=localStorage.getItem("access-token");await Bc.post("/api/webui/system/restart",{},{headers:{Authorization:`Bearer ${k}`}}),K({title:"重启中",description:"麦麦正在重启,请稍候..."}),setTimeout(()=>{A(),O(!1)},3e3)}catch(k){console.error("重启失败:",k),K({title:"重启失败",description:"无法重启麦麦,请检查控制台",variant:"destructive"}),O(!1)}},Q=u.useCallback(async()=>{try{const k=localStorage.getItem("access-token"),se=await Bc.get(`/api/webui/statistics/dashboard?hours=${f}`,{headers:{Authorization:`Bearer ${k}`}});i(se.data),d(!1),x(100)}catch(k){console.error("Failed to fetch dashboard data:",k),d(!1),x(100)}},[f]);if(u.useEffect(()=>{if(!c)return;x(0);const k=setTimeout(()=>x(15),200),se=setTimeout(()=>x(30),800),_=setTimeout(()=>x(45),2e3),ue=setTimeout(()=>x(60),4e3),ie=setTimeout(()=>x(75),6500),ae=setTimeout(()=>x(85),9e3),fe=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(k),clearTimeout(se),clearTimeout(_),clearTimeout(ue),clearTimeout(ie),clearTimeout(ae),clearTimeout(fe)}},[c]),u.useEffect(()=>{Q(),H(),A()},[Q,H,A]),u.useEffect(()=>{if(!p)return;const k=setInterval(()=>{Q(),A()},3e4);return()=>clearInterval(k)},[p,Q,A]),c||!n)return e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-200px)]",children:e.jsxs("div",{className:"text-center space-y-6 w-full max-w-md px-4",children:[e.jsx(Ct,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-lg font-medium",children:"加载统计数据中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取麦麦运行数据"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(wr,{value:h,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h,"%"]})]})]})});const{summary:T,model_stats:D=[],hourly_data:ne=[],daily_data:xe=[],recent_activity:_e=[]}=n,Se=T??{total_requests:0,total_cost:0,total_tokens:0,online_time:0,total_messages:0,total_replies:0,avg_response_time:0,cost_per_hour:0,tokens_per_hour:0},ge=k=>{const se=Math.floor(k/3600),_=Math.floor(k%3600/60);return`${se}小时${_}分钟`},ye=k=>new Date(k).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),be=Oy(D.length),z=D.map((k,se)=>({name:k.model_name,value:k.request_count,fill:be[se]})),X={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(ss,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(La,{value:f.toString(),onValueChange:k=>j(Number(k)),children:e.jsxs(wa,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(fs,{value:"24",children:"24小时"}),e.jsx(fs,{value:"168",children:"7天"}),e.jsx(fs,{value:"720",children:"30天"})]})}),e.jsxs(N,{variant:p?"default":"outline",size:"sm",onClick:()=>w(!p),className:"gap-2",children:[e.jsx(Ct,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(N,{variant:"outline",size:"sm",onClick:Q,children:e.jsx(Ct,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-lg border border-dashed border-muted-foreground/30 bg-muted/20",children:[S?e.jsx(gg,{className:"h-5 flex-1"}):v?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',v.hitokoto,'" —— ',v.from]}):null,e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:H,disabled:S,children:e.jsx(Ct,{className:`h-3.5 w-3.5 ${S?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ze,{className:"lg:col-span-1",children:[e.jsx(ys,{className:"pb-3",children:e.jsxs(ws,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(br,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(Ts,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:M?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(Ye,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(fa,{className:"h-3 w-3 mr-1"}),"运行中"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-red-500"}),e.jsxs(Ye,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(Oa,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),M&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",M.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",ge(M.uptime)]})]})]})})]}),e.jsxs(Ze,{className:"lg:col-span-2",children:[e.jsx(ys,{className:"pb-3",children:e.jsxs(ws,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(cn,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(Ts,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:V,disabled:U,className:"gap-2",children:[e.jsx(Zc,{className:`h-4 w-4 ${U?"animate-spin":""}`}),U?"重启中...":"重启麦麦"]}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/logs",children:[e.jsx(Da,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/plugins",children:[e.jsx(cb,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/settings",children:[e.jsx(oi,{className:"h-4 w-4"}),"系统设置"]})})]})})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(ob,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-2xl font-bold",children:Se.total_requests.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",f<48?f+"小时":Math.floor(f/24)+"天"]})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"总花费"}),e.jsx(db,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Se.total_cost.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:Se.cost_per_hour>0?`¥${Se.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Ic,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[(Se.total_tokens/1e3).toFixed(1),"K"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:Se.tokens_per_hour>0?`${(Se.tokens_per_hour/1e3).toFixed(1)}K/小时`:"暂无数据"})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(cn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[Se.avg_response_time.toFixed(2),"s"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"API平均耗时"})]})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-3",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(li,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Ts,{children:e.jsx("div",{className:"text-xl font-bold",children:ge(Se.online_time)})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(un,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-xl font-bold",children:Se.total_messages.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",Se.total_replies.toLocaleString()," 条"]})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(ub,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-xl font-bold",children:Se.total_messages>0?`¥${(Se.total_cost/Se.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(La,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(fs,{value:"trends",children:"趋势"}),e.jsx(fs,{value:"models",children:"模型"}),e.jsx(fs,{value:"activity",children:"活动"}),e.jsx(fs,{value:"daily",children:"日统计"})]}),e.jsxs(Ms,{value:"trends",className:"space-y-4",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"请求趋势"}),e.jsxs(ct,{children:["最近",f,"小时的请求量变化"]})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(HN,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(qN,{type:"monotone",dataKey:"requests",stroke:"var(--color-requests)",strokeWidth:2})]})})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"花费趋势"}),e.jsx(ct,{children:"API调用成本变化"})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(bu,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(Gc,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"Token消耗"}),e.jsx(ct,{children:"Token使用量变化"})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(bu,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(Gc,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(Ms,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"模型请求分布"}),e.jsxs(ct,{children:["各模型使用占比 (共 ",D.length," 个模型)"]})]}),e.jsx(Ts,{children:e.jsx(si,{config:Object.fromEntries(D.map((k,se)=>[k.model_name,{label:k.model_name,color:be[se]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(GN,{children:[e.jsx(ir,{content:e.jsx(ti,{})}),e.jsx(VN,{data:z,cx:"50%",cy:"50%",labelLine:!1,label:({name:k,percent:se})=>se&&se<.05?"":`${k} ${se?(se*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:z.map((k,se)=>e.jsx(FN,{fill:k.fill},`cell-${se}`))})]})})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"模型详细统计"}),e.jsx(ct,{children:"请求数、花费和性能"})]}),e.jsx(Ts,{children:e.jsx(ss,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:D.map((k,se)=>e.jsxs("div",{className:"p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"font-semibold text-sm truncate flex-1 min-w-0",children:k.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${se%5+1}))`}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"请求数:"}),e.jsx("span",{className:"ml-1 font-medium",children:k.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",k.total_cost.toFixed(2)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[(k.total_tokens/1e3).toFixed(1),"K"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"平均耗时:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[k.avg_response_time.toFixed(2),"s"]})]})]})]},se))})})})]})]})}),e.jsx(Ms,{value:"activity",children:e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"最近活动"}),e.jsx(ct,{children:"最新的API调用记录"})]}),e.jsx(Ts,{children:e.jsx(ss,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:_e.map((k,se)=>e.jsxs("div",{className:"p-3 sm:p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:k.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:k.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:ye(k.timestamp)})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsx("span",{className:"ml-1",children:k.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",k.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[k.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${k.status==="success"?"text-green-600":"text-red-600"}`,children:k.status})]})]})]},se))})})})]})}),e.jsx(Ms,{value:"daily",children:e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"每日统计"}),e.jsx(ct,{children:"最近7天的数据汇总"})]}),e.jsx(Ts,{children:e.jsx(si,{config:{requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"}},className:"h-[400px] sm:h-[500px] w-full aspect-auto",children:e.jsxs(bu,{data:xe,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>{const se=new Date(k);return`${se.getMonth()+1}/${se.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>new Date(k).toLocaleDateString("zh-CN")})}),e.jsx(ky,{content:e.jsx(Ng,{})}),e.jsx(Gc,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Gc,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]})]})})}const Ly={theme:"system",setTheme:()=>null},bg=u.createContext(Ly),$u=()=>{const n=u.useContext(bg);if(n===void 0)throw new Error("useTheme must be used within a ThemeProvider");return n},Uy=(n,i,c)=>{const d=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||d){i(n);return}const h=c.clientX,x=c.clientY,f=Math.hypot(Math.max(h,innerWidth-h),Math.max(x,innerHeight-x));document.startViewTransition(()=>{i(n)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${x}px)`,`circle(${f}px at ${h}px ${x}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},yg=u.createContext(void 0),wg=()=>{const n=u.useContext(yg);if(n===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return n},Xe=u.forwardRef(({className:n,...i},c)=>e.jsx(Cp,{className:$("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",n),...i,ref:c,children:e.jsx(wN,{className:$("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Xe.displayName=Cp.displayName;const By=ci("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),b=u.forwardRef(({className:n,...i},c)=>e.jsx(Hp,{ref:c,className:$(By(),n),...i}));b.displayName=Hp.displayName;const oe=u.forwardRef(({className:n,type:i,...c},d)=>e.jsx("input",{type:i,className:$("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:d,...c}));oe.displayName="Input";const Hy=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:n=>n.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:n=>/[A-Z]/.test(n)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:n=>/[a-z]/.test(n)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:n=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(n)}];function qy(n){const i=Hy.map(d=>({id:d.id,label:d.label,description:d.description,passed:d.validate(n)}));return{isValid:i.every(d=>d.passed),rules:i}}const Qu="0.11.6 Beta",Yu="MaiBot Dashboard",Gy=`${Yu} v${Qu}`,Vy=(n="v")=>`${n}${Qu}`,Ft={THEME:"maibot-ui-theme",ACCENT_COLOR:"accent-color",ENABLE_ANIMATIONS:"maibot-animations",ENABLE_WAVES_BACKGROUND:"maibot-waves-background",LOG_CACHE_SIZE:"maibot-log-cache-size",LOG_AUTO_SCROLL:"maibot-log-auto-scroll",LOG_FONT_SIZE:"maibot-log-font-size",LOG_LINE_SPACING:"maibot-log-line-spacing",DATA_SYNC_INTERVAL:"maibot-data-sync-interval",WS_RECONNECT_INTERVAL:"maibot-ws-reconnect-interval",WS_MAX_RECONNECT_ATTEMPTS:"maibot-ws-max-reconnect-attempts",COMPLETED_TOURS:"maibot-completed-tours"},Aa={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function st(n){const i=_g(n),c=localStorage.getItem(i);if(c===null)return Aa[n];const d=Aa[n];if(typeof d=="boolean")return c==="true";if(typeof d=="number"){const h=parseFloat(c);return isNaN(h)?d:h}return c}function ai(n,i){const c=_g(n);localStorage.setItem(c,String(i)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:n,value:i}}))}function Fy(){return{theme:st("theme"),accentColor:st("accentColor"),enableAnimations:st("enableAnimations"),enableWavesBackground:st("enableWavesBackground"),logCacheSize:st("logCacheSize"),logAutoScroll:st("logAutoScroll"),logFontSize:st("logFontSize"),logLineSpacing:st("logLineSpacing"),dataSyncInterval:st("dataSyncInterval"),wsReconnectInterval:st("wsReconnectInterval"),wsMaxReconnectAttempts:st("wsMaxReconnectAttempts")}}function $y(){const n=Fy(),i=localStorage.getItem(Ft.COMPLETED_TOURS),c=i?JSON.parse(i):[];return{...n,completedTours:c}}function Qy(n){const i=[],c=[];for(const[d,h]of Object.entries(n)){if(d==="completedTours"){Array.isArray(h)?(localStorage.setItem(Ft.COMPLETED_TOURS,JSON.stringify(h)),i.push("completedTours")):c.push("completedTours");continue}if(d in Aa){const x=d,f=Aa[x];if(typeof h==typeof f){if(x==="theme"&&!["light","dark","system"].includes(h)){c.push(d);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(h)){c.push(d);continue}ai(x,h),i.push(d)}else c.push(d)}else c.push(d)}return{success:i.length>0,imported:i,skipped:c}}function Yy(){for(const n of Object.keys(Aa))ai(n,Aa[n]);localStorage.removeItem(Ft.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function Xy(){const n=[],i=[],c=[];for(let d=0;dd.size-c.size),{used:n,items:localStorage.length,details:i}}function Ky(n){if(n===0)return"0 B";const i=1024,c=["B","KB","MB"],d=Math.floor(Math.log(n)/Math.log(i));return parseFloat((n/Math.pow(i,d)).toFixed(2))+" "+c[d]}function _g(n){return{theme:Ft.THEME,accentColor:Ft.ACCENT_COLOR,enableAnimations:Ft.ENABLE_ANIMATIONS,enableWavesBackground:Ft.ENABLE_WAVES_BACKGROUND,logCacheSize:Ft.LOG_CACHE_SIZE,logAutoScroll:Ft.LOG_AUTO_SCROLL,logFontSize:Ft.LOG_FONT_SIZE,logLineSpacing:Ft.LOG_LINE_SPACING,dataSyncInterval:Ft.DATA_SYNC_INTERVAL,wsReconnectInterval:Ft.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:Ft.WS_MAX_RECONNECT_ATTEMPTS}[n]}const Ma=u.forwardRef(({className:n,...i},c)=>e.jsxs(kp,{ref:c,className:$("relative flex w-full touch-none select-none items-center",n),...i,children:[e.jsx(_N,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(SN,{className:"absolute h-full bg-primary"})}),e.jsx(CN,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Ma.displayName=kp.displayName;class Jy{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return st("logCacheSize")}getMaxReconnectAttempts(){return st("wsMaxReconnectAttempts")}getReconnectInterval(){return st("wsReconnectInterval")}getWebSocketUrl(){{const i=window.location.protocol==="https:"?"wss:":"ws:",c=window.location.host;return`${i}//${c}/ws/logs`}}connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;const i=this.getWebSocketUrl();try{this.ws=new WebSocket(i),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=c=>{try{if(c.data==="pong")return;const d=JSON.parse(c.data);this.notifyLog(d)}catch(d){console.error("解析日志消息失败:",d)}},this.ws.onerror=c=>{console.error("❌ WebSocket 错误:",c),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(c){console.error("创建 WebSocket 连接失败:",c),this.attemptReconnect()}}attemptReconnect(){const i=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=i)return;this.reconnectAttempts+=1;const c=this.getReconnectInterval(),d=Math.min(c*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},d)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(i){return this.logCallbacks.add(i),()=>this.logCallbacks.delete(i)}onConnectionChange(i){return this.connectionCallbacks.add(i),i(this.isConnected),()=>this.connectionCallbacks.delete(i)}notifyLog(i){if(!this.logCache.some(d=>d.id===i.id)){this.logCache.push(i);const d=this.getMaxCacheSize();this.logCache.length>d&&(this.logCache=this.logCache.slice(-d)),this.logCallbacks.forEach(h=>{try{h(i)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(i){this.connectionCallbacks.forEach(c=>{try{c(i)}catch(d){console.error("连接状态回调执行失败:",d)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const rn=new Jy;typeof window<"u"&&rn.connect();const $s=XN,Xu=KN,Zy=QN,Sg=u.forwardRef(({className:n,...i},c)=>e.jsx(qp,{ref:c,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...i}));Sg.displayName=qp.displayName;const Bs=u.forwardRef(({className:n,children:i,preventOutsideClose:c=!1,...d},h)=>e.jsxs(Zy,{children:[e.jsx(Sg,{}),e.jsxs(Gp,{ref:h,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),onPointerDownOutside:c?x=>x.preventDefault():void 0,onInteractOutside:c?x=>x.preventDefault():void 0,...d,children:[i,e.jsxs(YN,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(dl,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bs.displayName=Gp.displayName;const Hs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",n),...i});Hs.displayName="DialogHeader";const at=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...i});at.displayName="DialogFooter";const qs=u.forwardRef(({className:n,...i},c)=>e.jsx(Vp,{ref:c,className:$("text-lg font-semibold leading-none tracking-tight",n),...i}));qs.displayName=Vp.displayName;const Is=u.forwardRef(({className:n,...i},c)=>e.jsx(Fp,{ref:c,className:$("text-sm text-muted-foreground",n),...i}));Is.displayName=Fp.displayName;const ps=TN,tt=EN,Iy=kN,Cg=u.forwardRef(({className:n,...i},c)=>e.jsx(Tp,{className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...i,ref:c}));Cg.displayName=Tp.displayName;const is=u.forwardRef(({className:n,...i},c)=>e.jsxs(Iy,{children:[e.jsx(Cg,{}),e.jsx(Ep,{ref:c,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),...i})]}));is.displayName=Ep.displayName;const rs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col space-y-2 text-center sm:text-left",n),...i});rs.displayName="AlertDialogHeader";const cs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...i});cs.displayName="AlertDialogFooter";const os=u.forwardRef(({className:n,...i},c)=>e.jsx(zp,{ref:c,className:$("text-lg font-semibold",n),...i}));os.displayName=zp.displayName;const ds=u.forwardRef(({className:n,...i},c)=>e.jsx(Ap,{ref:c,className:$("text-sm text-muted-foreground",n),...i}));ds.displayName=Ap.displayName;const us=u.forwardRef(({className:n,...i},c)=>e.jsx(Mp,{ref:c,className:$(gr(),n),...i}));us.displayName=Mp.displayName;const ms=u.forwardRef(({className:n,...i},c)=>e.jsx(Dp,{ref:c,className:$(gr({variant:"outline"}),"mt-2 sm:mt-0",n),...i}));ms.displayName=Dp.displayName;function Py(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"系统设置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理您的应用偏好设置"})]})}),e.jsxs(La,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(fs,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(mb,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(fs,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(hb,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(fs,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(oi,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(fs,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ra,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(ss,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(Ms,{value:"appearance",className:"mt-0",children:e.jsx(Wy,{})}),e.jsx(Ms,{value:"security",className:"mt-0",children:e.jsx(e0,{})}),e.jsx(Ms,{value:"other",className:"mt-0",children:e.jsx(s0,{})}),e.jsx(Ms,{value:"about",className:"mt-0",children:e.jsx(t0,{})})]})]})]})}function tp(n){const i=document.documentElement,d={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[n];if(d)i.style.setProperty("--primary",d.hsl),d.gradient?(i.style.setProperty("--primary-gradient",d.gradient),i.classList.add("has-gradient")):(i.style.removeProperty("--primary-gradient"),i.classList.remove("has-gradient"));else if(n.startsWith("#")){const h=x=>{x=x.replace("#","");const f=parseInt(x.substring(0,2),16)/255,j=parseInt(x.substring(2,4),16)/255,p=parseInt(x.substring(4,6),16)/255,w=Math.max(f,j,p),v=Math.min(f,j,p);let y=0,S=0;const C=(w+v)/2;if(w!==v){const M=w-v;switch(S=C>.5?M/(2-w-v):M/(w+v),w){case f:y=((j-p)/M+(jlocalStorage.getItem("accent-color")||"blue");u.useEffect(()=>{const w=localStorage.getItem("accent-color")||"blue";tp(w)},[]);const p=w=>{j(w),localStorage.setItem("accent-color",w),tp(w)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(Eu,{value:"light",current:n,onChange:i,label:"浅色",description:"始终使用浅色主题"}),e.jsx(Eu,{value:"dark",current:n,onChange:i,label:"深色",description:"始终使用深色主题"}),e.jsx(Eu,{value:"system",current:n,onChange:i,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(xa,{value:"blue",current:f,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(xa,{value:"purple",current:f,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(xa,{value:"green",current:f,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(xa,{value:"orange",current:f,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(xa,{value:"pink",current:f,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(xa,{value:"red",current:f,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(xa,{value:"gradient-sunset",current:f,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(xa,{value:"gradient-ocean",current:f,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(xa,{value:"gradient-forest",current:f,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(xa,{value:"gradient-aurora",current:f,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(xa,{value:"gradient-fire",current:f,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(xa,{value:"gradient-twilight",current:f,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:f.startsWith("#")?f:"#3b82f6",onChange:w=>p(w.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(oe,{type:"text",value:f,onChange:w=>p(w.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(b,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Xe,{id:"animations",checked:c,onCheckedChange:d})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(b,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Xe,{id:"waves-background",checked:h,onCheckedChange:x})]})})]})]})]})}function e0(){const n=ga(),[i,c]=u.useState(""),[d,h]=u.useState(""),[x,f]=u.useState(!1),[j,p]=u.useState(!1),[w,v]=u.useState(!1),[y,S]=u.useState(!1),[C,M]=u.useState(!1),[F,U]=u.useState(!1),[O,K]=u.useState(""),[H,A]=u.useState(!1),{toast:V}=Gs(),Q=u.useMemo(()=>qy(d),[d]),T=async ge=>{if(!i){V({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(ge),M(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>M(!1),2e3)}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},D=async()=>{if(!d.trim()){V({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!Q.isValid){const ge=Q.rules.filter(ye=>!ye.passed).map(ye=>ye.label).join(", ");V({title:"格式错误",description:`Token 不符合要求: ${ge}`,variant:"destructive"});return}v(!0);try{const ge=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:d.trim()})}),ye=await ge.json();ge.ok&&ye.success?(h(""),c(d.trim()),V({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{n({to:"/auth"})},1500)):V({title:"更新失败",description:ye.message||"无法更新 Token",variant:"destructive"})}catch(ge){console.error("更新 Token 错误:",ge),V({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{v(!1)}},ne=async()=>{S(!0);try{const ge=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),ye=await ge.json();ge.ok&&ye.success?(c(ye.token),K(ye.token),U(!0),A(!1),V({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):V({title:"生成失败",description:ye.message||"无法生成新 Token",variant:"destructive"})}catch(ge){console.error("生成 Token 错误:",ge),V({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{S(!1)}},xe=async()=>{try{await navigator.clipboard.writeText(O),A(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},_e=()=>{U(!1),setTimeout(()=>{K(""),A(!1)},300),setTimeout(()=>{n({to:"/auth"})},500)},Se=ge=>{ge||_e()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx($s,{open:F,onOpenChange:Se,children:e.jsxs(Bs,{className:"sm:max-w-md",children:[e.jsxs(Hs,{children:[e.jsxs(qs,{className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Is,{children:"这是您的新 Token,请立即保存。关闭此窗口后将跳转到登录页面。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border-2 border-primary/20 bg-primary/5 p-4",children:[e.jsx(b,{className:"text-xs text-muted-foreground mb-2 block",children:"您的新 Token (64位安全令牌)"}),e.jsx("div",{className:"font-mono text-sm break-all select-all bg-background p-3 rounded border",children:O})]}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ya,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"重要提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"此 Token 仅显示一次,关闭后无法再查看"}),e.jsx("li",{children:"请立即复制并保存到安全的位置"}),e.jsx("li",{children:"关闭窗口后将自动跳转到登录页面"}),e.jsx("li",{children:"请使用新 Token 重新登录系统"})]})]})]})})]}),e.jsxs(at,{className:"gap-2 sm:gap-0",children:[e.jsx(N,{variant:"outline",onClick:xe,className:"gap-2",children:H?e.jsxs(e.Fragment,{children:[e.jsx(sa,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Pc,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(N,{onClick:_e,children:"我已保存,关闭"})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"当前 Access Token"}),e.jsx("div",{className:"space-y-3 sm:space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"current-token",className:"text-sm",children:"您的访问令牌"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{id:"current-token",type:x?"text":"password",value:i||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{i?f(!x):V({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:x?"隐藏":"显示",children:x?e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(N,{variant:"outline",size:"icon",onClick:()=>T(i),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!i,children:C?e.jsx(sa,{className:"h-4 w-4 text-green-500"}):e.jsx(Pc,{className:"h-4 w-4"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",disabled:y,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(Ct,{className:$("h-4 w-4",y&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重新生成 Token"}),e.jsx(ds,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:ne,children:"确认生成"})]})]})]})]})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground",children:"请妥善保管您的 Access Token,不要泄露给他人"})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"自定义 Access Token"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(oe,{id:"new-token",type:j?"text":"password",value:d,onChange:ge=>h(ge.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:j?"隐藏":"显示",children:j?e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})})]}),d&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:Q.rules.map(ge=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[ge.passed?e.jsx(fa,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(ng,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:$(ge.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:ge.label})]},ge.id))}),Q.isValid&&e.jsx("div",{className:"mt-2 pt-2 border-t border-border",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(N,{onClick:D,disabled:w||!Q.isValid||!d,className:"w-full sm:w-auto",children:w?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function s0(){const n=ga(),{toast:i}=Gs(),[c,d]=u.useState(!1),[h,x]=u.useState(!1),[f,j]=u.useState(()=>st("logCacheSize")),[p,w]=u.useState(()=>st("wsReconnectInterval")),[v,y]=u.useState(()=>st("wsMaxReconnectAttempts")),[S,C]=u.useState(()=>st("dataSyncInterval")),[M,F]=u.useState(()=>sp()),[U,O]=u.useState(!1),[K,H]=u.useState(!1),A=u.useRef(null);if(h)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const V=()=>{F(sp())},Q=z=>{const X=z[0];j(X),ai("logCacheSize",X)},T=z=>{const X=z[0];w(X),ai("wsReconnectInterval",X)},D=z=>{const X=z[0];y(X),ai("wsMaxReconnectAttempts",X)},ne=z=>{const X=z[0];C(X),ai("dataSyncInterval",X)},xe=()=>{rn.clearLogs(),i({title:"日志已清除",description:"日志缓存已清空"})},_e=()=>{const z=Xy();V(),i({title:"缓存已清除",description:`已清除 ${z.clearedKeys.length} 项缓存数据`})},Se=()=>{O(!0);try{const z=$y(),X=JSON.stringify(z,null,2),k=new Blob([X],{type:"application/json"}),se=URL.createObjectURL(k),_=document.createElement("a");_.href=se,_.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(se),i({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(z){console.error("导出设置失败:",z),i({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{O(!1)}},ge=z=>{const X=z.target.files?.[0];if(!X)return;H(!0);const k=new FileReader;k.onload=se=>{try{const _=se.target?.result,ue=JSON.parse(_),ie=Qy(ue);ie.success?(j(st("logCacheSize")),w(st("wsReconnectInterval")),y(st("wsMaxReconnectAttempts")),C(st("dataSyncInterval")),V(),i({title:"导入成功",description:`成功导入 ${ie.imported.length} 项设置${ie.skipped.length>0?`,跳过 ${ie.skipped.length} 项`:""}`}),(ie.imported.includes("theme")||ie.imported.includes("accentColor"))&&i({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):i({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(_){console.error("导入设置失败:",_),i({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{H(!1),A.current&&(A.current.value="")}},k.readAsText(X)},ye=()=>{Yy(),j(Aa.logCacheSize),w(Aa.wsReconnectInterval),y(Aa.wsMaxReconnectAttempts),C(Aa.dataSyncInterval),V(),i({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},be=async()=>{d(!0);try{const z=localStorage.getItem("access-token"),X=await fetch("/api/webui/setup/reset",{method:"POST",headers:{Authorization:`Bearer ${z}`}}),k=await X.json();X.ok&&k.success?(i({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{n({to:"/setup"})},1e3)):i({title:"重置失败",description:k.message||"无法重置配置状态",variant:"destructive"})}catch(z){console.error("重置配置状态错误:",z),i({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{d(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Ic,{className:"h-5 w-5"}),"性能与存储"]}),e.jsxs("div",{className:"space-y-4 sm:space-y-5",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(xb,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:V,className:"h-7 px-2",children:e.jsx(Ct,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:Ky(M.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[M.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f," 条"]})]}),e.jsx(Ma,{value:[f],onValueChange:Q,min:100,max:5e3,step:100,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制日志查看器最多缓存的日志条数,较大的值会占用更多内存"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[S," 秒"]})]}),e.jsx(Ma,{value:[S],onValueChange:ne,min:10,max:120,step:5,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制首页统计数据的自动刷新间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Ma,{value:[p],onValueChange:T,min:1e3,max:1e4,step:500,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"日志 WebSocket 连接断开后的重连基础间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v," 次"]})]}),e.jsx(Ma,{value:[v],onValueChange:D,min:3,max:30,step:1,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"连接失败后的最大重连尝试次数"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:xe,className:"gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认清除本地缓存"}),e.jsx(ds,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:_e,children:"确认清除"})]})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(rl,{className:"h-5 w-5"}),"导入/导出设置"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"导出当前的界面设置以便备份,或从之前导出的文件中恢复设置。"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(N,{variant:"outline",onClick:Se,disabled:U,className:"gap-2",children:[e.jsx(rl,{className:"h-4 w-4"}),U?"导出中...":"导出设置"]}),e.jsx("input",{ref:A,type:"file",accept:".json",onChange:ge,className:"hidden"}),e.jsxs(N,{variant:"outline",onClick:()=>A.current?.click(),disabled:K,className:"gap-2",children:[e.jsx(fr,{className:"h-4 w-4"}),K?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(Zc,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重置所有设置"}),e.jsx(ds,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:ye,children:"确认重置"})]})]})]})})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"配置向导"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"重新进行初次配置向导,可以帮助您重新设置系统的基础配置。"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",disabled:c,className:"gap-2",children:[e.jsx(Zc,{className:$("h-4 w-4",c&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重新配置"}),e.jsx(ds,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:be,children:"确认重置"})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dashed border-yellow-500/50 bg-yellow-500/5 p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"开发者工具"]}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"以下功能仅供开发调试使用,可能会导致页面崩溃或异常。"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"destructive",className:"gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认触发错误"}),e.jsx(ds,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function t0(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"rounded-lg border-2 border-primary/30 bg-gradient-to-r from-primary/5 to-primary/10 p-4 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-shrink-0 rounded-lg bg-primary/10 p-2 sm:p-3",children:e.jsx("svg",{className:"h-6 w-6 sm:h-8 sm:w-8 text-primary",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-bold text-foreground mb-2",children:"开源项目"}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mb-3",children:"本项目在 GitHub 开源,欢迎 Star ⭐ 支持!"}),e.jsxs("a",{href:"https://github.com/Mai-with-u/MaiBot-Dashboard",target:"_blank",rel:"noopener noreferrer",className:$("inline-flex items-center gap-2 px-4 py-2 rounded-lg","bg-primary text-primary-foreground font-medium text-sm","hover:bg-primary/90 transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),children:[e.jsx("svg",{className:"h-4 w-4",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})}),"前往 GitHub",e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:["关于 ",Yu]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",Qu]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(ss,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(Zs,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(Zs,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(Zs,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(Zs,{name:"Lucide React",description:"精美的图标库",license:"ISC"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"路由与状态管理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(Zs,{name:"Zustand",description:"轻量级状态管理",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"表单处理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(Zs,{name:"Zod",description:"TypeScript 优先的 schema 验证",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"工具库"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(Zs,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(Zs,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(Zs,{name:"date-fns",description:"现代化日期处理库",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"动画效果"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(Zs,{name:"vaul",description:"抽屉组件动画",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"后端框架"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(Zs,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(Zs,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(Zs,{name:"python-multipart",description:"文件上传支持",license:"Apache-2.0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"开发工具"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(Zs,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(Zs,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(Zs,{name:"PostCSS",description:"CSS 转换工具",license:"MIT"})]})]})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源许可"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/5 border border-primary/20 p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:"rounded-md bg-primary/10 px-2 py-1",children:e.jsx("span",{className:"text-xs sm:text-sm font-bold text-primary",children:"GPLv3"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm sm:text-base font-semibold text-foreground mb-1",children:"MaiBot WebUI"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目采用 GNU General Public License v3.0 开源许可证。 您可以自由地使用、修改和分发本软件,但必须保持相同的开源许可。"})]})]})}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目依赖的所有开源库均遵循各自的开源许可证(MIT、Apache-2.0、BSD 等)。 感谢所有开源贡献者的无私奉献。"})]})]})]})}function Zs({name:n,description:i,license:c}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:n}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:i})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:c})]})}function Eu({value:n,current:i,onChange:c,label:d,description:h}){const x=i===n;return e.jsxs("button",{onClick:()=>c(n),className:$("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:d}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:h})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[n==="light"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-200"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-300"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-400"})]}),n==="dark"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-900"})]}),n==="system"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-200 to-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-300 to-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-400 to-slate-900"})]})]})]})}function xa({value:n,current:i,onChange:c,label:d,colorClass:h}){const x=i===n;return e.jsxs("button",{onClick:()=>c(n),className:$("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-1.5 right-1.5 sm:top-2 sm:right-2 h-1.5 w-1.5 sm:h-2 sm:w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5 sm:gap-2",children:[e.jsx("div",{className:$("h-8 w-8 sm:h-10 sm:w-10 rounded-full",h)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:d})]})]})}class a0{grad3;p;perm;constructor(i=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let c=0;c<256;c++)this.p[c]=Math.floor(Math.random()*256);this.perm=[];for(let c=0;c<512;c++)this.perm[c]=this.p[c&255]}dot(i,c,d){return i[0]*c+i[1]*d}mix(i,c,d){return(1-d)*i+d*c}fade(i){return i*i*i*(i*(i*6-15)+10)}perlin2(i,c){const d=Math.floor(i)&255,h=Math.floor(c)&255;i-=Math.floor(i),c-=Math.floor(c);const x=this.fade(i),f=this.fade(c),j=this.perm[d]+h,p=this.perm[j],w=this.perm[j+1],v=this.perm[d+1]+h,y=this.perm[v],S=this.perm[v+1];return this.mix(this.mix(this.dot(this.grad3[p%12],i,c),this.dot(this.grad3[y%12],i-1,c),x),this.mix(this.dot(this.grad3[w%12],i,c-1),this.dot(this.grad3[S%12],i-1,c-1),x),f)}}function ap(){const n=u.useRef(null),i=u.useRef(null),c=u.useRef(void 0),d=u.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:new a0(Math.random()),bounding:null});return u.useEffect(()=>{const h=i.current,x=n.current;if(!h||!x)return;const f=d.current,j=()=>{const F=h.getBoundingClientRect();f.bounding=F,x.style.width=`${F.width}px`,x.style.height=`${F.height}px`},p=()=>{if(!f.bounding)return;const{width:F,height:U}=f.bounding;f.lines=[],f.paths.forEach(ne=>ne.remove()),f.paths=[];const O=10,K=32,H=F+200,A=U+30,V=Math.ceil(H/O),Q=Math.ceil(A/K),T=(F-O*V)/2,D=(U-K*Q)/2;for(let ne=0;ne<=V;ne++){const xe=[];for(let Se=0;Se<=Q;Se++){const ge={x:T+O*ne,y:D+K*Se,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};xe.push(ge)}const _e=document.createElementNS("http://www.w3.org/2000/svg","path");x.appendChild(_e),f.paths.push(_e),f.lines.push(xe)}},w=F=>{const{lines:U,mouse:O,noise:K}=f;U.forEach(H=>{H.forEach(A=>{const V=K.perlin2((A.x+F*.0125)*.002,(A.y+F*.005)*.0015)*12;A.wave.x=Math.cos(V)*32,A.wave.y=Math.sin(V)*16;const Q=A.x-O.sx,T=A.y-O.sy,D=Math.hypot(Q,T),ne=Math.max(175,O.vs);if(D{const O={x:F.x+F.wave.x+(U?F.cursor.x:0),y:F.y+F.wave.y+(U?F.cursor.y:0)};return O.x=Math.round(O.x*10)/10,O.y=Math.round(O.y*10)/10,O},y=()=>{const{lines:F,paths:U}=f;F.forEach((O,K)=>{let H=v(O[0],!1),A=`M ${H.x} ${H.y}`;O.forEach((V,Q)=>{const T=Q===O.length-1;H=v(V,!T),A+=`L ${H.x} ${H.y}`}),U[K].setAttribute("d",A)})},S=F=>{const{mouse:U}=f;U.sx+=(U.x-U.sx)*.1,U.sy+=(U.y-U.sy)*.1;const O=U.x-U.lx,K=U.y-U.ly,H=Math.hypot(O,K);U.v=H,U.vs+=(H-U.vs)*.1,U.vs=Math.min(100,U.vs),U.lx=U.x,U.ly=U.y,U.a=Math.atan2(K,O),h&&(h.style.setProperty("--x",`${U.sx}px`),h.style.setProperty("--y",`${U.sy}px`)),w(F),y(),c.current=requestAnimationFrame(S)},C=F=>{if(!f.bounding)return;const{mouse:U}=f;U.x=F.pageX-f.bounding.left,U.y=F.pageY-f.bounding.top+window.scrollY,U.set||(U.sx=U.x,U.sy=U.y,U.lx=U.x,U.ly=U.y,U.set=!0)},M=()=>{j(),p()};return j(),p(),window.addEventListener("resize",M),window.addEventListener("mousemove",C),c.current=requestAnimationFrame(S),()=>{window.removeEventListener("resize",M),window.removeEventListener("mousemove",C),c.current&&cancelAnimationFrame(c.current)}},[]),e.jsxs("div",{ref:i,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:n,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` +`)}}):null},ir=UN,ti=u.forwardRef(({active:n,payload:i,className:c,indicator:d="dot",hideLabel:h=!1,hideIndicator:x=!1,label:f,labelFormatter:j,labelClassName:p,formatter:w,color:v,nameKey:y,labelKey:S},C)=>{const{config:M}=vg(),F=u.useMemo(()=>{if(h||!i?.length)return null;const[O]=i,K=`${S||O?.dataKey||O?.name||"value"}`,H=Lu(M,O,K),A=!S&&typeof f=="string"?M[f]?.label||f:H?.label;return j?e.jsx("div",{className:$("font-medium",p),children:j(A,i)}):A?e.jsx("div",{className:$("font-medium",p),children:A}):null},[f,j,i,h,p,M,S]);if(!n||!i?.length)return null;const U=i.length===1&&d!=="dot";return e.jsxs("div",{ref:C,className:$("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",c),children:[U?null:F,e.jsx("div",{className:"grid gap-1.5",children:i.filter(O=>O.type!=="none").map((O,K)=>{const H=`${y||O.name||O.dataKey||"value"}`,A=Lu(M,O,H),V=v||O.payload.fill||O.color;return e.jsx("div",{className:$("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",d==="dot"&&"items-center"),children:w&&O?.value!==void 0&&O.name?w(O.value,O.name,O,K,O.payload):e.jsxs(e.Fragment,{children:[A?.icon?e.jsx(A.icon,{}):!x&&e.jsx("div",{className:$("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":d==="dot","w-1":d==="line","w-0 border-[1.5px] border-dashed bg-transparent":d==="dashed","my-0.5":U&&d==="dashed"}),style:{"--color-bg":V,"--color-border":V}}),e.jsxs("div",{className:$("flex flex-1 justify-between leading-none",U?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[U?F:null,e.jsx("span",{className:"text-muted-foreground",children:A?.label||O.name})]}),O.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:O.value.toLocaleString()})]})]})},O.dataKey)})})]})});ti.displayName="ChartTooltip";const ky=BN,Ng=u.forwardRef(({className:n,hideIcon:i=!1,payload:c,verticalAlign:d="bottom",nameKey:h},x)=>{const{config:f}=vg();return c?.length?e.jsx("div",{ref:x,className:$("flex items-center justify-center gap-4",d==="top"?"pb-3":"pt-3",n),children:c.filter(j=>j.type!=="none").map(j=>{const p=`${h||j.dataKey||"value"}`,w=Lu(f,j,p);return e.jsxs("div",{className:$("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[w?.icon&&!i?e.jsx(w.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:j.color}}),w?.label]},j.value)})}):null});Ng.displayName="ChartLegend";function Lu(n,i,c){if(typeof i!="object"||i===null)return;const d="payload"in i&&typeof i.payload=="object"&&i.payload!==null?i.payload:void 0;let h=c;return c in i&&typeof i[c]=="string"?h=i[c]:d&&c in d&&typeof d[c]=="string"&&(h=d[c]),h in n?n[h]:n[c]}const gr=ci("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),N=u.forwardRef(({className:n,variant:i,size:c,asChild:d=!1,...h},x)=>{const f=d?$N:"button";return e.jsx(f,{className:$(gr({variant:i,size:c,className:n})),ref:x,...h})});N.displayName="Button";const Ty=ci("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ye({className:n,variant:i,...c}){return e.jsx("div",{className:$(Ty({variant:i}),n),...c})}const Ey=5,zy=5e3;let ku=0;function Ay(){return ku=(ku+1)%Number.MAX_SAFE_INTEGER,ku.toString()}const Tu=new Map,ep=n=>{if(Tu.has(n))return;const i=setTimeout(()=>{Tu.delete(n),hr({type:"REMOVE_TOAST",toastId:n})},zy);Tu.set(n,i)},My=(n,i)=>{switch(i.type){case"ADD_TOAST":return{...n,toasts:[i.toast,...n.toasts].slice(0,Ey)};case"UPDATE_TOAST":return{...n,toasts:n.toasts.map(c=>c.id===i.toast.id?{...c,...i.toast}:c)};case"DISMISS_TOAST":{const{toastId:c}=i;return c?ep(c):n.toasts.forEach(d=>{ep(d.id)}),{...n,toasts:n.toasts.map(d=>d.id===c||c===void 0?{...d,open:!1}:d)}}case"REMOVE_TOAST":return i.toastId===void 0?{...n,toasts:[]}:{...n,toasts:n.toasts.filter(c=>c.id!==i.toastId)}}},Kc=[];let Jc={toasts:[]};function hr(n){Jc=My(Jc,n),Kc.forEach(i=>{i(Jc)})}function Dy({...n}){const i=Ay(),c=h=>hr({type:"UPDATE_TOAST",toast:{...h,id:i}}),d=()=>hr({type:"DISMISS_TOAST",toastId:i});return hr({type:"ADD_TOAST",toast:{...n,id:i,open:!0,onOpenChange:h=>{h||d()}}}),{id:i,dismiss:d,update:c}}function Gs(){const[n,i]=u.useState(Jc);return u.useEffect(()=>(Kc.push(i),()=>{const c=Kc.indexOf(i);c>-1&&Kc.splice(c,1)}),[n]),{...n,toast:Dy,dismiss:c=>hr({type:"DISMISS_TOAST",toastId:c})}}const Oy=n=>{const i=[];for(let c=0;c{try{C(!0);const k=await Bc.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");y({hitokoto:k.data.hitokoto,from:k.data.from||k.data.from_who||"未知"})}catch(k){console.error("获取一言失败:",k),y({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{C(!1)}},[]),A=u.useCallback(async()=>{try{const k=localStorage.getItem("access-token"),se=await Bc.get("/api/webui/system/status",{headers:{Authorization:`Bearer ${k}`}});F(se.data)}catch(k){console.error("获取机器人状态失败:",k),F(null)}},[]),V=async()=>{if(!U)try{O(!0);const k=localStorage.getItem("access-token");await Bc.post("/api/webui/system/restart",{},{headers:{Authorization:`Bearer ${k}`}}),K({title:"重启中",description:"麦麦正在重启,请稍候..."}),setTimeout(()=>{A(),O(!1)},3e3)}catch(k){console.error("重启失败:",k),K({title:"重启失败",description:"无法重启麦麦,请检查控制台",variant:"destructive"}),O(!1)}},Q=u.useCallback(async()=>{try{const k=localStorage.getItem("access-token"),se=await Bc.get(`/api/webui/statistics/dashboard?hours=${f}`,{headers:{Authorization:`Bearer ${k}`}});i(se.data),d(!1),x(100)}catch(k){console.error("Failed to fetch dashboard data:",k),d(!1),x(100)}},[f]);if(u.useEffect(()=>{if(!c)return;x(0);const k=setTimeout(()=>x(15),200),se=setTimeout(()=>x(30),800),_=setTimeout(()=>x(45),2e3),ue=setTimeout(()=>x(60),4e3),ie=setTimeout(()=>x(75),6500),ae=setTimeout(()=>x(85),9e3),fe=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(k),clearTimeout(se),clearTimeout(_),clearTimeout(ue),clearTimeout(ie),clearTimeout(ae),clearTimeout(fe)}},[c]),u.useEffect(()=>{Q(),H(),A()},[Q,H,A]),u.useEffect(()=>{if(!p)return;const k=setInterval(()=>{Q(),A()},3e4);return()=>clearInterval(k)},[p,Q,A]),c||!n)return e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-200px)]",children:e.jsxs("div",{className:"text-center space-y-6 w-full max-w-md px-4",children:[e.jsx(Ct,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-lg font-medium",children:"加载统计数据中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取麦麦运行数据"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(wr,{value:h,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h,"%"]})]})]})});const{summary:T,model_stats:D=[],hourly_data:ne=[],daily_data:xe=[],recent_activity:_e=[]}=n,Se=T??{total_requests:0,total_cost:0,total_tokens:0,online_time:0,total_messages:0,total_replies:0,avg_response_time:0,cost_per_hour:0,tokens_per_hour:0},ge=k=>{const se=Math.floor(k/3600),_=Math.floor(k%3600/60);return`${se}小时${_}分钟`},ye=k=>new Date(k).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),be=Oy(D.length),z=D.map((k,se)=>({name:k.model_name,value:k.request_count,fill:be[se]})),X={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(ss,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(La,{value:f.toString(),onValueChange:k=>j(Number(k)),children:e.jsxs(wa,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(fs,{value:"24",children:"24小时"}),e.jsx(fs,{value:"168",children:"7天"}),e.jsx(fs,{value:"720",children:"30天"})]})}),e.jsxs(N,{variant:p?"default":"outline",size:"sm",onClick:()=>w(!p),className:"gap-2",children:[e.jsx(Ct,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(N,{variant:"outline",size:"sm",onClick:Q,children:e.jsx(Ct,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-lg border border-dashed border-muted-foreground/30 bg-muted/20",children:[S?e.jsx(gg,{className:"h-5 flex-1"}):v?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',v.hitokoto,'" —— ',v.from]}):null,e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:H,disabled:S,children:e.jsx(Ct,{className:`h-3.5 w-3.5 ${S?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ze,{className:"lg:col-span-1",children:[e.jsx(ys,{className:"pb-3",children:e.jsxs(ws,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(br,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(Ts,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:M?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(Ye,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(fa,{className:"h-3 w-3 mr-1"}),"运行中"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-red-500"}),e.jsxs(Ye,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(Oa,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),M&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",M.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",ge(M.uptime)]})]})]})})]}),e.jsxs(Ze,{className:"lg:col-span-2",children:[e.jsx(ys,{className:"pb-3",children:e.jsxs(ws,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(cn,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(Ts,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:V,disabled:U,className:"gap-2",children:[e.jsx(Zc,{className:`h-4 w-4 ${U?"animate-spin":""}`}),U?"重启中...":"重启麦麦"]}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/logs",children:[e.jsx(Da,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/plugins",children:[e.jsx(cb,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(N,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Yc,{to:"/settings",children:[e.jsx(oi,{className:"h-4 w-4"}),"系统设置"]})})]})})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(ob,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-2xl font-bold",children:Se.total_requests.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",f<48?f+"小时":Math.floor(f/24)+"天"]})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"总花费"}),e.jsx(db,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["¥",Se.total_cost.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:Se.cost_per_hour>0?`¥${Se.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Ic,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[(Se.total_tokens/1e3).toFixed(1),"K"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:Se.tokens_per_hour>0?`${(Se.tokens_per_hour/1e3).toFixed(1)}K/小时`:"暂无数据"})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(cn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[Se.avg_response_time.toFixed(2),"s"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"API平均耗时"})]})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-3",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(li,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Ts,{children:e.jsx("div",{className:"text-xl font-bold",children:ge(Se.online_time)})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(un,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-xl font-bold",children:Se.total_messages.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",Se.total_replies.toLocaleString()," 条"]})]})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ws,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(ub,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ts,{children:[e.jsx("div",{className:"text-xl font-bold",children:Se.total_messages>0?`¥${(Se.total_cost/Se.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(La,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(fs,{value:"trends",children:"趋势"}),e.jsx(fs,{value:"models",children:"模型"}),e.jsx(fs,{value:"activity",children:"活动"}),e.jsx(fs,{value:"daily",children:"日统计"})]}),e.jsxs(Ms,{value:"trends",className:"space-y-4",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"请求趋势"}),e.jsxs(ct,{children:["最近",f,"小时的请求量变化"]})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(HN,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(qN,{type:"monotone",dataKey:"requests",stroke:"var(--color-requests)",strokeWidth:2})]})})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"花费趋势"}),e.jsx(ct,{children:"API调用成本变化"})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(bu,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(Gc,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"Token消耗"}),e.jsx(ct,{children:"Token使用量变化"})]}),e.jsx(Ts,{children:e.jsx(si,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(bu,{data:ne,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>ye(k),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>ye(k)})}),e.jsx(Gc,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(Ms,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"模型请求分布"}),e.jsxs(ct,{children:["各模型使用占比 (共 ",D.length," 个模型)"]})]}),e.jsx(Ts,{children:e.jsx(si,{config:Object.fromEntries(D.map((k,se)=>[k.model_name,{label:k.model_name,color:be[se]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(GN,{children:[e.jsx(ir,{content:e.jsx(ti,{})}),e.jsx(VN,{data:z,cx:"50%",cy:"50%",labelLine:!1,label:({name:k,percent:se})=>se&&se<.05?"":`${k} ${se?(se*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:z.map((k,se)=>e.jsx(FN,{fill:k.fill},`cell-${se}`))})]})})})]}),e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"模型详细统计"}),e.jsx(ct,{children:"请求数、花费和性能"})]}),e.jsx(Ts,{children:e.jsx(ss,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:D.map((k,se)=>e.jsxs("div",{className:"p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"font-semibold text-sm truncate flex-1 min-w-0",children:k.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${se%5+1}))`}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"请求数:"}),e.jsx("span",{className:"ml-1 font-medium",children:k.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",k.total_cost.toFixed(2)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[(k.total_tokens/1e3).toFixed(1),"K"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"平均耗时:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[k.avg_response_time.toFixed(2),"s"]})]})]})]},se))})})})]})]})}),e.jsx(Ms,{value:"activity",children:e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"最近活动"}),e.jsx(ct,{children:"最新的API调用记录"})]}),e.jsx(Ts,{children:e.jsx(ss,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:_e.map((k,se)=>e.jsxs("div",{className:"p-3 sm:p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:k.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:k.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:ye(k.timestamp)})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsx("span",{className:"ml-1",children:k.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",k.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[k.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${k.status==="success"?"text-green-600":"text-red-600"}`,children:k.status})]})]})]},se))})})})]})}),e.jsx(Ms,{value:"daily",children:e.jsxs(Ze,{children:[e.jsxs(ys,{children:[e.jsx(ws,{children:"每日统计"}),e.jsx(ct,{children:"最近7天的数据汇总"})]}),e.jsx(Ts,{children:e.jsx(si,{config:{requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"}},className:"h-[400px] sm:h-[500px] w-full aspect-auto",children:e.jsxs(bu,{data:xe,children:[e.jsx(Hc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(qc,{dataKey:"timestamp",tickFormatter:k=>{const se=new Date(k);return`${se.getMonth()+1}/${se.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(lr,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ir,{content:e.jsx(ti,{labelFormatter:k=>new Date(k).toLocaleDateString("zh-CN")})}),e.jsx(ky,{content:e.jsx(Ng,{})}),e.jsx(Gc,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Gc,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]})]})})}const Ly={theme:"system",setTheme:()=>null},bg=u.createContext(Ly),$u=()=>{const n=u.useContext(bg);if(n===void 0)throw new Error("useTheme must be used within a ThemeProvider");return n},Uy=(n,i,c)=>{const d=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||d){i(n);return}const h=c.clientX,x=c.clientY,f=Math.hypot(Math.max(h,innerWidth-h),Math.max(x,innerHeight-x));document.startViewTransition(()=>{i(n)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${x}px)`,`circle(${f}px at ${h}px ${x}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},yg=u.createContext(void 0),wg=()=>{const n=u.useContext(yg);if(n===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return n},Xe=u.forwardRef(({className:n,...i},c)=>e.jsx(Cp,{className:$("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",n),...i,ref:c,children:e.jsx(wN,{className:$("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Xe.displayName=Cp.displayName;const By=ci("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),b=u.forwardRef(({className:n,...i},c)=>e.jsx(Hp,{ref:c,className:$(By(),n),...i}));b.displayName=Hp.displayName;const oe=u.forwardRef(({className:n,type:i,...c},d)=>e.jsx("input",{type:i,className:$("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:d,...c}));oe.displayName="Input";const Hy=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:n=>n.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:n=>/[A-Z]/.test(n)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:n=>/[a-z]/.test(n)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:n=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(n)}];function qy(n){const i=Hy.map(d=>({id:d.id,label:d.label,description:d.description,passed:d.validate(n)}));return{isValid:i.every(d=>d.passed),rules:i}}const Qu="0.11.6",Yu="MaiBot Dashboard",Gy=`${Yu} v${Qu}`,Vy=(n="v")=>`${n}${Qu}`,Ft={THEME:"maibot-ui-theme",ACCENT_COLOR:"accent-color",ENABLE_ANIMATIONS:"maibot-animations",ENABLE_WAVES_BACKGROUND:"maibot-waves-background",LOG_CACHE_SIZE:"maibot-log-cache-size",LOG_AUTO_SCROLL:"maibot-log-auto-scroll",LOG_FONT_SIZE:"maibot-log-font-size",LOG_LINE_SPACING:"maibot-log-line-spacing",DATA_SYNC_INTERVAL:"maibot-data-sync-interval",WS_RECONNECT_INTERVAL:"maibot-ws-reconnect-interval",WS_MAX_RECONNECT_ATTEMPTS:"maibot-ws-max-reconnect-attempts",COMPLETED_TOURS:"maibot-completed-tours"},Aa={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function st(n){const i=_g(n),c=localStorage.getItem(i);if(c===null)return Aa[n];const d=Aa[n];if(typeof d=="boolean")return c==="true";if(typeof d=="number"){const h=parseFloat(c);return isNaN(h)?d:h}return c}function ai(n,i){const c=_g(n);localStorage.setItem(c,String(i)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:n,value:i}}))}function Fy(){return{theme:st("theme"),accentColor:st("accentColor"),enableAnimations:st("enableAnimations"),enableWavesBackground:st("enableWavesBackground"),logCacheSize:st("logCacheSize"),logAutoScroll:st("logAutoScroll"),logFontSize:st("logFontSize"),logLineSpacing:st("logLineSpacing"),dataSyncInterval:st("dataSyncInterval"),wsReconnectInterval:st("wsReconnectInterval"),wsMaxReconnectAttempts:st("wsMaxReconnectAttempts")}}function $y(){const n=Fy(),i=localStorage.getItem(Ft.COMPLETED_TOURS),c=i?JSON.parse(i):[];return{...n,completedTours:c}}function Qy(n){const i=[],c=[];for(const[d,h]of Object.entries(n)){if(d==="completedTours"){Array.isArray(h)?(localStorage.setItem(Ft.COMPLETED_TOURS,JSON.stringify(h)),i.push("completedTours")):c.push("completedTours");continue}if(d in Aa){const x=d,f=Aa[x];if(typeof h==typeof f){if(x==="theme"&&!["light","dark","system"].includes(h)){c.push(d);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(h)){c.push(d);continue}ai(x,h),i.push(d)}else c.push(d)}else c.push(d)}return{success:i.length>0,imported:i,skipped:c}}function Yy(){for(const n of Object.keys(Aa))ai(n,Aa[n]);localStorage.removeItem(Ft.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function Xy(){const n=[],i=[],c=[];for(let d=0;dd.size-c.size),{used:n,items:localStorage.length,details:i}}function Ky(n){if(n===0)return"0 B";const i=1024,c=["B","KB","MB"],d=Math.floor(Math.log(n)/Math.log(i));return parseFloat((n/Math.pow(i,d)).toFixed(2))+" "+c[d]}function _g(n){return{theme:Ft.THEME,accentColor:Ft.ACCENT_COLOR,enableAnimations:Ft.ENABLE_ANIMATIONS,enableWavesBackground:Ft.ENABLE_WAVES_BACKGROUND,logCacheSize:Ft.LOG_CACHE_SIZE,logAutoScroll:Ft.LOG_AUTO_SCROLL,logFontSize:Ft.LOG_FONT_SIZE,logLineSpacing:Ft.LOG_LINE_SPACING,dataSyncInterval:Ft.DATA_SYNC_INTERVAL,wsReconnectInterval:Ft.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:Ft.WS_MAX_RECONNECT_ATTEMPTS}[n]}const Ma=u.forwardRef(({className:n,...i},c)=>e.jsxs(kp,{ref:c,className:$("relative flex w-full touch-none select-none items-center",n),...i,children:[e.jsx(_N,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(SN,{className:"absolute h-full bg-primary"})}),e.jsx(CN,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Ma.displayName=kp.displayName;class Jy{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return st("logCacheSize")}getMaxReconnectAttempts(){return st("wsMaxReconnectAttempts")}getReconnectInterval(){return st("wsReconnectInterval")}getWebSocketUrl(){{const i=window.location.protocol==="https:"?"wss:":"ws:",c=window.location.host;return`${i}//${c}/ws/logs`}}connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;const i=this.getWebSocketUrl();try{this.ws=new WebSocket(i),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=c=>{try{if(c.data==="pong")return;const d=JSON.parse(c.data);this.notifyLog(d)}catch(d){console.error("解析日志消息失败:",d)}},this.ws.onerror=c=>{console.error("❌ WebSocket 错误:",c),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(c){console.error("创建 WebSocket 连接失败:",c),this.attemptReconnect()}}attemptReconnect(){const i=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=i)return;this.reconnectAttempts+=1;const c=this.getReconnectInterval(),d=Math.min(c*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},d)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(i){return this.logCallbacks.add(i),()=>this.logCallbacks.delete(i)}onConnectionChange(i){return this.connectionCallbacks.add(i),i(this.isConnected),()=>this.connectionCallbacks.delete(i)}notifyLog(i){if(!this.logCache.some(d=>d.id===i.id)){this.logCache.push(i);const d=this.getMaxCacheSize();this.logCache.length>d&&(this.logCache=this.logCache.slice(-d)),this.logCallbacks.forEach(h=>{try{h(i)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(i){this.connectionCallbacks.forEach(c=>{try{c(i)}catch(d){console.error("连接状态回调执行失败:",d)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const rn=new Jy;typeof window<"u"&&rn.connect();const $s=XN,Xu=KN,Zy=QN,Sg=u.forwardRef(({className:n,...i},c)=>e.jsx(qp,{ref:c,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...i}));Sg.displayName=qp.displayName;const Bs=u.forwardRef(({className:n,children:i,preventOutsideClose:c=!1,...d},h)=>e.jsxs(Zy,{children:[e.jsx(Sg,{}),e.jsxs(Gp,{ref:h,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),onPointerDownOutside:c?x=>x.preventDefault():void 0,onInteractOutside:c?x=>x.preventDefault():void 0,...d,children:[i,e.jsxs(YN,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(dl,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bs.displayName=Gp.displayName;const Hs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",n),...i});Hs.displayName="DialogHeader";const at=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...i});at.displayName="DialogFooter";const qs=u.forwardRef(({className:n,...i},c)=>e.jsx(Vp,{ref:c,className:$("text-lg font-semibold leading-none tracking-tight",n),...i}));qs.displayName=Vp.displayName;const Is=u.forwardRef(({className:n,...i},c)=>e.jsx(Fp,{ref:c,className:$("text-sm text-muted-foreground",n),...i}));Is.displayName=Fp.displayName;const ps=TN,tt=EN,Iy=kN,Cg=u.forwardRef(({className:n,...i},c)=>e.jsx(Tp,{className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...i,ref:c}));Cg.displayName=Tp.displayName;const is=u.forwardRef(({className:n,...i},c)=>e.jsxs(Iy,{children:[e.jsx(Cg,{}),e.jsx(Ep,{ref:c,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),...i})]}));is.displayName=Ep.displayName;const rs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col space-y-2 text-center sm:text-left",n),...i});rs.displayName="AlertDialogHeader";const cs=({className:n,...i})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...i});cs.displayName="AlertDialogFooter";const os=u.forwardRef(({className:n,...i},c)=>e.jsx(zp,{ref:c,className:$("text-lg font-semibold",n),...i}));os.displayName=zp.displayName;const ds=u.forwardRef(({className:n,...i},c)=>e.jsx(Ap,{ref:c,className:$("text-sm text-muted-foreground",n),...i}));ds.displayName=Ap.displayName;const us=u.forwardRef(({className:n,...i},c)=>e.jsx(Mp,{ref:c,className:$(gr(),n),...i}));us.displayName=Mp.displayName;const ms=u.forwardRef(({className:n,...i},c)=>e.jsx(Dp,{ref:c,className:$(gr({variant:"outline"}),"mt-2 sm:mt-0",n),...i}));ms.displayName=Dp.displayName;function Py(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"系统设置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理您的应用偏好设置"})]})}),e.jsxs(La,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(fs,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(mb,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(fs,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(hb,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(fs,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(oi,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(fs,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ra,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(ss,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(Ms,{value:"appearance",className:"mt-0",children:e.jsx(Wy,{})}),e.jsx(Ms,{value:"security",className:"mt-0",children:e.jsx(e0,{})}),e.jsx(Ms,{value:"other",className:"mt-0",children:e.jsx(s0,{})}),e.jsx(Ms,{value:"about",className:"mt-0",children:e.jsx(t0,{})})]})]})]})}function tp(n){const i=document.documentElement,d={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[n];if(d)i.style.setProperty("--primary",d.hsl),d.gradient?(i.style.setProperty("--primary-gradient",d.gradient),i.classList.add("has-gradient")):(i.style.removeProperty("--primary-gradient"),i.classList.remove("has-gradient"));else if(n.startsWith("#")){const h=x=>{x=x.replace("#","");const f=parseInt(x.substring(0,2),16)/255,j=parseInt(x.substring(2,4),16)/255,p=parseInt(x.substring(4,6),16)/255,w=Math.max(f,j,p),v=Math.min(f,j,p);let y=0,S=0;const C=(w+v)/2;if(w!==v){const M=w-v;switch(S=C>.5?M/(2-w-v):M/(w+v),w){case f:y=((j-p)/M+(jlocalStorage.getItem("accent-color")||"blue");u.useEffect(()=>{const w=localStorage.getItem("accent-color")||"blue";tp(w)},[]);const p=w=>{j(w),localStorage.setItem("accent-color",w),tp(w)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(Eu,{value:"light",current:n,onChange:i,label:"浅色",description:"始终使用浅色主题"}),e.jsx(Eu,{value:"dark",current:n,onChange:i,label:"深色",description:"始终使用深色主题"}),e.jsx(Eu,{value:"system",current:n,onChange:i,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(xa,{value:"blue",current:f,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(xa,{value:"purple",current:f,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(xa,{value:"green",current:f,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(xa,{value:"orange",current:f,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(xa,{value:"pink",current:f,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(xa,{value:"red",current:f,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(xa,{value:"gradient-sunset",current:f,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(xa,{value:"gradient-ocean",current:f,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(xa,{value:"gradient-forest",current:f,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(xa,{value:"gradient-aurora",current:f,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(xa,{value:"gradient-fire",current:f,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(xa,{value:"gradient-twilight",current:f,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:f.startsWith("#")?f:"#3b82f6",onChange:w=>p(w.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(oe,{type:"text",value:f,onChange:w=>p(w.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(b,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Xe,{id:"animations",checked:c,onCheckedChange:d})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(b,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Xe,{id:"waves-background",checked:h,onCheckedChange:x})]})})]})]})]})}function e0(){const n=ga(),[i,c]=u.useState(""),[d,h]=u.useState(""),[x,f]=u.useState(!1),[j,p]=u.useState(!1),[w,v]=u.useState(!1),[y,S]=u.useState(!1),[C,M]=u.useState(!1),[F,U]=u.useState(!1),[O,K]=u.useState(""),[H,A]=u.useState(!1),{toast:V}=Gs(),Q=u.useMemo(()=>qy(d),[d]),T=async ge=>{if(!i){V({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(ge),M(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>M(!1),2e3)}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},D=async()=>{if(!d.trim()){V({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!Q.isValid){const ge=Q.rules.filter(ye=>!ye.passed).map(ye=>ye.label).join(", ");V({title:"格式错误",description:`Token 不符合要求: ${ge}`,variant:"destructive"});return}v(!0);try{const ge=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:d.trim()})}),ye=await ge.json();ge.ok&&ye.success?(h(""),c(d.trim()),V({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{n({to:"/auth"})},1500)):V({title:"更新失败",description:ye.message||"无法更新 Token",variant:"destructive"})}catch(ge){console.error("更新 Token 错误:",ge),V({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{v(!1)}},ne=async()=>{S(!0);try{const ge=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),ye=await ge.json();ge.ok&&ye.success?(c(ye.token),K(ye.token),U(!0),A(!1),V({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):V({title:"生成失败",description:ye.message||"无法生成新 Token",variant:"destructive"})}catch(ge){console.error("生成 Token 错误:",ge),V({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{S(!1)}},xe=async()=>{try{await navigator.clipboard.writeText(O),A(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},_e=()=>{U(!1),setTimeout(()=>{K(""),A(!1)},300),setTimeout(()=>{n({to:"/auth"})},500)},Se=ge=>{ge||_e()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx($s,{open:F,onOpenChange:Se,children:e.jsxs(Bs,{className:"sm:max-w-md",children:[e.jsxs(Hs,{children:[e.jsxs(qs,{className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Is,{children:"这是您的新 Token,请立即保存。关闭此窗口后将跳转到登录页面。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border-2 border-primary/20 bg-primary/5 p-4",children:[e.jsx(b,{className:"text-xs text-muted-foreground mb-2 block",children:"您的新 Token (64位安全令牌)"}),e.jsx("div",{className:"font-mono text-sm break-all select-all bg-background p-3 rounded border",children:O})]}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ya,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"重要提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"此 Token 仅显示一次,关闭后无法再查看"}),e.jsx("li",{children:"请立即复制并保存到安全的位置"}),e.jsx("li",{children:"关闭窗口后将自动跳转到登录页面"}),e.jsx("li",{children:"请使用新 Token 重新登录系统"})]})]})]})})]}),e.jsxs(at,{className:"gap-2 sm:gap-0",children:[e.jsx(N,{variant:"outline",onClick:xe,className:"gap-2",children:H?e.jsxs(e.Fragment,{children:[e.jsx(sa,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Pc,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(N,{onClick:_e,children:"我已保存,关闭"})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"当前 Access Token"}),e.jsx("div",{className:"space-y-3 sm:space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"current-token",className:"text-sm",children:"您的访问令牌"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{id:"current-token",type:x?"text":"password",value:i||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{i?f(!x):V({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:x?"隐藏":"显示",children:x?e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(N,{variant:"outline",size:"icon",onClick:()=>T(i),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!i,children:C?e.jsx(sa,{className:"h-4 w-4 text-green-500"}):e.jsx(Pc,{className:"h-4 w-4"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",disabled:y,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(Ct,{className:$("h-4 w-4",y&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重新生成 Token"}),e.jsx(ds,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:ne,children:"确认生成"})]})]})]})]})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground",children:"请妥善保管您的 Access Token,不要泄露给他人"})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"自定义 Access Token"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(oe,{id:"new-token",type:j?"text":"password",value:d,onChange:ge=>h(ge.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:j?"隐藏":"显示",children:j?e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground"})})]}),d&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:Q.rules.map(ge=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[ge.passed?e.jsx(fa,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(ng,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:$(ge.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:ge.label})]},ge.id))}),Q.isValid&&e.jsx("div",{className:"mt-2 pt-2 border-t border-border",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(N,{onClick:D,disabled:w||!Q.isValid||!d,className:"w-full sm:w-auto",children:w?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function s0(){const n=ga(),{toast:i}=Gs(),[c,d]=u.useState(!1),[h,x]=u.useState(!1),[f,j]=u.useState(()=>st("logCacheSize")),[p,w]=u.useState(()=>st("wsReconnectInterval")),[v,y]=u.useState(()=>st("wsMaxReconnectAttempts")),[S,C]=u.useState(()=>st("dataSyncInterval")),[M,F]=u.useState(()=>sp()),[U,O]=u.useState(!1),[K,H]=u.useState(!1),A=u.useRef(null);if(h)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const V=()=>{F(sp())},Q=z=>{const X=z[0];j(X),ai("logCacheSize",X)},T=z=>{const X=z[0];w(X),ai("wsReconnectInterval",X)},D=z=>{const X=z[0];y(X),ai("wsMaxReconnectAttempts",X)},ne=z=>{const X=z[0];C(X),ai("dataSyncInterval",X)},xe=()=>{rn.clearLogs(),i({title:"日志已清除",description:"日志缓存已清空"})},_e=()=>{const z=Xy();V(),i({title:"缓存已清除",description:`已清除 ${z.clearedKeys.length} 项缓存数据`})},Se=()=>{O(!0);try{const z=$y(),X=JSON.stringify(z,null,2),k=new Blob([X],{type:"application/json"}),se=URL.createObjectURL(k),_=document.createElement("a");_.href=se,_.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(se),i({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(z){console.error("导出设置失败:",z),i({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{O(!1)}},ge=z=>{const X=z.target.files?.[0];if(!X)return;H(!0);const k=new FileReader;k.onload=se=>{try{const _=se.target?.result,ue=JSON.parse(_),ie=Qy(ue);ie.success?(j(st("logCacheSize")),w(st("wsReconnectInterval")),y(st("wsMaxReconnectAttempts")),C(st("dataSyncInterval")),V(),i({title:"导入成功",description:`成功导入 ${ie.imported.length} 项设置${ie.skipped.length>0?`,跳过 ${ie.skipped.length} 项`:""}`}),(ie.imported.includes("theme")||ie.imported.includes("accentColor"))&&i({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):i({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(_){console.error("导入设置失败:",_),i({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{H(!1),A.current&&(A.current.value="")}},k.readAsText(X)},ye=()=>{Yy(),j(Aa.logCacheSize),w(Aa.wsReconnectInterval),y(Aa.wsMaxReconnectAttempts),C(Aa.dataSyncInterval),V(),i({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},be=async()=>{d(!0);try{const z=localStorage.getItem("access-token"),X=await fetch("/api/webui/setup/reset",{method:"POST",headers:{Authorization:`Bearer ${z}`}}),k=await X.json();X.ok&&k.success?(i({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{n({to:"/setup"})},1e3)):i({title:"重置失败",description:k.message||"无法重置配置状态",variant:"destructive"})}catch(z){console.error("重置配置状态错误:",z),i({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{d(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Ic,{className:"h-5 w-5"}),"性能与存储"]}),e.jsxs("div",{className:"space-y-4 sm:space-y-5",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(xb,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:V,className:"h-7 px-2",children:e.jsx(Ct,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:Ky(M.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[M.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f," 条"]})]}),e.jsx(Ma,{value:[f],onValueChange:Q,min:100,max:5e3,step:100,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制日志查看器最多缓存的日志条数,较大的值会占用更多内存"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[S," 秒"]})]}),e.jsx(Ma,{value:[S],onValueChange:ne,min:10,max:120,step:5,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制首页统计数据的自动刷新间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Ma,{value:[p],onValueChange:T,min:1e3,max:1e4,step:500,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"日志 WebSocket 连接断开后的重连基础间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(b,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v," 次"]})]}),e.jsx(Ma,{value:[v],onValueChange:D,min:3,max:30,step:1,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"连接失败后的最大重连尝试次数"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:xe,className:"gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认清除本地缓存"}),e.jsx(ds,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:_e,children:"确认清除"})]})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(rl,{className:"h-5 w-5"}),"导入/导出设置"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"导出当前的界面设置以便备份,或从之前导出的文件中恢复设置。"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(N,{variant:"outline",onClick:Se,disabled:U,className:"gap-2",children:[e.jsx(rl,{className:"h-4 w-4"}),U?"导出中...":"导出设置"]}),e.jsx("input",{ref:A,type:"file",accept:".json",onChange:ge,className:"hidden"}),e.jsxs(N,{variant:"outline",onClick:()=>A.current?.click(),disabled:K,className:"gap-2",children:[e.jsx(fr,{className:"h-4 w-4"}),K?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(Zc,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重置所有设置"}),e.jsx(ds,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:ye,children:"确认重置"})]})]})]})})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"配置向导"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"重新进行初次配置向导,可以帮助您重新设置系统的基础配置。"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"outline",disabled:c,className:"gap-2",children:[e.jsx(Zc,{className:$("h-4 w-4",c&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认重新配置"}),e.jsx(ds,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:be,children:"确认重置"})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dashed border-yellow-500/50 bg-yellow-500/5 p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"开发者工具"]}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"以下功能仅供开发调试使用,可能会导致页面崩溃或异常。"})}),e.jsxs(ps,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(N,{variant:"destructive",className:"gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(is,{children:[e.jsxs(rs,{children:[e.jsx(os,{children:"确认触发错误"}),e.jsx(ds,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(cs,{children:[e.jsx(ms,{children:"取消"}),e.jsx(us,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function t0(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"rounded-lg border-2 border-primary/30 bg-gradient-to-r from-primary/5 to-primary/10 p-4 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-shrink-0 rounded-lg bg-primary/10 p-2 sm:p-3",children:e.jsx("svg",{className:"h-6 w-6 sm:h-8 sm:w-8 text-primary",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-bold text-foreground mb-2",children:"开源项目"}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mb-3",children:"本项目在 GitHub 开源,欢迎 Star ⭐ 支持!"}),e.jsxs("a",{href:"https://github.com/Mai-with-u/MaiBot-Dashboard",target:"_blank",rel:"noopener noreferrer",className:$("inline-flex items-center gap-2 px-4 py-2 rounded-lg","bg-primary text-primary-foreground font-medium text-sm","hover:bg-primary/90 transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),children:[e.jsx("svg",{className:"h-4 w-4",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})}),"前往 GitHub",e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:["关于 ",Yu]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",Qu]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(ss,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(Zs,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(Zs,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(Zs,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(Zs,{name:"Lucide React",description:"精美的图标库",license:"ISC"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"路由与状态管理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(Zs,{name:"Zustand",description:"轻量级状态管理",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"表单处理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(Zs,{name:"Zod",description:"TypeScript 优先的 schema 验证",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"工具库"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(Zs,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(Zs,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(Zs,{name:"date-fns",description:"现代化日期处理库",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"动画效果"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(Zs,{name:"vaul",description:"抽屉组件动画",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"后端框架"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(Zs,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(Zs,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(Zs,{name:"python-multipart",description:"文件上传支持",license:"Apache-2.0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"开发工具"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zs,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(Zs,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(Zs,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(Zs,{name:"PostCSS",description:"CSS 转换工具",license:"MIT"})]})]})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源许可"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/5 border border-primary/20 p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:"rounded-md bg-primary/10 px-2 py-1",children:e.jsx("span",{className:"text-xs sm:text-sm font-bold text-primary",children:"GPLv3"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm sm:text-base font-semibold text-foreground mb-1",children:"MaiBot WebUI"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目采用 GNU General Public License v3.0 开源许可证。 您可以自由地使用、修改和分发本软件,但必须保持相同的开源许可。"})]})]})}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目依赖的所有开源库均遵循各自的开源许可证(MIT、Apache-2.0、BSD 等)。 感谢所有开源贡献者的无私奉献。"})]})]})]})}function Zs({name:n,description:i,license:c}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:n}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:i})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:c})]})}function Eu({value:n,current:i,onChange:c,label:d,description:h}){const x=i===n;return e.jsxs("button",{onClick:()=>c(n),className:$("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:d}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:h})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[n==="light"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-200"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-300"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-400"})]}),n==="dark"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-900"})]}),n==="system"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-200 to-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-300 to-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-400 to-slate-900"})]})]})]})}function xa({value:n,current:i,onChange:c,label:d,colorClass:h}){const x=i===n;return e.jsxs("button",{onClick:()=>c(n),className:$("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-1.5 right-1.5 sm:top-2 sm:right-2 h-1.5 w-1.5 sm:h-2 sm:w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5 sm:gap-2",children:[e.jsx("div",{className:$("h-8 w-8 sm:h-10 sm:w-10 rounded-full",h)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:d})]})]})}class a0{grad3;p;perm;constructor(i=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let c=0;c<256;c++)this.p[c]=Math.floor(Math.random()*256);this.perm=[];for(let c=0;c<512;c++)this.perm[c]=this.p[c&255]}dot(i,c,d){return i[0]*c+i[1]*d}mix(i,c,d){return(1-d)*i+d*c}fade(i){return i*i*i*(i*(i*6-15)+10)}perlin2(i,c){const d=Math.floor(i)&255,h=Math.floor(c)&255;i-=Math.floor(i),c-=Math.floor(c);const x=this.fade(i),f=this.fade(c),j=this.perm[d]+h,p=this.perm[j],w=this.perm[j+1],v=this.perm[d+1]+h,y=this.perm[v],S=this.perm[v+1];return this.mix(this.mix(this.dot(this.grad3[p%12],i,c),this.dot(this.grad3[y%12],i-1,c),x),this.mix(this.dot(this.grad3[w%12],i,c-1),this.dot(this.grad3[S%12],i-1,c-1),x),f)}}function ap(){const n=u.useRef(null),i=u.useRef(null),c=u.useRef(void 0),d=u.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:new a0(Math.random()),bounding:null});return u.useEffect(()=>{const h=i.current,x=n.current;if(!h||!x)return;const f=d.current,j=()=>{const F=h.getBoundingClientRect();f.bounding=F,x.style.width=`${F.width}px`,x.style.height=`${F.height}px`},p=()=>{if(!f.bounding)return;const{width:F,height:U}=f.bounding;f.lines=[],f.paths.forEach(ne=>ne.remove()),f.paths=[];const O=10,K=32,H=F+200,A=U+30,V=Math.ceil(H/O),Q=Math.ceil(A/K),T=(F-O*V)/2,D=(U-K*Q)/2;for(let ne=0;ne<=V;ne++){const xe=[];for(let Se=0;Se<=Q;Se++){const ge={x:T+O*ne,y:D+K*Se,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};xe.push(ge)}const _e=document.createElementNS("http://www.w3.org/2000/svg","path");x.appendChild(_e),f.paths.push(_e),f.lines.push(xe)}},w=F=>{const{lines:U,mouse:O,noise:K}=f;U.forEach(H=>{H.forEach(A=>{const V=K.perlin2((A.x+F*.0125)*.002,(A.y+F*.005)*.0015)*12;A.wave.x=Math.cos(V)*32,A.wave.y=Math.sin(V)*16;const Q=A.x-O.sx,T=A.y-O.sy,D=Math.hypot(Q,T),ne=Math.max(175,O.vs);if(D{const O={x:F.x+F.wave.x+(U?F.cursor.x:0),y:F.y+F.wave.y+(U?F.cursor.y:0)};return O.x=Math.round(O.x*10)/10,O.y=Math.round(O.y*10)/10,O},y=()=>{const{lines:F,paths:U}=f;F.forEach((O,K)=>{let H=v(O[0],!1),A=`M ${H.x} ${H.y}`;O.forEach((V,Q)=>{const T=Q===O.length-1;H=v(V,!T),A+=`L ${H.x} ${H.y}`}),U[K].setAttribute("d",A)})},S=F=>{const{mouse:U}=f;U.sx+=(U.x-U.sx)*.1,U.sy+=(U.y-U.sy)*.1;const O=U.x-U.lx,K=U.y-U.ly,H=Math.hypot(O,K);U.v=H,U.vs+=(H-U.vs)*.1,U.vs=Math.min(100,U.vs),U.lx=U.x,U.ly=U.y,U.a=Math.atan2(K,O),h&&(h.style.setProperty("--x",`${U.sx}px`),h.style.setProperty("--y",`${U.sy}px`)),w(F),y(),c.current=requestAnimationFrame(S)},C=F=>{if(!f.bounding)return;const{mouse:U}=f;U.x=F.pageX-f.bounding.left,U.y=F.pageY-f.bounding.top+window.scrollY,U.set||(U.sx=U.x,U.sy=U.y,U.lx=U.x,U.ly=U.y,U.set=!0)},M=()=>{j(),p()};return j(),p(),window.addEventListener("resize",M),window.addEventListener("mousemove",C),c.current=requestAnimationFrame(S),()=>{window.removeEventListener("resize",M),window.removeEventListener("mousemove",C),c.current&&cancelAnimationFrame(c.current)}},[]),e.jsxs("div",{ref:i,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:n,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` path { fill: none; stroke: hsl(var(--primary) / 0.20); diff --git a/webui/dist/index.html b/webui/dist/index.html index 6aa56064..66ce72c0 100644 --- a/webui/dist/index.html +++ b/webui/dist/index.html @@ -7,7 +7,7 @@ MaiBot Dashboard - +