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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user