Skip to content

Commit 86d147a

Browse files
authored
fix: 400 Bad Request when restoring conversation from persistence (#152)
1 parent b3f58b7 commit 86d147a

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,23 @@ public CompletableFuture<ChatCreateResult> createConversation(String workDoneTok
286286
param.setChatMode(chatModeName);
287287
param.setCustomChatModeId(customChatModeId);
288288

289+
// Set historical turns if provided, inserting them before the current user message.
290+
if (turns != null && turns.size() > 0) {
291+
param.getTurns().addAll(0, turns);
292+
}
293+
289294
if (StringUtils.isBlank(agentSlug)) {
290295
param.setWorkspaceFolder(PlatformUtils.getWorkspaceRootUri());
291296
param.setWorkspaceFolders(LSPEclipseUtils.getWorkspaceFolders());
292297
param.setTodoList(todos);
293298
} else {
294-
// Set agentSlug if provided - this will modify the first turn's agentSlug
299+
// Set agentSlug on the last turn (current user message) after history insertion
295300
if (param.getTurns() != null && !param.getTurns().isEmpty()) {
296-
param.getTurns().get(0).setAgentSlug(agentSlug);
301+
param.getTurns().get(param.getTurns().size() - 1).setAgentSlug(agentSlug);
297302
}
298303
param.setWorkspaceFolder(agentJobWorkspaceFolder);
299304
}
300305

301-
// Set historical turns if provided.
302-
if (turns != null && turns.size() > 0) {
303-
param.getTurns().addAll(turns);
304-
}
305-
306306
// TODO: remove needToolCallConfirmation when CLS fully supports it across all IDEs.
307307
param.setNeedToolCallConfirmation(true);
308308
if (currentFile != null) {

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ReplyData;
2727
import com.microsoft.copilot.eclipse.core.persistence.CopilotTurnData.ToolCallData;
2828
import com.microsoft.copilot.eclipse.core.persistence.UserTurnData.MessageData;
29-
import com.microsoft.copilot.eclipse.core.utils.ChatMessageUtils;
29+
3030

3131
/**
3232
* Factory for creating and transforming conversation data objects. Responsible only for pure data transformation with
@@ -218,12 +218,10 @@ public List<Turn> convertToTurns(List<AbstractTurnData> turnDataList) {
218218
.forLeft(requestText == null ? "" : requestText);
219219
result.add(new Turn(request, null, null));
220220
} else if (turnData instanceof CopilotTurnData copilotTurnData) {
221-
// TODO: We don't persist images for now, so hard code the modelSupportVersion to false. In the future, handle
222-
// images in responses and pass the model support version here if needed.
221+
// Assistant turns only contribute the response text; the request field is intentionally empty.
223222
String responseText = extractResponseFromCopilotTurnData(copilotTurnData);
224-
Either<String, List<ChatCompletionContentPart>> response = ChatMessageUtils
225-
.createMessageWithImages(responseText, new ArrayList<>(), false);
226-
result.add(new Turn(response, responseText, null));
223+
Either<String, List<ChatCompletionContentPart>> request = Either.forLeft("");
224+
result.add(new Turn(request, responseText, null));
227225
}
228226
}
229227
return result;

0 commit comments

Comments
 (0)