Commit Graph

285 Commits

Author SHA1 Message Date
minecraft1024a
e9b3125d4a feat(cross_context): 支持私聊和群聊混合的上下文共享
本次更新扩展了跨上下文共享功能,使其不再局限于群聊之间,现在可以支持群聊与私聊的混合共享。

主要变更:
- 将 `cross_context.groups` 的 `chat_ids` 配置格式从一维字符串列表(仅群号)更新为二维列表 `[["type", "id"], ...]`,其中 `type` 可以是 "group" 或 "private"。
- 更新了 `cross_context_api` 以正确处理新的配置格式,使其能够识别并获取私聊和群聊的消息历史。
- 相应地更新了配置文件模板 `bot_config_template.toml` 以反映新的配置格式和功能。

BREAKING CHANGE: `cross_context.groups` 的 `chat_ids` 配置格式已更改。旧的一维群号列表格式不再受支持,用户需要按照 `[["type", "id"], ...]` 的新格式更新其配置文件才能使用此功能。
2025-11-19 22:57:32 +08:00
minecraft1024a
b8d31207cb refactor(chat): 抽象化跨群聊上下文构建逻辑
将 `build_cross_context` 方法的实现委托给 `cross_context_api`。
这简化了 `prompt_utils` 中的代码,将复杂的上下文构建逻辑(包括获取其他群聊、根据模式获取和格式化消息)封装到专用的API中,提高了代码的模块化和可维护性。
2025-11-19 22:57:29 +08:00
Windpicker-owo
93fbc31662 fix(chat): 优化breaking模式下的兴趣值累积逻辑
重构heartFC_chat中的消息处理机制,使用累积兴趣值替代最近三次记录来判断是否进入breaking模式。主要变更包括:

- 将breaking模式判断基于累积兴趣值而非最近3次记录
- 在消息成功处理时重置累积兴趣值
- 调整阈值计算方式,使用聊天频率进行动态调整
- 修复send_api中的消息查找函数,提高回复消息匹配准确性

这些改动提高了对话节奏控制的稳定性,使breaking模式触发更加合理。
2025-11-19 22:57:25 +08:00
Windpicker-owo
51aad4f952 迁移:1f91967(remove:移除willing系统,移除reply2,移除能量值,移除reply_to改为message) 2025-11-19 22:57:24 +08:00
tt-P607
f120cd94d7 feat(plugin_system): 实现 on_plugin_loaded 异步钩子
在插件成功加载和注册后,添加一个新的生命周期钩子 `on_plugin_loaded`。

此钩子允许插件在加载完成后执行异步的初始化任务,例如建立数据库连接、加载数据或启动后台服务。通过使用 `asyncio.create_task`,确保了钩子的执行不会阻塞插件的加载流程,从而提高了系统的响应性和健壮性。
2025-11-19 22:56:07 +08:00
minecraft1024a
dfbe30f7e6 chore: 调整日志级别和更新默认配置
- 将事件注册成功的日志级别从INFO调整为DEBUG,以减少不必要的日志输出。
- 修正`maizone_refactored`插件中图片目录路径的表示方法,使用`.as_posix()`确保跨平台兼容性。
- 将备用Cookie获取服务的默认主机地址从一个具体的IP(`172.20.130.55`)更改为`127.0.0.1`,这更符合本地开发的通用配置。
2025-11-19 22:56:02 +08:00
Windpicker-owo
fe472dff60 修复代码格式和文件名大小写问题 2025-11-19 22:55:55 +08:00
Windpicker-owo
dfa2d8a438 feat(chat): 引入SmartPrompt智能提示构建系统
重构DefaultReplyer对话提示构建逻辑,统一使用SmartPrompt抽象组件替代原冗长的模板选择与参数拼装流程。将原160+行的分支式模板处理逻辑压缩为统一的SmartPrompt.build_prompt()调用,实现提示构建策略的可插拔与可维护性提升。

- 新增 src.chat.utils.smart_prompt 模块(SmartPrompt类及参数封装)
- 移除旧的normal/s4u分支硬编码,由SmartPrompt内部按需适配
- 事件管理器仅补充HandlerResult显式导入,无功能变动
2025-11-19 22:54:32 +08:00
minecraft1024a
9b3422cb05 refactor(plugin_system): 重构插件配置同步逻辑
将插件配置同步逻辑重构为更清晰、更健壮的实现。此更改将复杂的同步过程分解为两个独立的、职责单一的方法:

- `_sync_central_config_to_plugin`: 专注于将中央配置单向同步到插件目录。
- `_is_file_content_identical`: 提供一个高效的文件内容比较方法,通过MD5哈希值避免不必要的IO操作。

这种重构提高了代码的可读性、可维护性,并增强了错误处理能力。同时,代码库从 `os.path` 迁移到了现代的 `pathlib`,以实现更简洁、更面向对象的路径操作。
2025-11-19 22:54:29 +08:00
minecraft1024a
f5ec532822 紧急修复一下我写出来的问题,修复同步插件配置文件时配置文件路径错误的问题 2025-11-19 22:54:28 +08:00
Windpicker-owo
35472fe86b ruff 2025-11-19 22:54:16 +08:00
minecraft1024a
4b36a34c1e refactor(plugin): 优化插件配置加载与同步机制
- 移除全局插件配置开关 `plugins.centralized_config`。
- 简化 `PluginBase` 的配置加载逻辑,不再使用模板文件,而是直接在中央配置目录生成默认配置。
- 在 `PluginManager` 中增加配置同步逻辑,在加载插件时,实现插件目录与中央配置目录之间的双向同步,确保配置一致性。
- 更新 `bot_config_template.toml`,移除已废弃的 `[plugins]` 配置项并提升版本号。
2025-11-19 22:54:05 +08:00
minecraft1024a
01e06ae95b ruff ci 2025-11-19 22:51:31 +08:00
Windpicker-owo
eeddf1976c feat(napcat): 新增18个账号相关事件处理器与完善文档
为NapCat适配器添加完整的账号操作功能:
- 在线客户端查询、在线状态设置、最近联系人
- 好友列表、分组列表、删除好友、点赞
- 头像设置、个性签名、自定义在线状态
- 小程序卡片生成、用户信息/状态查询
并同步补充事件类型注解
BREAKING CHANGE: BaseEvent构造函数不再接受可变默认实参
2025-11-19 22:50:07 +08:00
Windpicker-owo
1dbf14c096 feat(napcat): 添加账号设置处理器和事件类型注解
为napcat插件增加SetProfileHandler来处理账号信息设置事件
- 实现参数解析和napcat API调用逻辑
- 添加详细的事件类型文档注解,包含参数说明和返回格式
- 扩展事件枚举类,新增多个群组相关操作事件
- 在插件初始化时自动注册所有事件处理器
- 为HandlerResultsCollection添加获取消息结果的方法

同时添加接口测试处理器用于验证事件系统的正常工作
2025-11-19 22:50:04 +08:00
minecraft1024a
11ecbf0a25 docs: remove outdated and unused documentation files
A significant number of documentation files, including design documents, user guides, and old images, have been removed to clean up the repository and eliminate outdated information. This reduces clutter and ensures that the documentation accurately reflects the current state of the project.

Key removals include:
- `memory_system_design_v3.md`
- `model_configuration_guide.md`
- `PERMISSION_SYSTEM.md`
- `CONTRIBUTE.md`
- `vector_db_usage_guide.md
2025-11-19 22:49:49 +08:00
minecraft1024a
a645e766ca refactor(cache): 重构工具缓存机制并优化LLM请求重试逻辑
将工具缓存的实现从`ToolExecutor`的装饰器模式重构为直接集成。缓存逻辑被移出`cache_manager.py`并整合进`ToolExecutor.execute_tool_call`方法中,简化了代码结构并使其更易于维护。

主要变更:
- 从`cache_manager.py`中移除了`wrap_tool_executor`函数。
- 在`tool_use.py`中,`execute_tool_call`现在包含完整的缓存检查和设置逻辑。
- 调整了`llm_models/utils_model.py`中的LLM请求逻辑,为模型生成的空回复或截断响应增加了内部重试机制,增强了稳定性。
- 清理了项目中未使用的导入和过时的文档文件,以保持代码库的整洁。
2025-11-19 22:49:46 +08:00
Windpicker-owo
ce64cc68e1 修复event权限,现在每个component都拥有plugin_name属性 2025-11-19 22:49:41 +08:00
minecraft1024a
d4ba286855 refactor(core): remove tool history manager and integrate cache into tool executor
Removes the `ToolHistoryManager` and its associated functionalities, including history recording, querying, and prompt generation. This simplifies the architecture by decoupling tool execution history from the core logic.

The tool caching mechanism is now directly integrated into the `ToolExecutor` by wrapping the `execute_tool_call` method. This ensures that caching is applied consistently for all tool executions that have it enabled, improving performance and reducing redundant calls.

- Deletes `src/common/tool_history.py`.
- Removes tool history related functions from `prompt_builder.py` and `tool_api.py`.
- Adds a `wrap_tool_executor` function in `cache_manager.py` to apply caching logic directly to the `ToolExecutor`.
2025-11-19 22:49:38 +08:00
雅诺狐
71c6b0ef1e Refactor plugin system and update permission checks
Removed the permission_example plugin and its files. Refactored plugin hot reload and manager logic for more robust reloading, deep reload, and cache clearing, including improved debounce and plugin name resolution. Updated MaiZone plugin and actions to use the new permission API for feed read/send actions, and registered new permission nodes. Enhanced plugin management commands with PlusCommand, improved help, and added hot reload and cache management commands.
2025-11-19 22:49:23 +08:00
雅诺狐
89bb9e5b3e Change default start_index in get_remaining to 0
Updated the get_remaining method in CommandArgs to default start_index to 0 instead of 1, ensuring all arguments are included by default when retrieving remaining parameters.
2025-11-19 22:49:22 +08:00
Windpicker-owo
e468dd1989 feat(plugin-system): 添加事件触发和订阅的白名单机制
为事件系统添加权限控制功能,包括:
- 在BaseEvent中新增allowed_subscribers和allowed_triggers白名单字段
- 事件管理器触发和订阅时进行白名单验证
- 为所有系统默认事件设置仅允许SYSTEM插件触发
- 在所有事件触发调用处显式传递plugin_name="SYSTEM"参数

确保只有授权插件可以触发特定事件和订阅处理器,增强系统安全性。
2025-11-19 22:49:20 +08:00
Windpicker-owo
dc13343b88 fix(plugin): 为事件处理器添加异步锁和并行执行支持
在BaseEvent类中引入asyncio.Lock确保同一个事件不能同时激活多次
重构事件触发逻辑,使用asyncio.gather并行执行所有订阅者处理器
提高事件处理效率的同时保证线程安全
2025-11-19 22:49:19 +08:00
Windpicker-owo
671ee6cbcf 引入lock防止同一个事件同时触发 2025-11-19 22:49:18 +08:00
雅诺狐
395cd14e52 Refactor permission checks and decorators usage
Refactored permission checks in built-in plugins to use the new @require_permission decorator, improving code clarity and consistency. Enhanced permission_decorators to better extract ChatStream and support PlusCommand. Updated PermissionCommand to use permission decorators for all subcommands, improved user mention parsing, and improved feedback messages. Registered a new permission node for sending feeds in MaiZone plugin and updated command registration to use PlusCommand info.
2025-11-19 22:49:16 +08:00
雅诺狐
a2873a71ef Add PlusCommand enhanced command system
Introduces the PlusCommand system for simplified command development, including new base classes, argument parsing utilities, and registration logic. Updates the plugin system, component registry, and bot message handling to support PlusCommand components alongside traditional commands. Adds documentation and configuration for command prefixes, and provides a developer guide for the new system.
2025-11-19 22:48:49 +08:00
minecraft1024a
6b53560a7e feat(tool_system): implement declarative caching for tools
This commit refactors the tool caching system to be more robust, configurable, and easier to use. The caching logic is centralized within the `wrap_tool_executor`, removing the need for boilerplate code within individual tool implementations.

Key changes:
- Adds `enable_cache`, `cache_ttl`, and `semantic_cache_query_key` attributes to `BaseTool` for declarative cache configuration.
- Moves caching logic from a simple history-based lookup and individual tools into a unified handling process in `wrap_tool_executor`.
- The new system leverages the central `tool_cache` manager for both exact and semantic caching based on tool configuration.
- Refactors `WebSurfingTool` and `URLParserTool` to utilize the new declarative caching mechanism, simplifying their code.
2025-11-19 22:48:37 +08:00
minecraft1024a
e7fa3d79ff Reapply "【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询..."
This reverts commit 3d93bc4079.
2025-11-19 22:48:31 +08:00
Furina-1013-create
1f800be3d1 feat(plugin_system): 增加工具执行日志记录
feat(plugin_system): 增加工具执行日志记录

在工具执行前添加一行日志,用于记录正在调用的工具名称和参数,方便调试和追踪。
2025-11-19 22:48:25 +08:00
Windpicker-owo
e068663ef9 Revert "【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询..."
This reverts commit 80ab0c687c.
2025-11-19 22:48:24 +08:00
Windpicker-owo
adfacd883c 【迁移】工具系统再完善:工具缓存、ttl支持、自动记录、长期保存、自动清理缓存、将记录与执行分离、api记录查询、时间聊天工具筛选查询... 2025-11-19 22:48:23 +08:00
minecraft1024a
dd9aecea14 feat(maizone): 新增QQ空间互通组功能,根据聊天上下文生成说说
引入了全新的“QQ空间互通组”功能。用户可以配置多个群聊为一个互通组。
在通过指令发布说说时,系统会自动获取这些群聊的近期聊天记录作为上下文,从而生成与当前讨论话题更相关的说说内容。

- 在 `config.toml` 中新增了 `[maizone_intercom]` 配置项用于定义互通组。
- 重构并增强了动态(说说)的拉取逻辑,提高了对不同数据格式的兼容性和解析的稳定性。
- 对项目中的多个文件进行了代码清理,移除了未使用的导入,使代码更加整洁。
2025-11-19 22:48:02 +08:00
雅诺狐
ab3a36bfa7 全面更换orjson 2025-11-19 22:47:10 +08:00
Windpicker-owo
dfd8d4ca9e 注册EventHandler组件 2025-11-19 22:46:30 +08:00
Windpicker-owo
5d1390d546 event重构暂时完成,待测试 2025-11-19 22:46:26 +08:00
Windpicker-owo
902a031a9d feat: 迁移Windpicker-owo的Event系统重构\n\n- 引入新的BaseEvent和HandlerResult架构\n- 实现灵活的事件订阅与激活机制\n- 添加事件管理器单例模式\n- 支持事件缓存和权重排序\n- 统一事件处理接口 2025-11-19 22:46:25 +08:00
雅诺狐
978af6b2ca Update permission_manager.py 2025-11-19 22:46:18 +08:00
雅诺狐
34252ea4a0 refactor: 清理代码质量和移除未使用文件
- 移除未使用的导入语句和变量
- 修复代码风格问题(空格、格式化等)
- 删除备份文件和测试文件
- 改进异常处理链式调用
- 添加权限系统数据库模型和配置
- 更新版本号至6.4.4
- 优化SQL查询使用正确的布尔表达式
2025-11-19 22:46:18 +08:00
雅诺狐
3360b22dca Refactor anti-injection system and remove command skip list
Removed the command skip list feature and related code from the anti-injection system, including configuration options, plugin command collection, and management commands. Refactored anti-injector logic to operate directly on message dictionaries and simplified whitelist and message content extraction. Updated response handling to perform anti-injection checks before reply generation, and removed skip list refresh logic from the plugin manager.
2025-11-19 22:46:06 +08:00
minecraft1024a
bca9747691 feat(plugin): 兼容 alpha 版本并更新插件版本限制
- 在版本比较器中增加对 alpha 版本号的兼容性处理,现在可以正确解析如 `0.10.0-alpha-1` 格式的版本。
2025-11-19 22:45:51 +08:00
minecraft1024a
2f1a9fa966 refactor(cleanup): 移除未使用的导入项与冗余代码
清理了整个代码库中所有无用的模块导入、重复定义以及冗余变量引用,具体包括:
- bot.py 去掉了 random、typing 的未使用 import
- antipromptinjector 模块统一移除未引用的 DetectionResult、Dict、List 等
- chat_loop 中删除了未调用的 Timer、mai_thinking_manager、events_manager 等引用
- qzone_service 删除多余 f-string 大括号,避免日志警告格式问题
- 其他模块同步剔除各自范围内的冗余 import(asyncio、datetime 等共 20+ 处)

保持功能不变,仅作代码整洁度优化,无破坏性变更。(并添加了一个现在暂时还没加进去的必应搜索源文件)
2025-11-19 22:45:22 +08:00
minecraft1024a
f53993e34a feat(proactive_thinking): 重构主动思考为由Planner直接决策
重构了主动思考的触发和决策流程。原有的通过生成特定prompt来启动思考循环的方式被移除,改为直接调用Planner的`PROACTIVE`模式。

- **Planner增强**:
  - 新增`PROACTIVE`聊天模式,用于处理主动思考场景。
  - 为`PROACTIVE`模式设计了专用的prompt模板,整合了长期记忆、当前状态等信息。
  - 引入`do_nothing`动作,允许Planner在分析后决定保持沉默。
  - 增加从海马体(长期记忆)获取上下文的功能,为决策提供更丰富的背景。

- **ProactiveThinker简化**:
  - 移除了原有的prompt生成和调用`observe`的逻辑。
  - 现在直接调用`action_planner.plan(mode=ChatMode.PROACTIVE)`来获取决策。
  - 根据Planner返回的动作(如`do_nothing`或具体行动),决定是保持沉默还是执行计划。

- **CycleProcessor & Tracker调整**:
  - `CycleProcessor`新增`execute_plan`方法,用于执行一个已经由Planner预先制定好的计划。
  - `CycleTracker`能够区分并标记由主动思考发起的循环(例如,cycle_id为 "1.p"),以便于追踪和分析。
2025-11-19 22:45:16 +08:00
雅诺狐
95bbce355a Improve anti-injection detection logging and text extraction
Added detailed debug logs for text extraction and LLM detection input in the anti-injector module. Refactored message processing to only use user-added content for detection, avoiding duplicate text. Fixed import paths for command_skip_list in plugin manager and anti_injector_manager to reflect new module structure.
2025-11-19 22:45:01 +08:00
雅诺狐
bb4592846c Refactor config system to use Pydantic validation
Refactored configuration classes to inherit from a new ValidatedConfigBase using Pydantic for robust validation and error reporting. Updated api_ada_configs.py, config.py, config_base.py, and official_configs.py to replace dataclasses with Pydantic models, add field validation, and improve error messages. This change enhances configuration reliability and developer feedback for misconfigurations. Also includes minor code cleanups and removal of unused variables in other modules.
2025-11-19 22:44:45 +08:00
minecraft1024a
808954a372 refactor(chat): 禁用工具执行器的缓存功能(因为这玩意真的没几次命中过的) 2025-11-19 22:44:41 +08:00
雅诺狐
383f704b53 Remove unused imports across multiple modules
Cleaned up various files by removing unused or redundant import statements to improve code readability and reduce potential confusion. No functional changes were made.
2025-11-19 22:44:32 +08:00
tt-P607
3e20d11eec <Thinking>
我需要分析这个git diff,并生成一个与之前完全不同的commit message。

让我先分析变更内容:

1. **主要变更**:
   - 在 `anti_injector.py` 中添加了新的 `auto` 处理模式
   - 添加了命令跳过列表功能 (`command_skip_list`)
   - 重构了反注入管理命令,从独立插件移动到核心动作插件
   - 更新了配置文件以支持新功能
   - 在插件管理器中添加了跳过列表刷新逻辑

2. **之前的commit message重点**:
   - 强调了"advanced anti-injection capabilities"
   - 重点描述了"intelligent 'auto' mode"
   - 提到了"command skip list"
   - 强调了"dynamically assesses threats"
   - 提到了"refactored and integrated into core actions plugin"

3. **我需要完全不同的角度**:
   - 可以从架构重构的角度
   - 可以从用户体验改进的角度
   - 可以从系统集成的角度
   - 可以从性能优化的角度

让我从**系统架构优化和插件整合**的角度来写这个commit message,重点强调:
- 插件系统的重构和整合
- 管理命令的迁移和统一
- 跳过机制的实现
- 自动化决策系统的引入

这样就能避免使用之前message中的关键词和结构。
</Thinking>

refactor(plugins): 重构反注入插件架构并优化命令管理体系

将反注入管理功能从独立插件迁移至核心动作模块,实现更好的系统集成。新增智能跳过机制,允许已注册的插件命令绕过检测流程,有效减少误判。同时引入自适应处理策略,系统可根据威胁评估结果自主选择最适当的响应方式。

插件管理器现已集成自动刷新功能,确保跳过列表与插件状态保持同步。配置系统扩展支持多种跳过模式和自定义规则,提升了整体可维护性和用户体验。
ps:谢谢雅诺狐姐姐投喂的提交喵^ω^
2025-11-19 22:44:03 +08:00
minecraft1024a
aa8906b491 feat(deps): 实现依赖包智能别名解析
引入了依赖包智能别名解析机制,以解决 Python 生态中常见的安装名与导入名不一致的问题(如 `beautifulsoup4` -> `bs4`)。

当通过包名直接导入失败时,依赖管理器会自动查询一个内置的别名映射表,并尝试使用别名再次导入。这大大提升了开发者在定义简单字符串格式依赖时的体验,减少了因名称不一致导致的依赖检查失败。

同时,更新了相关文档,详细说明了该功能的工作原理、解决了什么问题,并更新了最佳实践。
2025-11-19 22:43:48 +08:00
minecraft1024a
660428cdad refactor(config): 移除视频分析相关重复的配置及未使用的导入(所以我挺好奇为什么VideoAnalysisConfig能有两个)
同时,清理了多个文件中未使用的导入,包括 `inspect`、`base64` 和 `get_image_manager`,以保持代码库的整洁。
2025-11-19 22:43:48 +08:00
minecraft1024a
9b382a9505 feat(plugin): 实现插件配置集中化管理
将插件配置文件从各自的插件目录迁移至项目根目录下的 `config/plugins/` 文件夹中,方便用户统一管理和修改。

主要变更:
- 新增 `plugins.centralized_config` 总开关,用于控制是否启用此功能。
- 修改插件加载逻辑,现在会从 `config/plugins/<plugin_name>/` 目录读取用户配置。
- 如果用户配置不存在,会自动从插件目录下的模板配置文件复制一份。
- 保留了原有的配置版本检查和自动迁移功能,现在作用于用户配置文件。
2025-11-19 22:43:47 +08:00