| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.ai.domain.autotune.AutoTuneControlModeSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneJobStatus; |
| | | import com.zy.ai.domain.autotune.AutoTuneTriggerType; |
| | | import com.zy.ai.entity.AiAutoTuneMcpCall; |
| | |
| | | import com.zy.ai.service.AiAutoTuneJobService; |
| | | import com.zy.ai.service.AiAutoTuneMcpCallService; |
| | | import com.zy.ai.service.AutoTuneAgentService; |
| | | import com.zy.ai.service.AutoTuneControlModeService; |
| | | import com.zy.ai.service.AutoTuneCoordinatorService; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.WrkMastService; |
| | |
| | | @RequiredArgsConstructor |
| | | public class AutoTuneCoordinatorServiceImpl implements AutoTuneCoordinatorService { |
| | | |
| | | private static final String CONFIG_ENABLED = "aiAutoTuneEnabled"; |
| | | private static final String CONFIG_INTERVAL_MINUTES = "aiAutoTuneIntervalMinutes"; |
| | | private static final String DEFAULT_ENABLED = "N"; |
| | | private static final int DEFAULT_INTERVAL_MINUTES = 10; |
| | | private static final int MIN_INTERVAL_MINUTES = 5; |
| | | private static final int MAX_INTERVAL_MINUTES = 60; |
| | |
| | | ); |
| | | |
| | | private final ConfigService configService; |
| | | private final AutoTuneControlModeService autoTuneControlModeService; |
| | | private final WrkMastService wrkMastService; |
| | | private final AiAutoTuneJobService aiAutoTuneJobService; |
| | | private final AiAutoTuneMcpCallService aiAutoTuneMcpCallService; |
| | |
| | | } |
| | | |
| | | private boolean isEnabled() { |
| | | String enabled = configService.getConfigValue(CONFIG_ENABLED, DEFAULT_ENABLED); |
| | | if (enabled == null) { |
| | | return false; |
| | | } |
| | | String normalized = enabled.trim(); |
| | | return "Y".equalsIgnoreCase(normalized) |
| | | || "true".equalsIgnoreCase(normalized) |
| | | || "1".equals(normalized); |
| | | AutoTuneControlModeSnapshot controlMode = autoTuneControlModeService.currentMode(); |
| | | return controlMode != null && Boolean.TRUE.equals(controlMode.getEnabled()); |
| | | } |
| | | |
| | | private int resolveIntervalMinutes() { |
| | |
| | | } |
| | | |
| | | private AutoTuneAgentService.AutoTuneAgentResult failedAgentResult(String triggerType, Exception exception) { |
| | | AutoTuneControlModeSnapshot controlMode = autoTuneControlModeService.currentMode(); |
| | | AutoTuneAgentService.AutoTuneAgentResult result = new AutoTuneAgentService.AutoTuneAgentResult(); |
| | | result.setSuccess(false); |
| | | result.setTriggerType(triggerType); |
| | |
| | | result.setCompletionTokens(0L); |
| | | result.setTotalTokens(0L); |
| | | result.setMaxRoundsReached(false); |
| | | result.setAnalysisOnly(controlMode.getAnalysisOnly()); |
| | | result.setAllowApply(controlMode.getAllowApply()); |
| | | result.setExecutionMode(controlMode.getModeCode()); |
| | | result.setActualApplyCalled(false); |
| | | result.setRollbackCalled(false); |
| | | result.setSuccessCount(0); |
| | |
| | | private Map<String, Object> buildRequestSummary(AutoTuneAgentService.AutoTuneAgentResult agentResult) { |
| | | Map<String, Object> request = new LinkedHashMap<>(); |
| | | request.put("trigger", agentResult.getTriggerType()); |
| | | request.put("analysisOnly", agentResult.getAnalysisOnly()); |
| | | request.put("allowApply", agentResult.getAllowApply()); |
| | | request.put("executionMode", agentResult.getExecutionMode()); |
| | | return request; |
| | | } |
| | | |
| | |
| | | Map<String, Object> response = new LinkedHashMap<>(); |
| | | response.put("success", agentResult.getSuccess()); |
| | | response.put("summary", agentResult.getSummary()); |
| | | response.put("analysisOnly", agentResult.getAnalysisOnly()); |
| | | response.put("allowApply", agentResult.getAllowApply()); |
| | | response.put("executionMode", agentResult.getExecutionMode()); |
| | | response.put("toolCallCount", agentResult.getToolCallCount()); |
| | | response.put("llmCallCount", agentResult.getLlmCallCount()); |
| | | response.put("promptTokens", agentResult.getPromptTokens()); |