-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: new api listContexts/request is ready
Signed-off-by: Daniel Hu <[email protected]>
- Loading branch information
1 parent
c39784b
commit 5f072c3
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/ai/devchat/devchat/handler/ListContextsRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |