diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java index 8aaa7f6d..44892c10 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java @@ -286,23 +286,23 @@ public CompletableFuture createConversation(String workDoneTok param.setChatMode(chatModeName); param.setCustomChatModeId(customChatModeId); + // Set historical turns if provided, inserting them before the current user message. + if (turns != null && turns.size() > 0) { + param.getTurns().addAll(0, turns); + } + if (StringUtils.isBlank(agentSlug)) { param.setWorkspaceFolder(PlatformUtils.getWorkspaceRootUri()); param.setWorkspaceFolders(LSPEclipseUtils.getWorkspaceFolders()); param.setTodoList(todos); } else { - // Set agentSlug if provided - this will modify the first turn's agentSlug + // Set agentSlug on the last turn (current user message) after history insertion if (param.getTurns() != null && !param.getTurns().isEmpty()) { - param.getTurns().get(0).setAgentSlug(agentSlug); + param.getTurns().get(param.getTurns().size() - 1).setAgentSlug(agentSlug); } param.setWorkspaceFolder(agentJobWorkspaceFolder); } - // Set historical turns if provided. - if (turns != null && turns.size() > 0) { - param.getTurns().addAll(turns); - } - // TODO: remove needToolCallConfirmation when CLS fully supports it across all IDEs. param.setNeedToolCallConfirmation(true); if (currentFile != null) { diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java index 8ba73a6e..530f3baa 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java @@ -26,7 +26,7 @@ import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ReplyData; import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ToolCallData; import com.microsoft.copilot.eclipse.core.persistence.UserTurnData.MessageData; -import com.microsoft.copilot.eclipse.core.utils.ChatMessageUtils; + /** * Factory for creating and transforming conversation data objects. Responsible only for pure data transformation with @@ -218,12 +218,10 @@ public List convertToTurns(List turnDataList) { .forLeft(requestText == null ? "" : requestText); result.add(new Turn(request, null, null)); } else if (turnData instanceof CopilotTurnData copilotTurnData) { - // TODO: We don't persist images for now, so hard code the modelSupportVersion to false. In the future, handle - // images in responses and pass the model support version here if needed. + // Assistant turns only contribute the response text; the request field is intentionally empty. String responseText = extractResponseFromCopilotTurnData(copilotTurnData); - Either> response = ChatMessageUtils - .createMessageWithImages(responseText, new ArrayList<>(), false); - result.add(new Turn(response, responseText, null)); + Either> request = Either.forLeft(""); + result.add(new Turn(request, responseText, null)); } } return result;