pause streaming on rejection

This commit is contained in:
Nate Sesti 2023-07-06 22:36:37 -07:00
parent 9fc831e758
commit e1bf5fc21c
8 changed files with 43 additions and 20 deletions

View file

@ -192,7 +192,8 @@ class ContinueSDK(AbstractContinueSDK):
async def get_chat_context(self) -> List[ChatMessage]:
history_context = self.history.to_chat_history()
highlighted_code = self.__autopilot._highlighted_ranges
highlighted_code = [
hr.range for hr in self.__autopilot._highlighted_ranges]
preface = "The following code is highlighted"

View file

@ -152,6 +152,8 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
self.onAcceptRejectDiff(data["accepted"])
elif message_type == "mainUserInput":
self.onMainUserInput(data["input"])
elif message_type == "deleteAtIndex":
self.onDeleteAtIndex(data["index"])
elif message_type in ["highlightedCode", "openFiles", "readFile", "editFile", "workspaceDirectory", "getUserSecret", "runCommand", "uniqueId"]:
self.sub_queue.post(message_type, data)
else:
@ -164,10 +166,11 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
"edit": file_edit.dict()
})
async def showDiff(self, filepath: str, replacement: str):
async def showDiff(self, filepath: str, replacement: str, step_index: int):
await self._send_json("showDiff", {
"filepath": filepath,
"replacement": replacement
"replacement": replacement,
"step_index": step_index
})
async def setFileOpen(self, filepath: str, open: bool = True):
@ -245,6 +248,10 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
for _, session in self.session_manager.sessions.items():
session.autopilot.handle_manual_edits(edits)
def onDeleteAtIndex(self, index: int):
for _, session in self.session_manager.sessions.items():
session.autopilot.delete_at_index(index)
def onCommandOutput(self, output: str):
# Send the output to ALL autopilots.
# Maybe not ideal behavior

View file

@ -96,7 +96,11 @@ class AbstractIdeProtocolServer(ABC):
"""Called when highlighted code is updated"""
@abstractmethod
async def showDiff(self, filepath: str, replacement: str):
def onDeleteAtIndex(self, index: int):
"""Called when a step is deleted at a given index"""
@abstractmethod
async def showDiff(self, filepath: str, replacement: str, step_index: int):
"""Show a diff"""
@abstractproperty

View file

@ -305,7 +305,10 @@ class DefaultModelEditCodeStep(Step):
full_suffix_lines = full_file_contents_lines[rif.range.end.line:]
new_file_contents = "\n".join(
full_prefix_lines) + "\n" + completion + "\n" + "\n".join(full_suffix_lines)
await sdk.ide.showDiff(rif.filepath, new_file_contents)
step_index = sdk.history.current_index
await sdk.ide.showDiff(rif.filepath, new_file_contents, step_index)
# Important state variables
# -------------------------

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.0.118",
"version": "0.0.120",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.0.118",
"version": "0.0.120",
"license": "Apache-2.0",
"dependencies": {
"@electron/rebuild": "^3.2.10",

View file

@ -14,7 +14,7 @@
"displayName": "Continue",
"pricing": "Free",
"description": "The open-source coding autopilot",
"version": "0.0.118",
"version": "0.0.120",
"publisher": "Continue",
"engines": {
"vscode": "^1.67.0"

View file

@ -164,7 +164,7 @@ class IdeProtocolClient {
this.showSuggestion(data.edit);
break;
case "showDiff":
this.showDiff(data.filepath, data.replacement);
this.showDiff(data.filepath, data.replacement, data.step_index);
break;
case "openGUI":
case "connected":
@ -243,8 +243,8 @@ class IdeProtocolClient {
);
}
showDiff(filepath: string, replacement: string) {
diffManager.writeDiff(filepath, replacement);
showDiff(filepath: string, replacement: string, step_index: number) {
diffManager.writeDiff(filepath, replacement, step_index);
}
openFile(filepath: string) {
@ -431,6 +431,10 @@ class IdeProtocolClient {
sendMainUserInput(input: string) {
this.messenger?.send("mainUserInput", { input });
}
deleteAtIndex(index: number) {
this.messenger?.send("deleteAtIndex", { index });
}
}
export default IdeProtocolClient;

View file

@ -8,6 +8,7 @@ interface DiffInfo {
originalFilepath: string;
newFilepath: string;
editor?: vscode.TextEditor;
step_index: number;
}
export const DIFF_DIRECTORY = path.join(os.homedir(), ".continue", "diffs");
@ -36,8 +37,7 @@ class DiffManager {
private openDiffEditor(
originalFilepath: string,
newFilepath: string,
newContent: string
newFilepath: string
): vscode.TextEditor | undefined {
// If the file doesn't yet exist, don't open the diff editor
if (!fs.existsSync(newFilepath)) {
@ -62,7 +62,11 @@ class DiffManager {
return editor;
}
writeDiff(originalFilepath: string, newContent: string): string {
writeDiff(
originalFilepath: string,
newContent: string,
step_index: number
): string {
this.setupDirectory();
// Create or update existing diff
@ -77,6 +81,7 @@ class DiffManager {
const diffInfo: DiffInfo = {
originalFilepath,
newFilepath,
step_index,
};
this.diffs.set(newFilepath, diffInfo);
}
@ -84,11 +89,7 @@ class DiffManager {
// Open the editor if it hasn't been opened yet
const diffInfo = this.diffs.get(newFilepath);
if (diffInfo && !diffInfo?.editor) {
diffInfo.editor = this.openDiffEditor(
originalFilepath,
newFilepath,
newContent
);
diffInfo.editor = this.openDiffEditor(originalFilepath, newFilepath);
this.diffs.set(newFilepath, diffInfo);
}
@ -101,7 +102,7 @@ class DiffManager {
vscode.window.showTextDocument(diffInfo.editor.document);
vscode.commands.executeCommand("workbench.action.closeActiveEditor");
}
// this.diffs.delete(diffInfo.newFilepath);
this.diffs.delete(diffInfo.newFilepath);
fs.unlinkSync(diffInfo.newFilepath);
}
@ -138,6 +139,9 @@ class DiffManager {
return;
}
// Stop the step at step_index in case it is still streaming
ideProtocolClient.deleteAtIndex(diffInfo.step_index);
this.cleanUpDiff(diffInfo);
}
}