mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(perceive): refactor into registering context via ContextWorkspace
This commit is contained in:
@@ -1,27 +1,49 @@
|
|||||||
package work.slhaf.partner.module.modules.perceive;
|
package work.slhaf.partner.module.modules.perceive;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
import work.slhaf.partner.api.agent.factory.component.abstracts.AbstractAgentModule;
|
import work.slhaf.partner.api.agent.factory.component.abstracts.AbstractAgentModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.ContextBlock;
|
import work.slhaf.partner.core.cognition.CognitionCapability;
|
||||||
|
import work.slhaf.partner.core.cognition.CommunicationBlockContent;
|
||||||
|
import work.slhaf.partner.core.cognition.ContextBlock;
|
||||||
import work.slhaf.partner.core.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
public class PerceiveMonitor extends AbstractAgentModule.Running<PartnerRunningFlowContext> {
|
public class PerceiveMonitor extends AbstractAgentModule.Running<PartnerRunningFlowContext> {
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
|
@InjectCapability
|
||||||
|
private CognitionCapability cognitionCapability;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(PartnerRunningFlowContext context) {
|
public void execute(PartnerRunningFlowContext context) {
|
||||||
context.getContextBlocks().add(new PerceiveBlock(perceiveCapability.refreshInteract()));
|
String lastInteractTime = perceiveCapability.refreshInteract();
|
||||||
|
ContextBlock block = new ContextBlock(
|
||||||
|
new CommunicationBlockContent(
|
||||||
|
"environment_perceive_info",
|
||||||
|
"perceive_monitor",
|
||||||
|
CommunicationBlockContent.Projection.SUPPLY
|
||||||
|
) {
|
||||||
|
@Override
|
||||||
|
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
||||||
|
appendTextElement(document, root, "last_interact_time", lastInteractTime);
|
||||||
|
appendTextElement(document, root, "current_time", ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Set.of(ContextBlock.VisibleDomain.COMMUNICATION),
|
||||||
|
100,
|
||||||
|
30,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
cognitionCapability.contextWorkspace().register(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -29,43 +51,4 @@ public class PerceiveMonitor extends AbstractAgentModule.Running<PartnerRunningF
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
private static class PerceiveBlock extends ContextBlock {
|
|
||||||
|
|
||||||
private String lastInteractTime;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPriority() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Type getType() {
|
|
||||||
return Type.CONTEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getBlockName() {
|
|
||||||
return "perceive_info";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getSource() {
|
|
||||||
return "perceive_monitor";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
|
||||||
Element lastInteractTime = document.createElement("last_interact_time");
|
|
||||||
lastInteractTime.setTextContent(this.lastInteractTime);
|
|
||||||
root.appendChild(lastInteractTime);
|
|
||||||
|
|
||||||
Element currentTime = document.createElement("current_time");
|
|
||||||
currentTime.setTextContent(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
||||||
root.appendChild(currentTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user