From 3c1543a1049670c227755229a0305613442bcda8 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 29 四月 2026 20:43:13 +0800
Subject: [PATCH] Merge branch 'codex/ai-provider-protocol-gateway'

---
 src/main/java/com/zy/ai/service/impl/AutoTuneCoordinatorServiceImpl.java |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/zy/ai/service/impl/AutoTuneCoordinatorServiceImpl.java b/src/main/java/com/zy/ai/service/impl/AutoTuneCoordinatorServiceImpl.java
index 2ae5ba5..6e3148b 100644
--- a/src/main/java/com/zy/ai/service/impl/AutoTuneCoordinatorServiceImpl.java
+++ b/src/main/java/com/zy/ai/service/impl/AutoTuneCoordinatorServiceImpl.java
@@ -2,6 +2,7 @@
 
 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;
@@ -10,6 +11,7 @@
 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;
@@ -36,9 +38,7 @@
 @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;
@@ -54,6 +54,7 @@
     );
 
     private final ConfigService configService;
+    private final AutoTuneControlModeService autoTuneControlModeService;
     private final WrkMastService wrkMastService;
     private final AiAutoTuneJobService aiAutoTuneJobService;
     private final AiAutoTuneMcpCallService aiAutoTuneMcpCallService;
@@ -117,14 +118,8 @@
     }
 
     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() {
@@ -193,6 +188,7 @@
     }
 
     private AutoTuneAgentService.AutoTuneAgentResult failedAgentResult(String triggerType, Exception exception) {
+        AutoTuneControlModeSnapshot controlMode = autoTuneControlModeService.currentMode();
         AutoTuneAgentService.AutoTuneAgentResult result = new AutoTuneAgentService.AutoTuneAgentResult();
         result.setSuccess(false);
         result.setTriggerType(triggerType);
@@ -203,6 +199,9 @@
         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);
@@ -395,6 +394,9 @@
     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;
     }
 
@@ -402,6 +404,9 @@
         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());

--
Gitblit v1.9.1