diff options
author | Nate Sesti <33237525+sestinj@users.noreply.github.com> | 2023-06-12 21:36:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 21:36:11 -0700 |
commit | 6676ff5ae1141dd37a11cfaa1dc07c8d24dcbf76 (patch) | |
tree | b66cd84fc66d21daac2333b9f7c6b4ee54370ed9 /continuedev/src/continuedev/server | |
parent | 19769044e875295c2e247dfd4c9d91ab1bf5dc28 (diff) | |
parent | 221d352e149a9b09e48010f14e98049bada2e7eb (diff) | |
download | sncontinue-6676ff5ae1141dd37a11cfaa1dc07c8d24dcbf76.tar.gz sncontinue-6676ff5ae1141dd37a11cfaa1dc07c8d24dcbf76.tar.bz2 sncontinue-6676ff5ae1141dd37a11cfaa1dc07c8d24dcbf76.zip |
Merge pull request #76 from continuedev/superset-of-chat
Superset of chat
Diffstat (limited to 'continuedev/src/continuedev/server')
-rw-r--r-- | continuedev/src/continuedev/server/gui.py | 17 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/gui_protocol.py | 14 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/session_manager.py | 1 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/state_manager.py | 21 |
4 files changed, 52 insertions, 1 deletions
diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py index b873a88f..cf046734 100644 --- a/continuedev/src/continuedev/server/gui.py +++ b/continuedev/src/continuedev/server/gui.py @@ -77,6 +77,10 @@ class GUIProtocolServer(AbstractGUIProtocolServer): self.on_reverse_to_index(data["index"]) elif message_type == "retry_at_index": self.on_retry_at_index(data["index"]) + elif message_type == "clear_history": + self.on_clear_history() + elif message_type == "delete_at_index": + self.on_delete_at_index(data["index"]) except Exception as e: print(e) @@ -86,6 +90,12 @@ class GUIProtocolServer(AbstractGUIProtocolServer): "state": state }) + async def send_available_slash_commands(self): + commands = await self.session.autopilot.get_available_slash_commands() + await self._send_json("available_slash_commands", { + "commands": commands + }) + def on_main_input(self, input: str): # Do something with user input asyncio.create_task(self.session.autopilot.accept_user_input(input)) @@ -106,6 +116,12 @@ class GUIProtocolServer(AbstractGUIProtocolServer): asyncio.create_task( self.session.autopilot.retry_at_index(index)) + def on_clear_history(self): + asyncio.create_task(self.session.autopilot.clear_history()) + + def on_delete_at_index(self, index: int): + asyncio.create_task(self.session.autopilot.delete_at_index(index)) + @router.websocket("/ws") async def websocket_endpoint(websocket: WebSocket, session: Session = Depends(websocket_session)): @@ -117,6 +133,7 @@ async def websocket_endpoint(websocket: WebSocket, session: Session = Depends(we protocol.websocket = websocket # Update any history that may have happened before connection + await protocol.send_available_slash_commands() await protocol.send_state_update() while AppStatus.should_exit is False: diff --git a/continuedev/src/continuedev/server/gui_protocol.py b/continuedev/src/continuedev/server/gui_protocol.py index 287f9e3b..d9506c6f 100644 --- a/continuedev/src/continuedev/server/gui_protocol.py +++ b/continuedev/src/continuedev/server/gui_protocol.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Dict, List from abc import ABC, abstractmethod @@ -28,5 +28,17 @@ class AbstractGUIProtocolServer(ABC): """Send a state update to the client""" @abstractmethod + async def send_available_slash_commands(self, commands: List[Dict]): + """Send a list of available slash commands to the client""" + + @abstractmethod def on_retry_at_index(self, index: int): """Called when the user requests a retry at a previous index""" + + @abstractmethod + def on_clear_history(self): + """Called when the user requests to clear the history""" + + @abstractmethod + def on_delete_at_index(self, index: int): + """Called when the user requests to delete a step at a given index""" diff --git a/continuedev/src/continuedev/server/session_manager.py b/continuedev/src/continuedev/server/session_manager.py index 0dbfaf38..ebea08a5 100644 --- a/continuedev/src/continuedev/server/session_manager.py +++ b/continuedev/src/continuedev/server/session_manager.py @@ -28,6 +28,7 @@ class DemoAutopilot(Autopilot): cumulative_edit_string = "" def handle_manual_edits(self, edits: List[FileEditWithFullContents]): + return for edit in edits: self.cumulative_edit_string += edit.fileEdit.replacement self._manual_edits_buffer.append(edit) diff --git a/continuedev/src/continuedev/server/state_manager.py b/continuedev/src/continuedev/server/state_manager.py new file mode 100644 index 00000000..c9bd760b --- /dev/null +++ b/continuedev/src/continuedev/server/state_manager.py @@ -0,0 +1,21 @@ +from typing import Any, List, Tuple, Union +from fastapi import WebSocket +from pydantic import BaseModel +from ..core.main import FullState + +# State updates represented as (path, replacement) pairs +StateUpdate = Tuple[List[Union[str, int]], Any] + + +class StateManager: + """ + A class that acts as the source of truth for state, ingesting changes to the entire object and streaming only the updated portions to client. + """ + + def __init__(self, ws: WebSocket): + self.ws = ws + + def _send_update(self, updates: List[StateUpdate]): + self.ws.send_json( + [update.dict() for update in updates] + ) |