Skip to content

Commit

Permalink
Feat: new api listContexts/request is ready
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hu <[email protected]>
  • Loading branch information
daniel-hutao committed Nov 14, 2023
1 parent c39784b commit 5f072c3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/ai/devchat/devchat/ActionHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ActionHandlerFactory {
put(DevChatActions.INSERT_CODE_REQUEST, InsertCodeRequestHandler.class);
put(DevChatActions.REPLACE_FILE_CONTENT_REQUEST, ReplaceFileContentHandler.class);
put(DevChatActions.VIEW_DIFF_REQUEST, ViewDiffRequestHandler.class);
put(DevChatActions.LIST_CONTEXTS_REQUEST, ListContextsRequestHandler.class);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ai/devchat/devchat/DevChatActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public class DevChatActions {
public static final String REPLACE_FILE_CONTENT_RESPONSE = "replaceFileContent/response";
public static final String VIEW_DIFF_REQUEST = "viewDiff/request";
public static final String VIEW_DIFF_RESPONSE = "viewDiff/response";
public static final String LIST_CONTEXTS_REQUEST = "listContexts/request";
public static final String LIST_CONTEXTS_RESPONSE = "listContexts/response";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ai.devchat.devchat.handler;

import ai.devchat.common.Log;
import ai.devchat.devchat.ActionHandler;
import ai.devchat.devchat.DevChatActionHandler;
import ai.devchat.devchat.DevChatActions;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListContextsRequestHandler implements ActionHandler {
private JSONObject metadata;
private JSONObject payload;
private final DevChatActionHandler devChatActionHandler;

public ListContextsRequestHandler(DevChatActionHandler devChatActionHandler) {
this.devChatActionHandler = devChatActionHandler;
}

@Override
public void executeAction() {
Log.info("Handling list context request");

String callbackFunc = metadata.getString("callback");

List<Map<String, String>> contextList = new ArrayList<>();
Map<String, String> context1 = new HashMap<>();
context1.put("command", "git diff -cached");
context1.put("description", "the staged changes since the last commit");

Map<String, String> context2 = new HashMap<>();
context2.put("command", "git diff HEAD");
context2.put("description", "all changes since the last commit");

contextList.add(context1);
contextList.add(context2);

devChatActionHandler.sendResponse(DevChatActions.LIST_CONTEXTS_RESPONSE, callbackFunc, (metadata, payload) -> {
metadata.put("status", "success");
metadata.put("error", "");

payload.put("contexts", contextList);
});
}

@Override
public void setMetadata(JSONObject metadata) {
this.metadata = metadata;
}

@Override
public void setPayload(JSONObject payload) {
this.payload = payload;
}
}

0 comments on commit 5f072c3

Please sign in to comment.