chore: remove legacy exception handler and adjust runtime class location

This commit is contained in:
2026-04-10 14:31:56 +08:00
parent d29dad4691
commit 663d66fdea
45 changed files with 27 additions and 525 deletions

View File

@@ -1,7 +1,7 @@
package work.slhaf.partner;
import work.slhaf.partner.framework.agent.Agent;
import work.slhaf.partner.runtime.interaction.WebSocketGatewayRegistration;
import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration;
public class Main {
public static void main(String[] args) {

View File

@@ -1,24 +0,0 @@
package work.slhaf.partner.common.config;
import lombok.Data;
@Data
public class Config {
private String agentId;
private WebSocketConfig webSocketConfig;
private VectorConfig vectorConfig;
@Data
public static class VectorConfig {
private int type;
private String ollamaEmbeddingUrl;
private String ollamaEmbeddingModel;
private String tokenizerPath;
private String embeddingModelPath;
}
@Data
public static class WebSocketConfig {
private int port;
}
}

View File

@@ -1,13 +0,0 @@
package work.slhaf.partner.common.exception;
import work.slhaf.partner.framework.agent.factory.config.exception.ConfigFactoryInitFailedException;
public class ConfigLoadFailedException extends ConfigFactoryInitFailedException {
public ConfigLoadFailedException(String message, Throwable cause) {
super(message, cause);
}
public ConfigLoadFailedException(String message) {
super(message);
}
}

View File

@@ -1,13 +0,0 @@
package work.slhaf.partner.common.exception;
import work.slhaf.partner.framework.agent.exception.AgentLaunchFailedException;
public class ServiceLoadFailedException extends AgentLaunchFailedException {
public ServiceLoadFailedException(String message, Throwable cause) {
super(message, cause);
}
public ServiceLoadFailedException(String message) {
super(message);
}
}

View File

@@ -1,16 +0,0 @@
package work.slhaf.partner.core.action.entity;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import java.util.List;
@Data
public class GeneratedData {
private List<String> dependencies;
private String code;
private String codeType;
private String launcher;
private boolean serialize;
private JSONObject responseSchema;
}

View File

@@ -1,5 +0,0 @@
package work.slhaf.partner.core.action.entity;
public class McpData {
}

View File

@@ -1,11 +0,0 @@
package work.slhaf.partner.core.action.entity.cache;
import lombok.Data;
import java.util.List;
@Data
public class CacheAdjustData {
private String input;
private List<CacheAdjustMetaData> metaDataList;
}

View File

@@ -1,10 +0,0 @@
package work.slhaf.partner.core.action.entity.cache;
import lombok.Data;
@Data
public class CacheAdjustMetaData {
private String tendency;
private boolean passed;
private boolean hit;
}

View File

@@ -1,13 +0,0 @@
package work.slhaf.partner.core.action.exception;
import work.slhaf.partner.framework.agent.exception.AgentRuntimeException;
public class ActionDataNotFoundException extends AgentRuntimeException {
public ActionDataNotFoundException(String message) {
super(message);
}
public ActionDataNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -1,13 +0,0 @@
package work.slhaf.partner.core.action.exception;
import work.slhaf.partner.framework.agent.exception.AgentRuntimeException;
public class ActionLoadFailedException extends AgentRuntimeException {
public ActionLoadFailedException(String message) {
super(message);
}
public ActionLoadFailedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -15,7 +15,7 @@ import work.slhaf.partner.common.mcp.InProcessMcpTransport;
import work.slhaf.partner.core.action.entity.MetaActionInfo;
import work.slhaf.partner.core.action.exception.ActionInitFailedException;
import work.slhaf.partner.core.action.runner.execution.CommandExecutionService;
import work.slhaf.partner.framework.agent.common.support.DirectoryWatchSupport;
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport;
import java.io.File;
import java.io.IOException;

View File

@@ -10,7 +10,7 @@ import work.slhaf.partner.core.action.entity.MetaActionInfo;
import work.slhaf.partner.core.action.runner.LocalRunnerClient;
import work.slhaf.partner.core.action.runner.policy.ExecutionPolicy;
import work.slhaf.partner.core.action.runner.policy.RunnerExecutionPolicyListener;
import work.slhaf.partner.framework.agent.common.support.DirectoryWatchSupport;
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport;
import java.io.File;
import java.io.IOException;

View File

@@ -1,7 +1,7 @@
package work.slhaf.partner.core.action.runner.mcp;
import lombok.extern.slf4j.Slf4j;
import work.slhaf.partner.framework.agent.common.support.DirectoryWatchSupport;
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport;
import java.io.IOException;
import java.nio.file.Files;

View File

@@ -13,7 +13,7 @@ import work.slhaf.partner.framework.agent.model.pojo.Message;
import work.slhaf.partner.framework.agent.state.State;
import work.slhaf.partner.framework.agent.state.StateSerializable;
import work.slhaf.partner.framework.agent.state.StateValue;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.nio.file.Path;
import java.util.ArrayList;

View File

@@ -1,7 +0,0 @@
package work.slhaf.partner.core.memory.exception;
public class NullSliceListException extends RuntimeException {
public NullSliceListException(String message) {
super(message);
}
}

View File

@@ -2,21 +2,12 @@ package work.slhaf.partner.core.memory.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import java.io.Serial;
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SliceRef extends PersistableObject {
@Serial
private static final long serialVersionUID = 1L;
public class SliceRef {
private String unitId;
private String sliceId;
}

View File

@@ -1,82 +0,0 @@
package work.slhaf.partner.core.memory.pojo.node;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import work.slhaf.partner.core.memory.exception.NullSliceListException;
import work.slhaf.partner.core.memory.pojo.MemorySlice;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
public class MemoryNode extends PersistableObject implements Comparable<MemoryNode> {
@Serial
private static final long serialVersionUID = 1L;
private static String SLICE_DATA_DIR = "./data/memory/slice/";
/**
* 记忆节点唯一标识, 用于作为实际文件名, 如(xxxx-xxxxx-xxxxx.slice)
*/
private String memoryNodeId;
/**
* 记忆节点所属日期
*/
private LocalDate localDate;
/**
* 该日期对应的全部记忆切片
*/
private CopyOnWriteArrayList<MemorySlice> memorySliceList;
@Override
public int compareTo(MemoryNode memoryNode) {
if (memoryNode.getLocalDate().isAfter(this.localDate)) {
return -1;
} else if (memoryNode.getLocalDate().isBefore(this.localDate)) {
return 1;
}
return 0;
}
public List<MemorySlice> loadMemorySliceList() throws IOException, ClassNotFoundException {
//检查是否存在对应文件
File file = new File(SLICE_DATA_DIR + this.getMemoryNodeId() + ".slice");
if (file.exists()) {
this.memorySliceList = deserialize(file);
} else {
//逻辑正常的话这部分应该不会出现除非在insertMemory中进行save操作之前出现异常中断了方法但程序却没有结束
this.memorySliceList = new CopyOnWriteArrayList<>();
}
return this.memorySliceList;
}
public void saveMemorySliceList() throws IOException {
if (memorySliceList == null) {
throw new NullSliceListException("memorySliceList为NULL! 检查实现逻辑!");
}
File file = new File(SLICE_DATA_DIR + this.getMemoryNodeId() + ".slice");
Files.createDirectories(Path.of(SLICE_DATA_DIR));
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) {
oos.writeObject(this.memorySliceList);
}
//取消切片挂载, 释放内存
this.memorySliceList = null;
}
private CopyOnWriteArrayList<MemorySlice> deserialize(File file) throws IOException, ClassNotFoundException {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
return (CopyOnWriteArrayList<MemorySlice>) ois.readObject();
}
}
}

View File

@@ -1,20 +0,0 @@
package work.slhaf.partner.core.memory.pojo.node;
import lombok.Data;
import lombok.EqualsAndHashCode;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import java.io.Serial;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@EqualsAndHashCode(callSuper = true)
@Data
public class TopicNode extends PersistableObject {
@Serial
private static final long serialVersionUID = 1L;
private ConcurrentHashMap<String, TopicNode> topicNodes = new ConcurrentHashMap<>();
private CopyOnWriteArrayList<MemoryNode> memoryNodes = new CopyOnWriteArrayList<>();
}

View File

@@ -1,53 +0,0 @@
package work.slhaf.partner.core.perceive.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import java.io.Serial;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class User extends PersistableObject {
@Serial
private static final long serialVersionUID = 1L;
private String uuid;
private String nickName;
private HashMap<String/*platform*/, String> info = new HashMap<>();
private String relation = Constant.Relation.STRANGER;
// private HashMap<LocalDate, String> events = new HashMap<>();
private List<String> impressions = new ArrayList<>();
private List<String> attitude = new ArrayList<>();
private LinkedHashMap<LocalDate, String> relationChange = new LinkedHashMap<>();
private HashMap<String, String> staticMemory = new HashMap<>();
public void addInfo(String platform, String userInfo) {
this.info.put(platform, userInfo);
}
public void updateRelationChange(String changeReason) {
relationChange.put(LocalDate.now(), changeReason);
}
public void updateRelationChange(LocalDate date, String changeReason) {
relationChange.put(date, changeReason);
}
public void updateRelationChange(LinkedHashMap<LocalDate, String> tempRelationChange) {
relationChange.putAll(tempRelationChange);
}
public static class Constant {
public static class Relation {
public static final String STRANGER = "陌生";
}
}
}

View File

@@ -1,14 +0,0 @@
package work.slhaf.partner.module.action.executor.exception;
import work.slhaf.partner.framework.agent.exception.AgentRuntimeException;
public class ActionExecutingFailedException extends AgentRuntimeException {
public ActionExecutingFailedException(String message) {
super(message);
}
public ActionExecutingFailedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -22,7 +22,7 @@ import work.slhaf.partner.module.action.planner.evaluator.entity.EvaluatorResult
import work.slhaf.partner.module.action.planner.extractor.ActionExtractor;
import work.slhaf.partner.module.action.planner.extractor.entity.ExtractorResult;
import work.slhaf.partner.module.action.scheduler.ActionScheduler;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

View File

@@ -12,7 +12,7 @@ import work.slhaf.partner.framework.agent.factory.component.annotation.Init;
import work.slhaf.partner.framework.agent.model.ActivateModel;
import work.slhaf.partner.framework.agent.model.StreamChatMessageConsumer;
import work.slhaf.partner.framework.agent.model.pojo.Message;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;

View File

@@ -7,8 +7,6 @@ import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import work.slhaf.partner.core.cognition.CognitionCapability;
import work.slhaf.partner.core.memory.MemoryCapability;
import work.slhaf.partner.core.memory.exception.UnExistedDateIndexException;
import work.slhaf.partner.core.memory.exception.UnExistedTopicException;
import work.slhaf.partner.core.memory.pojo.MemorySlice;
import work.slhaf.partner.core.memory.pojo.MemoryUnit;
import work.slhaf.partner.core.memory.pojo.SliceRef;
@@ -19,6 +17,8 @@ import work.slhaf.partner.framework.agent.model.pojo.Message;
import work.slhaf.partner.framework.agent.state.State;
import work.slhaf.partner.framework.agent.state.StateSerializable;
import work.slhaf.partner.framework.agent.state.StateValue;
import work.slhaf.partner.module.memory.runtime.exception.UnExistedDateIndexException;
import work.slhaf.partner.module.memory.runtime.exception.UnExistedTopicException;
import work.slhaf.partner.module.memory.selector.ActivatedMemorySlice;
import java.nio.file.Path;

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.core.memory.exception;
package work.slhaf.partner.module.memory.runtime.exception;
public class UnExistedDateIndexException extends RuntimeException {
public UnExistedDateIndexException(String message) {

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.core.memory.exception;
package work.slhaf.partner.module.memory.runtime.exception;
public class UnExistedTopicException extends RuntimeException {
public UnExistedTopicException(String message) {

View File

@@ -2,22 +2,14 @@ package work.slhaf.partner.module.memory.selector;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import work.slhaf.partner.framework.agent.model.pojo.Message;
import java.io.Serial;
import java.time.LocalDate;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
public class ActivatedMemorySlice extends PersistableObject {
@Serial
private static final long serialVersionUID = 1L;
public class ActivatedMemorySlice {
private String unitId;
private String sliceId;
private LocalDate date;

View File

@@ -11,20 +11,20 @@ import work.slhaf.partner.core.action.ActionCore;
import work.slhaf.partner.core.cognition.BlockContent;
import work.slhaf.partner.core.cognition.CognitionCapability;
import work.slhaf.partner.core.cognition.ContextBlock;
import work.slhaf.partner.core.memory.exception.UnExistedDateIndexException;
import work.slhaf.partner.core.memory.exception.UnExistedTopicException;
import work.slhaf.partner.framework.agent.factory.capability.annotation.InjectCapability;
import work.slhaf.partner.framework.agent.factory.component.abstracts.AbstractAgentModule;
import work.slhaf.partner.framework.agent.factory.component.annotation.InjectModule;
import work.slhaf.partner.framework.agent.model.pojo.Message;
import work.slhaf.partner.module.memory.runtime.MemoryRuntime;
import work.slhaf.partner.module.memory.runtime.exception.UnExistedDateIndexException;
import work.slhaf.partner.module.memory.runtime.exception.UnExistedTopicException;
import work.slhaf.partner.module.memory.selector.evaluator.SliceSelectEvaluator;
import work.slhaf.partner.module.memory.selector.evaluator.entity.EvaluatorInput;
import work.slhaf.partner.module.memory.selector.extractor.MemorySelectExtractor;
import work.slhaf.partner.module.memory.selector.extractor.entity.ExtractorInput;
import work.slhaf.partner.module.memory.selector.extractor.entity.ExtractorMatchData;
import work.slhaf.partner.module.memory.selector.extractor.entity.ExtractorResult;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.time.LocalDate;
import java.time.LocalDateTime;

View File

@@ -26,7 +26,7 @@ import work.slhaf.partner.module.memory.updater.summarizer.MultiSummarizer;
import work.slhaf.partner.module.memory.updater.summarizer.SingleSummarizer;
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeInput;
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeResult;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.util.List;
import java.util.concurrent.ExecutorService;

View File

@@ -1,7 +0,0 @@
package work.slhaf.partner.module.memory.updater.exception;
public class UnExpectedMessageCountException extends RuntimeException {
public UnExpectedMessageCountException(String message) {
super(message);
}
}

View File

@@ -10,7 +10,7 @@ import work.slhaf.partner.core.cognition.ContextBlock;
import work.slhaf.partner.core.perceive.PerceiveCapability;
import work.slhaf.partner.framework.agent.factory.capability.annotation.InjectCapability;
import work.slhaf.partner.framework.agent.factory.component.abstracts.AbstractAgentModule;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.runtime.interaction.data.context
package work.slhaf.partner.runtime
import work.slhaf.partner.framework.agent.interaction.flow.RunningFlowContext

View File

@@ -1,54 +0,0 @@
package work.slhaf.partner.runtime.exception;
import lombok.extern.slf4j.Slf4j;
import work.slhaf.partner.framework.agent.exception.AgentExceptionCallback;
import work.slhaf.partner.framework.agent.exception.AgentLaunchFailedException;
import work.slhaf.partner.framework.agent.exception.AgentRuntimeException;
import work.slhaf.partner.runtime.exception.pojo.GlobalExceptionData;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@Slf4j
public class PartnerExceptionCallback implements AgentExceptionCallback {
private static final String EXCEPTION_SNAPSHOTS_PATH = "./data/exception/snapshots/";
private static final String EXCEPTION_LOG_PATH = "./data/exception/log/";
@Override
public void onRuntimeException(AgentRuntimeException exception) {
GlobalExceptionData exceptionData = new GlobalExceptionData();
Path filePath = Paths.get(EXCEPTION_SNAPSHOTS_PATH, exceptionData.getExceptionTime() + ".dat");
try {
Files.createDirectories(Path.of(EXCEPTION_SNAPSHOTS_PATH));
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filePath.toFile()));
oos.writeObject(exceptionData);
oos.close();
BufferedWriter logWriter = new BufferedWriter(new FileWriter(EXCEPTION_LOG_PATH + exceptionData.getExceptionTime() + ".log"));
logWriter.write(exception.getMessage());
logWriter.close();
log.warn("[GlobalExceptionHandler] 捕获异常, 状态快照已保存到: {}", filePath);
log.warn("[GlobalExceptionHandler] 捕获异常, 异常日志已保存到: {}", EXCEPTION_LOG_PATH + exceptionData.getExceptionTime() + ".log");
} catch (IOException e) {
log.error("[GlobalExceptionHandler] 捕获异常, 保存失败: ", e);
}
}
@Override
public void onFailedException(AgentLaunchFailedException exception) {
Path filepath = Paths.get(EXCEPTION_LOG_PATH, System.currentTimeMillis() + ".log");
try {
Files.createDirectories(Path.of(EXCEPTION_LOG_PATH));
BufferedWriter logWriter = new BufferedWriter(new FileWriter(EXCEPTION_LOG_PATH + System.currentTimeMillis() + ".log"));
logWriter.write(exception.getMessage());
logWriter.close();
log.warn("[GlobalExceptionHandler] 捕获启动失败异常, 异常日志已保存到: {}", filepath);
} catch (IOException ex) {
log.error("[GlobalExceptionHandler] 捕获启动失败异常, 保存失败: ", ex);
}
}
}

View File

@@ -1,23 +0,0 @@
package work.slhaf.partner.runtime.exception.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
@EqualsAndHashCode(callSuper = true)
@Slf4j
@Data
public class GlobalException extends RuntimeException {
private GlobalExceptionData data;
public GlobalException(String message) {
super(message);
try {
this.data = new GlobalExceptionData();
} catch (Exception e) {
log.error("[GlobalException] 捕获异常, 获取数据失败");
}
}
}

View File

@@ -1,17 +0,0 @@
package work.slhaf.partner.runtime.exception.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import work.slhaf.partner.framework.agent.common.entity.PersistableObject;
import java.io.Serial;
@EqualsAndHashCode(callSuper = true)
@Data
public class GlobalExceptionData extends PersistableObject {
@Serial
private static final long serialVersionUID = 1L;
protected Long exceptionTime = System.currentTimeMillis();
private String exceptionMessage;
}

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.runtime.interaction;
package work.slhaf.partner.runtime.gateway;
import com.alibaba.fastjson2.JSONObject;
import lombok.ToString;
@@ -13,7 +13,7 @@ import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration;
import work.slhaf.partner.framework.agent.interaction.AgentRuntime;
import work.slhaf.partner.framework.agent.interaction.data.InputData;
import work.slhaf.partner.framework.agent.interaction.data.InteractionEvent;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
import work.slhaf.partner.runtime.PartnerRunningFlowContext;
import java.net.InetSocketAddress;
import java.util.concurrent.ConcurrentHashMap;

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.runtime.interaction
package work.slhaf.partner.runtime.gateway
import work.slhaf.partner.framework.agent.interaction.AgentGateway
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration

View File

@@ -1,6 +0,0 @@
package work.slhaf.partner.framework.agent.common.entity;
import java.io.Serializable;
public abstract class PersistableObject implements Serializable {
}

View File

@@ -3,8 +3,8 @@ package work.slhaf.partner.framework.agent.config
import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject
import org.slf4j.LoggerFactory
import work.slhaf.partner.framework.agent.common.support.DirectoryWatchSupport
import work.slhaf.partner.framework.agent.exception.AgentLaunchFailedException
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport
import java.io.IOException
import java.lang.reflect.Field
import java.lang.reflect.Modifier

View File

@@ -1,7 +0,0 @@
package work.slhaf.partner.framework.agent.exception;
public interface AgentExceptionCallback {
void onRuntimeException(AgentRuntimeException e);
void onFailedException(AgentLaunchFailedException e);
}

View File

@@ -1,39 +0,0 @@
package work.slhaf.partner.framework.agent.exception;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GlobalExceptionHandler {
public static GlobalExceptionHandler INSTANCE = new GlobalExceptionHandler();
private AgentExceptionCallback exceptionCallback = new LogAgentExceptionCallback();
public static void setExceptionCallback(AgentExceptionCallback callback) {
INSTANCE.exceptionCallback = callback;
}
public boolean handle(Throwable e) {
boolean exit;
Throwable cause = e.getCause();
switch (cause) {
case AgentRunningFailedException arfe -> {
exit = true;
exceptionCallback.onRuntimeException((AgentRuntimeException) cause);
}
case AgentRuntimeException are -> {
exit = false;
exceptionCallback.onRuntimeException((AgentRuntimeException) cause);
}
case AgentLaunchFailedException alfe -> {
exit = true;
exceptionCallback.onFailedException((AgentLaunchFailedException) cause);
}
default -> {
exit = true;
log.error("意外异常: ", cause);
}
}
return exit;
}
}

View File

@@ -1,17 +0,0 @@
package work.slhaf.partner.framework.agent.exception;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LogAgentExceptionCallback implements AgentExceptionCallback {
@Override
public void onRuntimeException(AgentRuntimeException e) {
log.error("Agent 运行异常: ", e);
}
@Override
public void onFailedException(AgentLaunchFailedException e) {
throw e;
}
}

View File

@@ -1,11 +0,0 @@
package work.slhaf.partner.framework.agent.factory.exception;
public class ExternalModulePathNotExistException extends AgentRegisterFactoryFailedException {
public ExternalModulePathNotExistException(String message) {
super(message);
}
public ExternalModulePathNotExistException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -4,13 +4,11 @@ import com.alibaba.fastjson2.annotation.JSONCreator
import com.alibaba.fastjson2.annotation.JSONField
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue
import work.slhaf.partner.framework.agent.common.entity.PersistableObject
import java.io.Serial
data class Message(
val role: Character,
val content: String
) : PersistableObject() {
) {
fun roleValue(): String = role.value
@@ -34,8 +32,4 @@ data class Message(
}
}
companion object {
@Serial
private const val serialVersionUID = 1L
}
}

View File

@@ -1,4 +1,4 @@
package work.slhaf.partner.framework.agent.common.support;
package work.slhaf.partner.framework.agent.support;
import lombok.extern.slf4j.Slf4j;

View File

@@ -3,7 +3,7 @@ package work.slhaf.partner.framework.common.support;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import work.slhaf.partner.framework.agent.common.support.DirectoryWatchSupport;
import work.slhaf.partner.framework.agent.support.DirectoryWatchSupport;
import java.io.IOException;
import java.nio.file.Files;