菜单优化

This commit is contained in:
张家训
2026-06-08 17:40:57 +08:00
parent ecdfb1f1a1
commit b76a2a451e
11 changed files with 295 additions and 223 deletions
@@ -20,6 +20,7 @@ public class ToolRegistry {
private final WorkUtilsProperties properties;
private List<Tool> enabledTools;
private Map<String, Tool> toolByIdMap;
private Map<String, Tool> toolByCommandMap;
/**
* Spring自动注入所有Tool Bean
@@ -35,12 +36,17 @@ public class ToolRegistry {
Set<String> enabledIds = resolveEnabledIds();
this.enabledTools = new ArrayList<>();
this.toolByIdMap = new LinkedHashMap<>();
this.toolByCommandMap = new LinkedHashMap<>();
for (Tool tool : allTools) {
try {
if (enabledIds == null || enabledIds.contains(tool.getId())) {
enabledTools.add(tool);
toolByIdMap.put(tool.getId(), tool);
String cmd = tool.getCommandName();
if (cmd != null && !cmd.isEmpty()) {
toolByCommandMap.put(cmd, tool);
}
log.info("注册工具: {} [{}]", tool.getName(), tool.getId());
} else {
log.info("跳过已禁用工具: {} [{}]", tool.getName(), tool.getId());
@@ -68,6 +74,13 @@ public class ToolRegistry {
return Optional.ofNullable(toolByIdMap.get(id));
}
/**
* 按命令行命令名查找工具
*/
public Optional<Tool> getToolByCommand(String command) {
return Optional.ofNullable(toolByCommandMap.get(command));
}
/**
* 根据配置解析启用的工具ID集合
* 优先级: enabled白名单 > disabled黑名单 > 全部启用