mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(LocalRunnerClient): repair paths registering order and support creating directories automatically
This commit is contained in:
@@ -57,10 +57,10 @@ 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 TMP_ACTION_PATH;
|
||||||
private final String DYNAMIC_ACTION_PATH = buildPathStr(ACTION_PATH, "dynamic");
|
private final String DYNAMIC_ACTION_PATH;
|
||||||
private final String MCP_SERVER_PATH = buildPathStr(ACTION_PATH, "mcp");
|
private final String MCP_SERVER_PATH;
|
||||||
private final String MCP_DESC_PATH = buildPathStr(MCP_SERVER_PATH, "desc");
|
private final String MCP_DESC_PATH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储包括 DescMcp、DynamicActionMcp、CommonMcp 在内的所有 MCP Server 对应的客户端
|
* 存储包括 DescMcp、DynamicActionMcp、CommonMcp 在内的所有 MCP Server 对应的客户端
|
||||||
@@ -99,6 +99,13 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
|
|
||||||
public LocalRunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor, @Nullable String baseActionPath) {
|
public LocalRunnerClient(ConcurrentHashMap<String, MetaActionInfo> existedMetaActions, ExecutorService executor, @Nullable String baseActionPath) {
|
||||||
super(existedMetaActions, executor, baseActionPath);
|
super(existedMetaActions, executor, baseActionPath);
|
||||||
|
this.TMP_ACTION_PATH = buildPathStr(ACTION_PATH, "tmp");
|
||||||
|
this.DYNAMIC_ACTION_PATH = buildPathStr(ACTION_PATH, "dynamic");
|
||||||
|
this.MCP_SERVER_PATH = buildPathStr(ACTION_PATH, "mcp");
|
||||||
|
this.MCP_DESC_PATH = buildPathStr(MCP_SERVER_PATH, "desc");
|
||||||
|
|
||||||
|
createPaths();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
watchService = FileSystems.getDefault().newWatchService();
|
watchService = FileSystems.getDefault().newWatchService();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -110,6 +117,17 @@ public class LocalRunnerClient extends RunnerClient {
|
|||||||
setupShutdownHook();
|
setupShutdownHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createPaths() {
|
||||||
|
try {
|
||||||
|
Files.createDirectory(Path.of(TMP_ACTION_PATH));
|
||||||
|
Files.createDirectory(Path.of(DYNAMIC_ACTION_PATH));
|
||||||
|
Files.createDirectory(Path.of(MCP_SERVER_PATH));
|
||||||
|
Files.createDirectory(Path.of(MCP_DESC_PATH));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ActionInitFailedException("目录创建失败: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerCommonMcp() {
|
private void registerCommonMcp() {
|
||||||
val ctx = new WatchContext(Path.of(MCP_SERVER_PATH), watchService);
|
val ctx = new WatchContext(Path.of(MCP_SERVER_PATH), watchService);
|
||||||
val common = new LocalWatchEventProcessor.Common(existedMetaActions, mcpClients, ctx);
|
val common = new LocalWatchEventProcessor.Common(existedMetaActions, mcpClients, ctx);
|
||||||
|
|||||||
@@ -5,13 +5,16 @@ 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 org.jetbrains.annotations.Nullable;
|
||||||
import work.slhaf.partner.core.action.entity.McpData;
|
import work.slhaf.partner.core.action.entity.ActionFileMetaData;
|
||||||
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;
|
||||||
import work.slhaf.partner.core.action.entity.MetaAction.ResultStatus;
|
import work.slhaf.partner.core.action.entity.MetaAction.ResultStatus;
|
||||||
import work.slhaf.partner.core.action.entity.MetaActionInfo;
|
import work.slhaf.partner.core.action.entity.MetaActionInfo;
|
||||||
|
import work.slhaf.partner.core.action.exception.ActionInitFailedException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
@@ -51,6 +54,12 @@ public abstract class RunnerClient {
|
|||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
baseActionPath = baseActionPath == null ? DATA : baseActionPath;
|
baseActionPath = baseActionPath == null ? DATA : baseActionPath;
|
||||||
this.ACTION_PATH = buildPathStr(baseActionPath, "action");
|
this.ACTION_PATH = buildPathStr(baseActionPath, "action");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.createDirectory(Path.of(ACTION_PATH));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ActionInitFailedException("目录创建失败: " + ACTION_PATH, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user