feat: enhance session ID calculation and plugin management
- Updated `calculate_session_id` method in `SessionUtils` to include optional `account_id` and `scope` parameters for more granular session ID generation. - Added new environment variables in `plugin_runtime` for external plugin dependencies and global configuration snapshots. - Introduced methods in `RuntimeComponentManagerProtocol` for loading and reloading plugins globally, accommodating external dependencies. - Enhanced `PluginRunnerSupervisor` to manage external available plugin IDs during plugin reloads. - Implemented dependency extraction and management in `PluginRuntimeManager` to handle cross-supervisor dependencies. - Added tests for session ID calculation and message registration in `ChatManager` to ensure correct behavior with new parameters.
This commit is contained in:
@@ -5,13 +5,22 @@ import hashlib
|
||||
|
||||
class SessionUtils:
|
||||
@staticmethod
|
||||
def calculate_session_id(platform: str, *, user_id: Optional[str] = None, group_id: Optional[str] = None) -> str:
|
||||
def calculate_session_id(
|
||||
platform: str,
|
||||
*,
|
||||
user_id: Optional[str] = None,
|
||||
group_id: Optional[str] = None,
|
||||
account_id: Optional[str] = None,
|
||||
scope: Optional[str] = None,
|
||||
) -> str:
|
||||
"""计算session_id
|
||||
|
||||
Args:
|
||||
platform: 平台名称
|
||||
user_id: 用户ID(如果是私聊)
|
||||
group_id: 群ID(如果是群聊)
|
||||
account_id: 当前平台账号 ID,可选
|
||||
scope: 当前路由作用域,可选
|
||||
Returns:
|
||||
str: 计算得到的会话ID
|
||||
Raises:
|
||||
@@ -19,8 +28,15 @@ class SessionUtils:
|
||||
"""
|
||||
if not user_id and not group_id:
|
||||
raise ValueError("UserID 或 GroupID 必须提供其一")
|
||||
|
||||
route_components = []
|
||||
if account_id:
|
||||
route_components.append(f"account:{account_id}")
|
||||
if scope:
|
||||
route_components.append(f"scope:{scope}")
|
||||
|
||||
if group_id:
|
||||
components = [platform, group_id]
|
||||
components = [platform, *route_components, group_id]
|
||||
else:
|
||||
components = [platform, user_id, "private"]
|
||||
components = [platform, *route_components, user_id, "private"]
|
||||
return hashlib.md5("_".join(components).encode()).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user