mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(framework): remove coordinated capability mechanism and related manager/annotations
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package work.slhaf.partner.core;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CoordinateManager;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated;
|
||||
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.core.cognation.CognationCore;
|
||||
import work.slhaf.partner.core.memory.MemoryCore;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static work.slhaf.partner.common.util.ExtractUtil.extractUserId;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@CoordinateManager
|
||||
public class CoordinatedManager implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//在框架将自动注入core,详见CapabilityRegistryFactory
|
||||
private CognationCore cognationCore;
|
||||
private MemoryCore memoryCore;
|
||||
|
||||
|
||||
private boolean isCacheSingleUser() {
|
||||
return memoryCore.getUserDialogMap().size() <= 1;
|
||||
}
|
||||
|
||||
@Coordinated(capability = "cognation")
|
||||
public boolean isSingleUser() {
|
||||
return isCacheSingleUser() && isChatMessagesSingleUser();
|
||||
}
|
||||
|
||||
private boolean isChatMessagesSingleUser() {
|
||||
Set<String> userIdSet = new HashSet<>();
|
||||
cognationCore.getChatMessages().forEach(m -> {
|
||||
if (m.getRole().equals(ChatConstant.Character.ASSISTANT)) {
|
||||
return;
|
||||
}
|
||||
String userId = extractUserId(m.getContent());
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
userIdSet.add(userId);
|
||||
});
|
||||
return userIdSet.size() <= 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package work.slhaf.partner.core.cognation;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.api.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.chat.pojo.MetaMessage;
|
||||
|
||||
@@ -32,6 +31,4 @@ public interface CognationCapability {
|
||||
|
||||
String getCurrentMemoryId();
|
||||
|
||||
@ToCoordinated
|
||||
boolean isSingleUser();
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package work.slhaf.partner.api.agent.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Core的协调类,该注解的实现类中如果存在任何{@link CapabilityCore}实例的引用,都将被自动注入
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CoordinateManager {
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package work.slhaf.partner.api.agent.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 用于标注协调方法,`value`值需与对应的`@ToCoordinated`保持一致
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface Coordinated {
|
||||
String capability();
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package work.slhaf.partner.api.agent.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 当`@Capability`所注接口中,如果存在方法需要协调多个Core服务的调用,可以通过该注解进行排除
|
||||
* value值为方法对应标识,需与协调实现处的方法标识保持一致
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ToCoordinated {
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package work.slhaf.demo.service;
|
||||
|
||||
import work.slhaf.demo.service.core.BTestCore;
|
||||
import work.slhaf.demo.service.core.CTestCore;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CoordinateManager;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated;
|
||||
|
||||
@CoordinateManager
|
||||
public class TestCoordinateManager {
|
||||
private BTestCore bTestCore = new BTestCore();
|
||||
private CTestCore cTestCore = new CTestCore();
|
||||
|
||||
@Coordinated(capability = "test_c")
|
||||
public void testMethodCoordinate(String input) {
|
||||
String resultB = bTestCore.testCoordinateSubMethod();
|
||||
cTestCore.testCoordinateSubMethod(resultB);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package work.slhaf.demo.service.capability;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
||||
|
||||
@Capability("test_c")
|
||||
public interface CTestCapability {
|
||||
void testMethodNormalA(String input);
|
||||
|
||||
@ToCoordinated
|
||||
void testMethodCoordinate(String input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user