diff --git a/src/main/java/com/olympus/hermione/services/ProjectService.java b/src/main/java/com/olympus/hermione/services/ProjectService.java index 04ef3a2..b958fbb 100644 --- a/src/main/java/com/olympus/hermione/services/ProjectService.java +++ b/src/main/java/com/olympus/hermione/services/ProjectService.java @@ -3,9 +3,6 @@ package com.olympus.hermione.services; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; import org.bson.types.ObjectId; import org.slf4j.Logger; @@ -14,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.olympus.hermione.dto.ScenarioOutput; -import com.olympus.hermione.models.ScenarioExecution; -import com.olympus.hermione.repository.ProjectRepository; + import com.olympus.hermione.security.entity.User; import com.olympus.hermione.security.repository.UserRepository; import com.olympus.model.Application; @@ -27,9 +21,6 @@ import com.olympus.model.Project; public class ProjectService { private Logger logger = LoggerFactory.getLogger(ProjectService.class); - - @Autowired - private ProjectRepository projectRepo; @Autowired private UserRepository userRepo; diff --git a/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java b/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java index 44412f0..2af1511 100644 --- a/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java +++ b/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java @@ -338,6 +338,9 @@ public class ScenarioExecutionService { folder_name = scenarioExecutionInput.getInputs().get("MultiFileUpload"); } if (scenarioExecutionInput.getInputs().containsKey("SingleFileUpload")) { + if (scenarioExecutionInput.getInputs().containsKey("Folder")) { + folder_name = scenarioExecutionInput.getInputs().get("Folder"); + } scenarioExecutionInput.getInputs().put("SingleFileUpload", uploadDir + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload")); } diff --git a/src/main/java/com/olympus/hermione/stepSolvers/OlympusAgentSolver.java b/src/main/java/com/olympus/hermione/stepSolvers/OlympusAgentSolver.java index bf17cdb..6823eae 100644 --- a/src/main/java/com/olympus/hermione/stepSolvers/OlympusAgentSolver.java +++ b/src/main/java/com/olympus/hermione/stepSolvers/OlympusAgentSolver.java @@ -135,19 +135,56 @@ public class OlympusAgentSolver extends StepSolver { String.class ); - JSONObject jsonResponse = new JSONObject(response.getBody()); - + JSONObject outer = new JSONObject(response.getBody()); + + // Try to extract the inner `response` field (ChatResponse.response) + JSONObject jsonResponse = null; + Object respObj = outer.opt("response"); + String finalOutput = ""; + + if (respObj instanceof JSONObject) { + jsonResponse = (JSONObject) respObj; + } else if (respObj instanceof String) { + String respStr = (String) respObj; + // If the inner response is a JSON string, parse it + try { + jsonResponse = new JSONObject(respStr); + } catch (Exception ex) { + // Not a JSON string: use the raw string as final output + finalOutput = respStr; + } + } + + // If we didn't find an inner json, fallback to outer as response container + if (jsonResponse == null) { + jsonResponse = outer; + } + + // Prefer explicit final_output field, otherwise attempt to derive it + finalOutput = jsonResponse.optString("final_output", finalOutput); + if (finalOutput == null || finalOutput.isEmpty()) { + // If final_output is missing, try common alternatives + if (jsonResponse.has("content")) { + finalOutput = jsonResponse.optString("content", ""); + } else if (jsonResponse.has("result")) { + finalOutput = jsonResponse.optString("result", ""); + } else { + // As last resort, use the jsonResponse stringified + finalOutput = jsonResponse.toString(); + } + } + logger.info("Hermione execution completed"); logger.info("Execution ID: " + jsonResponse.optString("execution_id")); - logger.info("Final output: " + jsonResponse.optString("final_output")); - - // Store the complete response - this.scenarioExecution.getExecSharedMap().put(this.agent_output_variable, jsonResponse.toString()); - - // Also store final output separately for easy access + logger.info("Final output: " + finalOutput); + + // Store only the final output (content) in the execSharedMap to avoid saving the full wrapper + this.scenarioExecution.getExecSharedMap().put(this.agent_output_variable, finalOutput); + + // Also store final output separately for easy access (keeps previous behavior) this.scenarioExecution.getExecSharedMap().put( - this.agent_output_variable + "_final_output", - jsonResponse.optString("final_output", "") + this.agent_output_variable + "_final_output", + finalOutput );