Commit Graph

130 Commits

Author SHA1 Message Date
Windpicker-owo
3fcf8e9add feat(memory): 重构记忆系统并移除插件热重载
重构记忆系统核心模块,引入全局记忆作用域、记忆指纹去重机制和查询规划器,优化多阶段检索性能。移除插件热重载系统及其相关依赖。

主要变更:
- 引入全局记忆作用域,简化记忆管理
- 实现记忆指纹去重,避免重复记忆存储
- 新增查询规划器,支持语义查询规划和记忆类型过滤
- 优化多阶段检索,增加语义重排和权重配置
- 改进向量存储,支持嵌入维度自动解析和查询向量生成
- 增强元数据索引,支持主体索引和更新操作
- 记忆构建器支持多主体和自然语言展示
- 移除watchdog依赖和插件热重载模块
- 更新配置模板,简化记忆配置项

BREAKING CHANGE: 移除插件热重载系统,相关API和命令不再可用。记忆系统接口有较大调整,使用该系统的模块需要适配新接口。
2025-11-19 23:11:14 +08:00
Windpicker-owo
c31fd02daf refactor(chat): 迁移数据库操作为异步模式并修复相关调用
将同步数据库操作全面迁移为异步模式,主要涉及:
- 将 `with get_db_session()` 改为 `async with get_db_session()`
- 修复相关异步调用链,确保 await 正确传递
- 优化消息管理器、上下文管理器等核心组件的异步处理
- 移除同步的 person_id 获取方法,避免协程对象传递问题

修复 deepcopy 在 StreamContext 中的序列化问题,跳过不可序列化的 asyncio.Task 对象

删除无用的测试文件和废弃的插件清单文件
2025-11-19 23:09:34 +08:00
Windpicker-owo
bdf43c2455 fix 2025-11-19 23:08:03 +08:00
Windpicker-owo
dce48d38cf feat: 在插件系统中添加 Chatter 组件
- 在 component_types.py 中新增了用于 CHATTER 的 ComponentType。
- 实现了 ChatterInfo 类,用于存储 Chatter 组件的相关信息。
- 增强了 ComponentRegistry,以支持 Chatter 组件的注册与管理。
- 创建了 ChatterManager,用于管理 Chatter 实例并处理聊天流。
- 开发了 BaseChatter 抽象类,用于定义 Chatter 的行为规范。
- 实现了 AffinityChatter,作为具备兴趣评分与关系构建功能的具体 Chatter 组件。
- 添加了一个内置的 Chatter 插件,并附带完整文档与使用示例。
- 更新了 PluginManager,在插件概览中加入 Chatter 组件的统计信息。
2025-11-19 23:08:03 +08:00
Windpicker-owo
df3c616d09 ruff,私聊视为提及了bot 2025-11-19 23:07:30 +08:00
minecraft1024a
80283fe77d fix(plugin): 移除插件配置同步调用并增强错误日志
在插件管理器中,移除了加载插件时对已废弃的配置同步方法的调用。

同时,为了更好地排查 `maizone` 插件发送动态失败的问题,增强了其命令的异常日志,现在会额外记录异常类型。
2025-11-19 23:05:50 +08:00
minecraft1024a
9a40e86894 删除插件配置文件的双向迁移逻辑 2025-11-19 23:05:49 +08:00
minecraft1024a
6bf05fd660 fix(permission): 将权限管理器初始化改为异步
`PermissionManager` 的 `__init__` 方法中包含了同步的数据库初始化操作,这会在异步环境中阻塞事件循环。

本次提交将数据库连接的逻辑移至一个新的异步方法 `initialize()` 中,并在应用启动时显式调用和等待它。这确保了数据库的初始化过程是异步执行的,避免了潜在的性能问题。

BREAKING CHANGE: `PermissionManager` 实例化后需要手动调用并等待 `initialize()` 方法来完成数据库初始化。
2025-11-19 23:05:35 +08:00
雅诺狐
679195d792 refactor(db): 修正SQLAlchemy异步操作调用方式
移除session.add()方法的不必要await调用,修正异步数据库操作模式。主要变更包括:

- 将 `await session.add()` 统一改为 `session.add()`
- 修正部分函数调用为异步版本(如消息查询函数)
- 重构SQLAlchemyTransaction为完全异步实现
- 重写napcat_adapter_plugin数据库层以符合异步规范
- 添加aiomysql和aiosqlite依赖支持
2025-11-19 23:05:17 +08:00
雅诺狐
0cffc0aa95 refactor(db): 将数据库操作异步化
- 将所有 session.add() 改为 await session.add()
- 将所有 session.commit() 改为 await session.commit()
- 将 session.refresh() 改为 await session.refresh()
2025-11-19 23:05:14 +08:00
tt-P607
5892ed1452 refactor(db): 重构数据库交互为异步模式
为了提升性能并与项目整体的异步架构保持一致,对核心数据库交互模块进行了异步化重构。

主要修改内容包括:
- 将 `PermissionManager` 中的所有数据库操作从同步改为异步,以避免阻塞事件循环。
- 使用 `async_sessionmaker` 和 `async with session` 替代原有的同步会话管理。
- 将 SQLAlchemy 查询语法更新为异步兼容的 `await session.execute(select(...))` 模式。
- 相应地,调用链中依赖数据库操作的多个方法也已更新为 `async` 函数。
2025-11-19 23:05:09 +08:00
雅诺狐
93542cadef perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
2025-11-19 23:05:00 +08:00
Windpicker-owo
ea7d3b364f plugin_name改为permission_group 2025-11-19 22:59:12 +08:00
Windpicker-owo
086a7322b3 fix:修复插件组件无法正确获取插件配置的问题 2025-11-19 22:58:56 +08:00
Windpicker-owo
03d1f7c57c 继续尝试迁移,但是组件获取插件配置存在问题 2025-11-19 22:58:34 +08:00
Windpicker-owo
3980509caa refactor(prompt): 重构并统一提示词系统
- 删除旧的智能提示词系统(smart_prompt.py)和相关参数模块(prompt_parameters.py)
- 将 prompt_builder.py 重命名为 prompt.py 并精简功能
- 更新所有模块的导入路径从 `src.chat.utils.prompt_builder` 到 `src.chat.utils.prompt`
- 统一提示词构建接口,使用新的 PromptContext 替代 SmartPromptParameters
- 移除重复和冗余代码,简化系统架构

BREAKING CHANGE: 旧的 SmartPrompt 系统已被完全移除,所有相关模块需要改用新的统一 Prompt 系统
2025-11-19 22:58:17 +08:00
minecraft1024a
2e436dff33 rrrrrrrrrrrrrruuuuuuuuuuuuuuuuuuuuffffffffffffffffffffffffff 2025-11-19 22:57:45 +08:00
minecraft1024a
d66e04baff chore: format code and remove redundant blank lines
This commit applies automated code formatting across the project. The changes primarily involve removing unnecessary blank lines and ensuring consistent code style, improving readability and maintainability without altering functionality.
2025-11-19 22:57:44 +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
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
雅诺狐
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
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
雅诺狐
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
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
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
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
雅诺狐
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