diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-08-06 09:28:22 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-08-06 09:28:22 -0700 |
commit | f19345c652cfcf1bdf13d0a44a2f302e0cd1aa4c (patch) | |
tree | 4582964105452768a5346afcd764d26db6091504 /continuedev/src/continuedev/server | |
parent | 98de69abbd221d0f6b7257a72b89b191356b10b7 (diff) | |
download | sncontinue-f19345c652cfcf1bdf13d0a44a2f302e0cd1aa4c.tar.gz sncontinue-f19345c652cfcf1bdf13d0a44a2f302e0cd1aa4c.tar.bz2 sncontinue-f19345c652cfcf1bdf13d0a44a2f302e0cd1aa4c.zip |
feat: :construction: Router and new history page
Diffstat (limited to 'continuedev/src/continuedev/server')
-rw-r--r-- | continuedev/src/continuedev/server/gui.py | 3 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/main.py | 3 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/session_manager.py | 43 |
3 files changed, 42 insertions, 7 deletions
diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py index 7c89c5c2..b6f7b141 100644 --- a/continuedev/src/continuedev/server/gui.py +++ b/continuedev/src/continuedev/server/gui.py @@ -154,6 +154,9 @@ class GUIProtocolServer(AbstractGUIProtocolServer): create_async_task( self.session.autopilot.select_context_item(id, query), self.on_error) + async def reconnect_at_session(self, session_id: str): + await self._send_json("reconnect_at_session", {"session_id": session_id}) + @router.websocket("/ws") async def websocket_endpoint(websocket: WebSocket, session: Session = Depends(websocket_session)): diff --git a/continuedev/src/continuedev/server/main.py b/continuedev/src/continuedev/server/main.py index f8dfb009..f0a3f094 100644 --- a/continuedev/src/continuedev/server/main.py +++ b/continuedev/src/continuedev/server/main.py @@ -11,13 +11,14 @@ import argparse from .ide import router as ide_router from .gui import router as gui_router -from .session_manager import session_manager +from .session_manager import session_manager, router as sessions_router from ..libs.util.logging import logger app = FastAPI() app.include_router(ide_router) app.include_router(gui_router) +app.include_router(sessions_router) # Add CORS support app.add_middleware( diff --git a/continuedev/src/continuedev/server/session_manager.py b/continuedev/src/continuedev/server/session_manager.py index 56c92307..dade9853 100644 --- a/continuedev/src/continuedev/server/session_manager.py +++ b/continuedev/src/continuedev/server/session_manager.py @@ -1,6 +1,6 @@ import os import traceback -from fastapi import WebSocket +from fastapi import WebSocket, APIRouter from typing import Any, Coroutine, Dict, Union from uuid import uuid4 import json @@ -8,14 +8,16 @@ import json from fastapi.websockets import WebSocketState from ..plugins.steps.core.core import MessageStep -from ..libs.util.paths import getSessionFilePath, getSessionsFolderPath -from ..core.main import FullState, HistoryNode +from ..libs.util.paths import getSessionFilePath, getSessionsFolderPath, getSessionsListFilePath +from ..core.main import FullState, HistoryNode, SessionInfo from ..core.autopilot import Autopilot from .ide_protocol import AbstractIdeProtocolServer from ..libs.util.create_async_task import create_async_task from ..libs.util.errors import SessionNotFound from ..libs.util.logging import logger +router = APIRouter(prefix="/sessions", tags=["sessions"]) + class Session: session_id: str @@ -74,12 +76,12 @@ class SessionManager: # Start the autopilot (must be after session is added to sessions) and the policy try: - await autopilot.start() + await autopilot.start(full_state=full_state) except Exception as e: # Have to manually add to history because autopilot isn't started formatted_err = '\n'.join(traceback.format_exception(e)) msg_step = MessageStep( - name="Error loading context manager", message=formatted_err) + name="Error starting Autopilot", message=formatted_err) msg_step.description = f"```\n{formatted_err}\n```" autopilot.history.add_node(HistoryNode( step=msg_step, @@ -87,7 +89,7 @@ class SessionManager: depth=0, active=False )) - logger.warning(f"Error loading context manager: {e}") + logger.warning(f"Error starting Autopilot: {e}") def on_error(e: Exception) -> Coroutine: err_msg = '\n'.join(traceback.format_exception(e)) @@ -112,6 +114,27 @@ class SessionManager: with open(getSessionFilePath(session_id), "w") as f: json.dump(full_state.dict(), f) + # Read and update the sessions list + with open(getSessionsListFilePath(), "r") as f: + sessions_list = json.load(f) + + sessions_list.append(SessionInfo( + session_info=full_state.session_info + )) + + async def load_session(self, old_session_id: str, new_session_id: str): + """Load the session's FullState from a json file""" + + # First persist the current state + await self.persist_session(old_session_id) + + # Delete the old session, but keep the IDE + ide = self.registered_ides[old_session_id] + self.registered_ides[old_session_id] = None + + # Start the new session + await self.new_session(ide, session_id=new_session_id) + def register_websocket(self, session_id: str, ws: WebSocket): self.sessions[session_id].ws = ws logger.debug(f"Registered websocket for session {session_id}") @@ -130,3 +153,11 @@ class SessionManager: session_manager = SessionManager() + + +@router.get("/list") +async def list_sessions(): + """List all sessions""" + sessions_list_file = getSessionsListFilePath() + sessions = json.load(open(sessions_list_file, "r")) + return sessions |