完善自动化任务广场目标选择
自动化任务目标改为从广场发布资源获取,不再按当前空间筛选。 任务中心允许任务归档空间与发布目标空间不同,并在执行时透传组件、技能和模型参数。
This commit is contained in:
@@ -9,6 +9,7 @@ import com.xspaceagi.agent.core.adapter.dto.TryReqDto;
|
||||
import com.xspaceagi.agent.core.adapter.dto.WorkflowExecuteRequestDto;
|
||||
import com.xspaceagi.agent.core.adapter.dto.config.ModelConfigDto;
|
||||
import com.xspaceagi.agent.core.adapter.dto.config.workflow.WorkflowConfigDto;
|
||||
import com.xspaceagi.agent.core.adapter.repository.entity.AgentComponentConfig;
|
||||
import com.xspaceagi.agent.core.adapter.repository.entity.Published;
|
||||
import com.xspaceagi.agent.core.infra.component.agent.dto.AgentExecuteResult;
|
||||
import com.xspaceagi.system.application.dto.SendNotifyMessageDto;
|
||||
@@ -84,7 +85,7 @@ public class TaskCenterApplicationServiceImpl implements TaskExecuteService {
|
||||
}
|
||||
|
||||
private void executeWorkflowTask(MonoSink<Boolean> sink, ScheduleTaskDto scheduleTask) {
|
||||
WorkflowConfigDto workflowConfigDto = workflowApplicationService.queryPublishedWorkflowConfig(Long.parseLong(scheduleTask.getTargetId()), scheduleTask.getSpaceId(), true);
|
||||
WorkflowConfigDto workflowConfigDto = workflowApplicationService.queryPublishedWorkflowConfig(Long.parseLong(scheduleTask.getTargetId()), null, true);
|
||||
if (workflowConfigDto == null) {
|
||||
sink.error(BizException.of(ErrorCodeEnum.INVALID_PARAM, BizExceptionCodeEnum.agentWorkflowOffline));
|
||||
return;
|
||||
@@ -133,13 +134,22 @@ public class TaskCenterApplicationServiceImpl implements TaskExecuteService {
|
||||
}
|
||||
});
|
||||
}
|
||||
mergeSelectedComponents(selectedComponents, params.get("selectedComponents"));
|
||||
TryReqDto tryReqDto = new TryReqDto();
|
||||
tryReqDto.setDebug(false);
|
||||
tryReqDto.setConversationId(conversation.getId());
|
||||
tryReqDto.setMessage(params.get("message").toString());
|
||||
tryReqDto.setSelectedComponents(selectedComponents);
|
||||
List<Long> skillIds = toLongList(params.get("skillIds"));
|
||||
if (!skillIds.isEmpty()) {
|
||||
tryReqDto.setSkillIds(skillIds);
|
||||
}
|
||||
Long modelId = toLong(params.get("modelId"));
|
||||
if (modelId != null) {
|
||||
tryReqDto.setModelId(modelId);
|
||||
}
|
||||
try {
|
||||
if (YesOrNoEnum.Y.getKey().equals(conversation.getAgent().getAllowOtherModel())) {
|
||||
if (tryReqDto.getModelId() == null && YesOrNoEnum.Y.getKey().equals(conversation.getAgent().getAllowOtherModel())) {
|
||||
List<ModelConfigDto> modelConfigDtos = agentApplicationService.queryUserCanSelectModelListForAgent(conversation.getUserId(), conversation.getAgentId());
|
||||
if (!CollectionUtils.isEmpty(modelConfigDtos)) {
|
||||
tryReqDto.setModelId(modelConfigDtos.get(0).getId());
|
||||
@@ -154,6 +164,94 @@ public class TaskCenterApplicationServiceImpl implements TaskExecuteService {
|
||||
executeAgentTask0(sink, requestContext, tryReqDto, scheduleTask, 0);
|
||||
}
|
||||
|
||||
private void mergeSelectedComponents(List<TryReqDto.SelectedComponentDto> selectedComponents, Object rawSelectedComponents) {
|
||||
if (!(rawSelectedComponents instanceof Collection<?> rawList)) {
|
||||
return;
|
||||
}
|
||||
Set<String> existing = new HashSet<>();
|
||||
for (TryReqDto.SelectedComponentDto item : selectedComponents) {
|
||||
if (item.getId() != null && item.getType() != null) {
|
||||
existing.add(item.getType().name() + ":" + item.getId());
|
||||
}
|
||||
}
|
||||
for (Object rawItem : rawList) {
|
||||
TryReqDto.SelectedComponentDto selectedComponentDto = parseSelectedComponent(rawItem);
|
||||
if (selectedComponentDto == null || selectedComponentDto.getId() == null || selectedComponentDto.getType() == null) {
|
||||
continue;
|
||||
}
|
||||
String key = selectedComponentDto.getType().name() + ":" + selectedComponentDto.getId();
|
||||
if (existing.add(key)) {
|
||||
selectedComponents.add(selectedComponentDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TryReqDto.SelectedComponentDto parseSelectedComponent(Object rawItem) {
|
||||
if (rawItem instanceof TryReqDto.SelectedComponentDto selectedComponentDto) {
|
||||
return selectedComponentDto.getId() != null && selectedComponentDto.getType() != null ? selectedComponentDto : null;
|
||||
}
|
||||
if (!(rawItem instanceof Map<?, ?> map)) {
|
||||
return null;
|
||||
}
|
||||
Long id = toLong(map.get("id"));
|
||||
AgentComponentConfig.Type type = toComponentType(map.get("type"));
|
||||
if (id == null || type == null) {
|
||||
return null;
|
||||
}
|
||||
TryReqDto.SelectedComponentDto selectedComponentDto = new TryReqDto.SelectedComponentDto();
|
||||
selectedComponentDto.setId(id);
|
||||
selectedComponentDto.setType(type);
|
||||
return selectedComponentDto;
|
||||
}
|
||||
|
||||
private AgentComponentConfig.Type toComponentType(Object value) {
|
||||
if (value instanceof AgentComponentConfig.Type type) {
|
||||
return type;
|
||||
}
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String typeName = value.toString();
|
||||
for (AgentComponentConfig.Type type : AgentComponentConfig.Type.values()) {
|
||||
if (type.name().equalsIgnoreCase(typeName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Long> toLongList(Object value) {
|
||||
if (!(value instanceof Collection<?> collection)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Long> result = new ArrayList<>();
|
||||
for (Object item : collection) {
|
||||
Long parsed = toLong(item);
|
||||
if (parsed != null) {
|
||||
result.add(parsed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Long toLong(Object value) {
|
||||
if (value instanceof Number number) {
|
||||
return number.longValue();
|
||||
}
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String text = value.toString();
|
||||
if (text.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(text);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void executeAgentTask0(MonoSink<Boolean> sink, RequestContext<Object> requestContext, TryReqDto tryReqDto, ScheduleTaskDto scheduleTask, int times) {
|
||||
RequestContext.set(requestContext);
|
||||
AtomicBoolean retry = new AtomicBoolean(false);
|
||||
|
||||
@@ -78,9 +78,6 @@ public class TaskCenterController {
|
||||
if (publishedDto == null) {
|
||||
return ReqResult.error("Target object does not exist or has been removed");
|
||||
}
|
||||
if (!publishedDto.getSpaceId().equals(scheduleTaskAddDto.getSpaceId())) {
|
||||
return ReqResult.error("Target object space ID does not match task space ID");
|
||||
}
|
||||
ScheduleTaskDto scheduleTaskDto = new ScheduleTaskDto();
|
||||
BeanUtils.copyProperties(scheduleTaskAddDto, scheduleTaskDto);
|
||||
scheduleTaskDto.setTaskId(UUID.randomUUID().toString().replace("-", ""));
|
||||
|
||||
Reference in New Issue
Block a user