mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(action): reorganize constants in action module
This commit is contained in:
@@ -5,8 +5,6 @@ public final class Constant {
|
|||||||
public static final class Path {
|
public static final class Path {
|
||||||
public static final String DATA = "data";
|
public static final String DATA = "data";
|
||||||
public static final String MEMORY_DATA = DATA + "/memory";
|
public static final String MEMORY_DATA = DATA + "/memory";
|
||||||
public static final String ACTION_PROGRAM = DATA + "/action";
|
|
||||||
public static final String TMP_ACTION_DIR_LOCAL = ACTION_PROGRAM + "/tmp";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package work.slhaf.partner.common.util;
|
||||||
|
|
||||||
|
public class PathUtil {
|
||||||
|
public static String buildPathStr(String... path) {
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
for (int i = 0; i < path.length; i++) {
|
||||||
|
str.append(path[i]);
|
||||||
|
if (i < path.length - 1) {
|
||||||
|
str.append("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,11 +40,16 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static work.slhaf.partner.common.Constant.Path.TMP_ACTION_DIR_LOCAL;
|
import static work.slhaf.partner.common.util.PathUtil.buildPathStr;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LocalRunnerClient extends RunnerClient {
|
public class LocalRunnerClient extends RunnerClient {
|
||||||
|
|
||||||
|
private final String TMP_ACTION_PATH = buildPathStr(ACTION_PATH, "tmp");
|
||||||
|
private final String DYNAMIC_ACTION_PATH = buildPathStr(ACTION_PATH, "dynamic");
|
||||||
|
private final String MCP_SERVER_PATH = buildPathStr(ACTION_PATH, "mcp");
|
||||||
|
private final String MCP_DESC_PATH = buildPathStr(MCP_SERVER_PATH, "desc");
|
||||||
|
|
||||||
private final Map<String, McpSyncClient> mcpClients = new HashMap<>();
|
private final Map<String, McpSyncClient> mcpClients = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* 动态生成的行动程序都将挂载至该 McpServer
|
* 动态生成的行动程序都将挂载至该 McpServer
|
||||||
@@ -52,8 +57,8 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
private McpStatelessAsyncServer dynamicActionMcpServer;
|
private McpStatelessAsyncServer dynamicActionMcpServer;
|
||||||
private final WatchService watchService;
|
private final WatchService watchService;
|
||||||
|
|
||||||
public LocalRunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor, @Nullable String actionWatchPath) {
|
public LocalRunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor, @Nullable String baseActionPath) {
|
||||||
super(existedMetaActions, executor);
|
super(existedMetaActions, executor, baseActionPath);
|
||||||
try {
|
try {
|
||||||
watchService = FileSystems.getDefault().newWatchService();
|
watchService = FileSystems.getDefault().newWatchService();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -143,7 +148,7 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String buildTmpPath(MetaAction tempAction, String codeType) {
|
public String buildTmpPath(MetaAction tempAction, String codeType) {
|
||||||
return Path.of(TMP_ACTION_DIR_LOCAL, System.currentTimeMillis() + "-" + tempAction.getKey() + codeType).toString();
|
return Path.of(TMP_ACTION_PATH, System.currentTimeMillis() + "-" + tempAction.getKey() + codeType).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package work.slhaf.partner.core.action.runner;
|
package work.slhaf.partner.core.action.runner;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import io.modelcontextprotocol.server.McpStatelessAsyncServer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import work.slhaf.partner.core.action.entity.McpData;
|
import work.slhaf.partner.core.action.entity.McpData;
|
||||||
import work.slhaf.partner.core.action.entity.MetaAction;
|
import work.slhaf.partner.core.action.entity.MetaAction;
|
||||||
import work.slhaf.partner.core.action.entity.MetaAction.Result;
|
import work.slhaf.partner.core.action.entity.MetaAction.Result;
|
||||||
@@ -13,6 +15,9 @@ import java.io.IOException;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import static work.slhaf.partner.common.Constant.Path.DATA;
|
||||||
|
import static work.slhaf.partner.common.util.PathUtil.buildPathStr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行客户端抽象类
|
* 执行客户端抽象类
|
||||||
* <br/>
|
* <br/>
|
||||||
@@ -33,15 +38,19 @@ import java.util.concurrent.ExecutorService;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class RunnerClient {
|
public abstract class RunnerClient {
|
||||||
|
|
||||||
|
protected final String ACTION_PATH;
|
||||||
|
|
||||||
protected final ConcurrentHashMap<String, MetaActionInfo> existedMetaActions;
|
protected final ConcurrentHashMap<String, MetaActionInfo> existedMetaActions;
|
||||||
protected final ExecutorService executor;
|
protected final ExecutorService executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActionCore 将注入虚拟线程池
|
* ActionCore 将注入虚拟线程池
|
||||||
*/
|
*/
|
||||||
public RunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor) {
|
public RunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor, @Nullable String baseActionPath) {
|
||||||
this.existedMetaActions = existedMetaActions;
|
this.existedMetaActions = existedMetaActions;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
|
baseActionPath = baseActionPath == null ? DATA : baseActionPath;
|
||||||
|
this.ACTION_PATH = buildPathStr(baseActionPath, "action");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user