Commit Graph

962 Commits

Author SHA1 Message Date
雅诺狐
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
雅诺狐
31e028ab25 Refactor anti-injection system into modular subpackages
Split the anti-prompt-injector module into core, processors, management, and decision submodules for better maintainability and separation of concerns. Moved and refactored detection, shielding, statistics, user ban, message processing, and counter-attack logic into dedicated files. Updated imports and initialization in __init__.py and anti_injector.py to use the new structure. No functional changes to detection logic, but code organization is significantly improved.
2025-11-19 22:45:01 +08:00
minecraft1024a
438bcc4f59 fix(chat): 修复主动思考范围配置及空用户ID问题
- 增加对 `proactive_thinking_chat_scope` 配置值的有效性验证,防止因无效配置导致意外行为。(乱填参数是吧,我跟你爆了)

- 修复了当 `user_id` 为 `None` 时可能引发的 `get_person_id` 调用错误,确保在这种情况下程序能够稳定运行。
2025-11-19 22:45:00 +08:00
minecraft1024a
3777ec9d73 feat(chat): 实现可配置的主动思考范围并优化逻辑
- 将主动思考的prompt移至代码内部,并区分私聊和群聊场景。
- 增加`The_scope_that_proactive_thinking_can_trigger`配置项,允许用户将主动思考限制在“全部”、“私聊”或“群聊”范围。
- 删除了旧的`proactive_thinking_prompt_template`配置。
- 优化了主动思考的触发条件,现在会根据新的范围配置进行检查。
- 清理了代码中多余的空行和未使用的导入。
2025-11-19 22:44:59 +08:00
minecraft1024a
a31ee1ab5f refactor(video): update config key from utils_video to video_analysis 2025-11-19 22:44:56 +08:00
Furina-1013-create
00eacc7570 改进focus模式下的回复逻辑,理论上现在focus模式下在bot被@ / 提及 时应该会回复了
采用的是在focus模式下移除no_reply动作的方式
同步更新bot_config_template里面的注释
2025-11-19 22:44:55 +08:00
minecraft1024a
4a3fc57e6f refactor(antipromptinjector): 将每次输入都记录的 info 级别调至 debug
避免大量冗余信息在常规日志级别输出,保持日志整洁
2025-11-19 22:44:54 +08:00
minecraft1024a
7d13d0b6c2 fix(embedding): 彻底解决事件循环冲突导致的嵌入生成异常
通过以下改动修复嵌入生成过程中的事件循环相关问题:
- 在 EmbeddingStore._get_embedding 中,改为同步创建-使用-销毁的新事件循环模式,彻底避免嵌套事件循环问题
- 调整批量嵌入 _get_embeddings_batch_threaded,确保每个线程使用独立、短生命周期的事件循环
- 新增 force_new 参数,LLM 请求嵌入任务时强制创建新的客户端实例,减少跨循环对象复用
- 在 OpenAI 客户端的 embedding 调用处补充详细日志,方便排查网络连接异常
- get_embedding() 每次都重建 LLMRequest,降低实例在多个事件循环中穿梭的概率

此次改动虽然以同步风格“硬掰”异步接口,但对现有接口零破坏,确保了向量数据库及相关知识检索功能的稳定性。(还有就是把的脚本文件夹移回来了)
2025-11-19 22:44:54 +08:00
雅诺狐
f35d52401b 修复了专注错误
Updated logic in heartFC_chat.py and relationship_manager.py to prioritize 'chat_info_platform', then 'user_platform', and finally a default when determining platform information. Added a fallback to 'unknown' in get_person_id if platform is None, improving robustness when platform data is missing.

Co-Authored-By: tt-P607 <68868379+tt-P607@users.noreply.github.com>
2025-11-19 22:44:53 +08:00
minecraft1024a
dcecd9cf7d refactor(memory): 移除混合记忆模型,全面转向向量化瞬时记忆
删除了 `HybridInstantMemory` 模块及其复杂的策略判断、同步和检索逻辑。此举旨在简化记忆系统的架构,统一采用 `VectorInstantMemoryV2` 作为唯一的瞬时记忆解决方案。(虽然我也不知道效果好不好反正先转了再说,因为基于大模型的瞬时记忆有那么一点点慢)
2025-11-19 22:44:52 +08:00
minecraft1024a
f2e82cf82f refactor(memory): 重构瞬时记忆为全量向量化存储模型
新系统采用“全量存储,定时清理”的设计理念,将所有聊天消息向量化并存入ChromaDB。通过后台线程定时清理过期消息,取代了之前基于“重要性模式”判断是否记忆的复杂逻辑。

主要变更:
- **全量存储**: 不再进行前置判断,所有消息均被向量化存储,简化了记忆创建流程。
- **定时清理**: 引入基于`threading`的后台任务,根据设定的`retention_hours`自动清理过期记忆,确保系统轻量高效。
- **简化检索**: 检索逻辑更新为直接查询相似消息,并增加了相似度阈值过滤和时间差格式化,提高了上下文的准确性和可读性。

在 `DefaultReplyer` 中,已切换至新的 `HybridInstantMemory`(其底层实现为V2),并优化了记忆上下文的构建逻辑,使其能更稳定地处理不同类型的记忆返回结果。
2025-11-19 22:44:50 +08:00
minecraft1024a
4fc7c51ee0 feat(memory): 引入基于向量的瞬时记忆系统
用基于 ChromaDB 和向量相似度的新瞬时记忆系统取代了原有的实现。此更改旨在提高记忆创建和检索的准确性和相关性。

主要变更:
- **向量化重要性判断**: 放弃了原有的 LLM 判断方法,通过将聊天记录与预定义的“重要性模式”进行向量相似度比较,来决定是否创建记忆。
- **高效去重**: 在存储新记忆之前,通过向量相似度检查,有效避免了内容重复。
- **精准检索**: 利用向量搜索,根据用户当前输入检索最相关的记忆,提高了上下文的连贯性。
- **双重存储**: 为了保持系统兼容性,记忆同时存储在 ChromaDB 向量数据库和现有的 SQLAlchemy 数据库中。
- **代码集成**: 在 `DefaultReplyer` 中将 `InstantMemory` 的实现切换为新的 `VectorInstantMemory`。
2025-11-19 22:44:49 +08:00
minecraft1024a
58f58144d0 refactor(chat): 调整消息选择的优先级
在确定 `action_message` 时,优先使用 `target_message` 而不是 `message_data`。

这一变更优化了消息处理流程,确保在存在明确的目标消息时,系统能够正确地选择它,从而避免了潜在的逻辑冲突,使行为更加符合预期。

Co-authored-by: 雅诺狐 <212194964+foxcyber907@users.noreply.github.com>
Co-authored-by: tt-P607 <68868379+tt-P607@users.noreply.github.com>
2025-11-19 22:44:46 +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
minecraft1024a
d355153a19 feat(video): 视频识别功能开关与日志优化
根据全局配置 `global_config.video_analysis.enable` 控制视频识别功能的启用与禁用。

- 当视频识别功能禁用时,收到视频消息将直接返回 `[视频]` 或空字符串,不再进行分析,以节约资源。
2025-11-19 22:44:04 +08:00
minecraft1024a
d20daaf3e2 新增反击模式支持,允许在检测到提示词注入攻击时生成反击响应并发送。更新相关配置和处理逻辑,增强系统的防护能力。 2025-11-19 22:44:03 +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
雅诺狐
e404844a07 Expand dangerous keyword list in message shielding
Extended the list of dangerous keywords in the _partially_shield_content method to cover more attack vectors, including system commands, privilege escalation, information leakage, and social engineering. This enhances the robustness of the message shielding mechanism against prompt injection and related attacks.
2025-11-19 22:43:59 +08:00
雅诺狐
118533fcdc Expand and update prompt injection detection patterns
Enhanced the default_patterns list in PromptInjectionDetector with more comprehensive and specific regular expressions to improve detection of prompt injection attempts, including new patterns for admin commands, system prompts, privilege escalation, and sensitive information leakage. This update aims to strengthen the robustness of the anti-prompt-injection mechanism.
2025-11-19 22:43:58 +08:00
雅诺狐
2d91a7d55c Refactor anti-injector process result handling
Introduced a ProcessResult enum to standardize anti-injector message processing outcomes. Updated anti_injector.py to return ProcessResult values instead of booleans, and refactored bot.py to handle these results with improved logging and clearer control flow. This change improves code clarity and maintainability for anti-prompt injection logic.
2025-11-19 22:43:58 +08:00
雅诺狐
16da725272 Add LLM anti-prompt injection system
Introduces a comprehensive anti-prompt injection system for LLMs, including rule-based and LLM-based detection, user ban/whitelist management, message shielding, and statistics tracking. Adds new modules under src/chat/antipromptinjector, integrates anti-injection checks into the message receive flow, updates configuration and database models, and provides test scripts. Also updates templates and logger aliases to support the new system.
2025-11-19 22:43:57 +08:00
雅诺狐
ced43386bf Refactor antiprompt flowchart and fix indentation
Updated the antipromptinjector flowchart for improved clarity and logic. Fixed indentation in expression_selector.py to correct code structure. Removed obsolete db_migration_plan.md documentation.
2025-11-19 22:43:44 +08:00
minecraft1024a
ebf811a85c feat(chat): 私聊专注模式下强制回复
在私聊的专注模式下,即使用户的发言没有触发任何功能,机器人也会进行回复,而不是选择“no_reply”。
此举旨在提升私聊场景下的用户体验,避免机器人因未匹配到关键词而沉默,让对话感觉更自然。
2025-11-19 22:43:37 +08:00
雅诺狐
762cdf327b Update emoji_manager.py 2025-11-19 22:42:43 +08:00
雅诺狐
f82e6e80c9 fix:数据库修复 2025-11-19 22:42:42 +08:00
雅诺狐
bae59b8856 Create 流程图.md
Co-Authored-By: tt-P607 <68868379+tt-P607@users.noreply.github.com>
2025-11-19 22:42:28 +08:00
minecraft1024a
176a6b9c2e feat(config): 为表情包识别添加独立的VLM模型配置
为表情包识别功能(emoji_vlm)引入了专门的模型任务配置,使其与通用的视觉语言模型(VLM)配置分离。这提高了配置的灵活性和模块化程度。

- 在 `api_ada_configs.py` 中新增 `emoji_vlm` 任务配置。
- 更新 `emoji_manager.py` 以使用新的 `emoji_vlm` 配置。
- 在 `model_config_template.toml` 中添加了相应的配置模板。
2025-11-19 22:42:27 +08:00
minecraft1024a
793c6e3817 fix(statistic): 修复统计任务中因数据库记录格式问题导致的异常
在处理来自数据库的记录时,增加对记录类型的检查和时间戳格式的转换。确保即使记录不是预期的字典格式,或者时间戳字段为None或字符串格式,程序也能够安全处理,避免因`TypeError`或`AttributeError`导致整个统计任务中断(说真的这都一天了为什么还没人修)
2025-11-19 22:42:24 +08:00
雅诺狐
875e02d42f 数据库重构 2025-11-19 22:40:23 +08:00
雅诺狐
dfecccfc56 llm统计记录模型反应时间 2025-11-19 22:40:11 +08:00
minecraft1024a
38fed9b4cc 添加聊天类型限制功能,支持根据聊天类型过滤命令和动作,新增私聊和群聊专用命令及动作,优化相关日志记录。 2025-11-19 22:40:01 +08:00
Furina-1013-create
f19fbcb814 炸飞Breaking形式并顺手修了一个数据库的小bug 2025-11-19 22:39:41 +08:00
minecraft1024a
8a68a6b641 优化ActionPlanner类中的时间戳更新逻辑,确保在成功执行计划后再更新last_obs_time_mark,以提高消息判断的准确性。 2025-11-19 22:39:29 +08:00
minecraft1024a
fe43cb3816 将聊天消息构建器中的日志级别从info调整为debug,以减少日志输出的冗余,优化调试信息的记录。 2025-11-19 22:39:16 +08:00
minecraft1024a
80eab4cf1a 在聊天消息构建器中添加日志记录功能,记录函数调用参数和处理过程,优化动作记录的返回格式,确保返回的动作记录包含必要字段。 2025-11-19 22:39:09 +08:00
minecraft1024a
bf9e1e60c4 优化插件热重载管理,支持多个监听目录 2025-11-19 22:39:07 +08:00
minecraft1024a
ebf6fc5c20 重构日程管理模块,将原有的schedule_manager模块迁移至manager目录,并更新相关引用。同时优化了定时任务管理逻辑,确保基于日程的发送功能正常运作,改进了日志记录和活动处理机制(OK兄弟们全体目光向我看齐,看我看我,我是个sb) 2025-11-19 22:39:03 +08:00
Furina-1013-create
2d22b3d561 我靠我我视频识别怎么又给我炸了
--已重新修复......
2025-11-19 22:38:52 +08:00
Furina-1013-create
f8ec12b00b 光速修复主动思考的bug -AI选择沉默的时候会把这个消息泄漏到群聊里面 2025-11-19 22:38:46 +08:00
Furina-1013-create
1e84acd18c 增加关于主动思考的配置,现在你可以在配置文件里面设置Bot的一个主动思考回复的行为
请务必不要修改proactive_thinking_prompt_template里面的{time}占位符以及请回复沉默!!!( )
 对了还有,你们知道吗,狐狐已经同意女装了(不是
2025-11-19 22:38:43 +08:00
minecraft1024a
1b1799e3c1 整理了一下配置文件 2025-11-19 22:38:38 +08:00
minecraft1024a
c9124a155a 添加表情包情感分析功能,允许通过配置启用二次识别以生成情感关键词,并更新相关文档和配置模板。 2025-11-19 22:38:33 +08:00
minecraft1024a
f53cd56148 更新时间戳显示模式,在消息回复和规划器规划时:消息将显示完整日期 (如: 2024-01-15 14:30:22) 2025-11-19 22:38:28 +08:00
minecraft1024a
9af7cd0ccf 更新聊天响应逻辑,优化消息针对性判断,避免无意义参与;同时在提示中增加针对性分析规则以提升对话质量。 2025-11-19 22:38:22 +08:00
minecraft1024a
6a1e86cf35 添加决策器自定义提示词功能,允许用户启用并设置自定义提示词内容 2025-11-19 22:38:02 +08:00
minecraft1024a
2db8720498 优化决策后时间戳更新逻辑,确保新消息判断的准确性 2025-11-19 22:37:54 +08:00
ikun-11451
0053daffd9 给这个文件的请求session加上一个with上下文管理喵~ 2025-11-19 22:37:46 +08:00
雅诺狐
2dfd986ba4 Update storage.py 2025-11-19 22:37:40 +08:00