mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
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:
@@ -1,16 +1,8 @@
|
|||||||
package work.slhaf.partner.core.action.entity;
|
package work.slhaf.partner.core.action.entity;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import lombok.Data;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -32,31 +24,4 @@ public class MetaActionInfo {
|
|||||||
private boolean strictDependencies;
|
private boolean strictDependencies;
|
||||||
|
|
||||||
private JSONObject responseSchema;
|
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<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
if (!complete)
|
if (!complete)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
MetaActionInfo newActionInfo = new MetaActionInfo(thisDir.toFile());
|
MetaActionInfo newActionInfo = new MetaActionInfo();
|
||||||
existedMetaActions.put(thisDir.toString(), newActionInfo);
|
existedMetaActions.put(thisDir.toString(), newActionInfo);
|
||||||
} catch (ActionLoadFailedException e) {
|
} catch (ActionLoadFailedException e) {
|
||||||
log.warn("行动信息重新加载失败,触发行为: {}", kind.name());
|
log.warn("行动信息重新加载失败,触发行为: {}", kind.name());
|
||||||
@@ -366,7 +366,7 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
}
|
}
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
try {
|
try {
|
||||||
MetaActionInfo actionInfo = new MetaActionInfo(f);
|
MetaActionInfo actionInfo = new MetaActionInfo();
|
||||||
existedMetaActions.put(f.getName(), actionInfo);
|
existedMetaActions.put(f.getName(), actionInfo);
|
||||||
log.info("行动程序[{}]已加载", actionInfo.getKey());
|
log.info("行动程序[{}]已加载", actionInfo.getKey());
|
||||||
} catch (ActionLoadFailedException e) {
|
} catch (ActionLoadFailedException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user