refactor(chat): 迁移数据库操作为异步模式并修复相关调用

将同步数据库操作全面迁移为异步模式,主要涉及:
- 将 `with get_db_session()` 改为 `async with get_db_session()`
- 修复相关异步调用链,确保 await 正确传递
- 优化消息管理器、上下文管理器等核心组件的异步处理
- 移除同步的 person_id 获取方法,避免协程对象传递问题

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

删除无用的测试文件和废弃的插件清单文件
This commit is contained in:
Windpicker-owo
2025-09-28 20:40:46 +08:00
parent 9836d317b8
commit c31fd02daf
28 changed files with 526 additions and 604 deletions

View File

@@ -542,7 +542,22 @@ class PluginManager:
plugin_instance.on_unload()
# 从组件注册表中移除插件的所有组件
asyncio.run(component_registry.unregister_plugin(plugin_name))
try:
loop = asyncio.get_event_loop()
if loop.is_running():
fut = asyncio.run_coroutine_threadsafe(
component_registry.unregister_plugin(plugin_name), loop
)
fut.result(timeout=5)
else:
asyncio.run(component_registry.unregister_plugin(plugin_name))
except Exception:
# 最后兜底:直接同步调用(如果 unregister_plugin 为非协程)或忽略错误
try:
# 如果 unregister_plugin 是普通函数
component_registry.unregister_plugin(plugin_name)
except Exception as e:
logger.debug(f"卸载插件时调用 component_registry.unregister_plugin 失败: {e}")
# 从已加载插件中移除
del self.loaded_plugins[plugin_name]