refactor(MetaActionInfo): remove outdated constructor

Context:
Previously, MetaActionInfo comes from the local filesystem changes.
But now MCP Servers already provide a method to get information of MetaActions.
The pre- or post-dependencies are still required, for some MCP Tools cannot just be executed without additional context.
This commit is contained in:
2025-12-18 16:24:04 +08:00
parent 1e6ff1b30c
commit 0eee12d685
2 changed files with 2 additions and 37 deletions

View File

@@ -1,16 +1,8 @@
package work.slhaf.partner.core.action.entity;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import org.apache.commons.io.FileUtils;
import work.slhaf.partner.core.action.exception.ActionLoadFailedException;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,31 +24,4 @@ public class MetaActionInfo {
private boolean strictDependencies;
private JSONObject responseSchema;
public MetaActionInfo(File actionDir) {
if (actionDir.isFile()) {
throw new ActionLoadFailedException("Action directory expected, but file found: " + actionDir.getAbsolutePath());
}
File[] files = actionDir.listFiles();
if (files == null || files.length == 0) {
throw new ActionLoadFailedException("Action directory is empty: " + actionDir.getAbsolutePath());
}
//加载desc.json
File desc = Path.of(actionDir.getPath(), "desc.json").toFile();
if (!desc.exists() || desc.isDirectory()) {
throw new ActionLoadFailedException("Action desc.json not found: " + desc.getAbsolutePath());
}
try {
String s = FileUtils.readFileToString(desc, StandardCharsets.UTF_8);
MetaActionInfo temp = JSONObject.parseObject(s, MetaActionInfo.class);
BeanUtil.copyProperties(temp, this);
} catch (Exception e) {
throw new ActionLoadFailedException("Failed to load action desc.json: " + desc.getAbsolutePath(), e);
}
//进行必要的字段校验和初始化
if (type == null) throw new ActionLoadFailedException("Action type missing in desc.json");
if (params == null) params = new HashMap<>();
if (preActions == null) preActions = new ArrayList<>();
if (postActions == null) postActions = new ArrayList<>();
}
}

View File

@@ -282,7 +282,7 @@ public class LocalRunnerClient extends RunnerClient {
if (!complete)
return;
try {
MetaActionInfo newActionInfo = new MetaActionInfo(thisDir.toFile());
MetaActionInfo newActionInfo = new MetaActionInfo();
existedMetaActions.put(thisDir.toString(), newActionInfo);
} catch (ActionLoadFailedException e) {
log.warn("行动信息重新加载失败,触发行为: {}", kind.name());
@@ -366,7 +366,7 @@ public class LocalRunnerClient extends RunnerClient {
}
for (File f : files) {
try {
MetaActionInfo actionInfo = new MetaActionInfo(f);
MetaActionInfo actionInfo = new MetaActionInfo();
existedMetaActions.put(f.getName(), actionInfo);
log.info("行动程序[{}]已加载", actionInfo.getKey());
} catch (ActionLoadFailedException e) {