mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
fix(plugins): 展开模块级别插件名为具体函数名
在一个 function 文件中可能注册多个 @register_function,当配置下发或 本地配置使用模块名(文件名)时,需要自动展开为具体的函数名列表。 改动内容: - register.py: 新增 module_func_map 全局映射,在 register_function 装饰器中自动记录模块名 → 函数名列表的映射关系 - connection.py: 处理服务端下发的插件配置时,将模块级的 plugins 配置 复制到各具体函数名 key 下,并将模块名展开写入 Intent functions 列表 - plugin_executor.py: 新增 _expand_plugin_names() 兜底展开逻辑和 _get_plugin_description() 双层查找方法,确保本地配置场景也能正确展开
This commit is contained in:
@@ -78,6 +78,8 @@ class DeviceTypeRegistry:
|
||||
|
||||
# 初始化函数注册字典
|
||||
all_function_registry = {}
|
||||
# 模块名 -> 函数名列表的映射,用于将模块级别的插件名展开为具体的函数名
|
||||
module_func_map = {}
|
||||
|
||||
|
||||
def register_function(name, desc, type=None):
|
||||
@@ -85,6 +87,9 @@ def register_function(name, desc, type=None):
|
||||
|
||||
def decorator(func):
|
||||
all_function_registry[name] = FunctionItem(name, desc, func, type)
|
||||
# 记录模块名到函数名的映射,用于 expand 模块级别的插件配置
|
||||
module_name = func.__module__.split(".")[-1]
|
||||
module_func_map.setdefault(module_name, []).append(name)
|
||||
logger.bind(tag=TAG).debug(f"函数 '{name}' 已加载,可以注册使用")
|
||||
return func
|
||||
|
||||
|
||||
Reference in New Issue
Block a user