|
@@ -3,7 +3,7 @@ from typing import Dict, Callable
|
|
|
from fastapi import WebSocket, WebSocketDisconnect
|
|
from fastapi import WebSocket, WebSocketDisconnect
|
|
|
from .msg_stack import message_stack
|
|
from .msg_stack import message_stack
|
|
|
|
|
|
|
|
-from opendevin.logging import opendevin_logger as logger
|
|
|
|
|
|
|
+from opendevin.logger import opendevin_logger as logger
|
|
|
|
|
|
|
|
DEL_DELT_SEC = 60 * 60 * 5
|
|
DEL_DELT_SEC = 60 * 60 * 5
|
|
|
|
|
|
|
@@ -27,20 +27,20 @@ class Session:
|
|
|
try:
|
|
try:
|
|
|
data = await self.websocket.receive_json()
|
|
data = await self.websocket.receive_json()
|
|
|
except ValueError:
|
|
except ValueError:
|
|
|
- await self.send_error("Invalid JSON")
|
|
|
|
|
|
|
+ await self.send_error('Invalid JSON')
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
- message_stack.add_message(self.sid, "user", data)
|
|
|
|
|
- action = data.get("action", None)
|
|
|
|
|
|
|
+ message_stack.add_message(self.sid, 'user', data)
|
|
|
|
|
+ action = data.get('action', None)
|
|
|
await dispatch(action, data)
|
|
await dispatch(action, data)
|
|
|
except WebSocketDisconnect:
|
|
except WebSocketDisconnect:
|
|
|
self.is_alive = False
|
|
self.is_alive = False
|
|
|
- logger.info("WebSocket disconnected, sid: %s", self.sid)
|
|
|
|
|
|
|
+ logger.info('WebSocket disconnected, sid: %s', self.sid)
|
|
|
except RuntimeError as e:
|
|
except RuntimeError as e:
|
|
|
# WebSocket is not connected
|
|
# WebSocket is not connected
|
|
|
- if "WebSocket is not connected" in str(e):
|
|
|
|
|
|
|
+ if 'WebSocket is not connected' in str(e):
|
|
|
self.is_alive = False
|
|
self.is_alive = False
|
|
|
- logger.exception("Error in loop_recv: %s", e)
|
|
|
|
|
|
|
+ logger.exception('Error in loop_recv: %s', e)
|
|
|
|
|
|
|
|
async def send(self, data: Dict[str, object]) -> bool:
|
|
async def send(self, data: Dict[str, object]) -> bool:
|
|
|
try:
|
|
try:
|
|
@@ -55,11 +55,11 @@ class Session:
|
|
|
|
|
|
|
|
async def send_error(self, message: str) -> bool:
|
|
async def send_error(self, message: str) -> bool:
|
|
|
"""Sends an error message to the client."""
|
|
"""Sends an error message to the client."""
|
|
|
- return await self.send({"error": True, "message": message})
|
|
|
|
|
|
|
+ return await self.send({'error': True, 'message': message})
|
|
|
|
|
|
|
|
async def send_message(self, message: str) -> bool:
|
|
async def send_message(self, message: str) -> bool:
|
|
|
"""Sends a message to the client."""
|
|
"""Sends a message to the client."""
|
|
|
- return await self.send({"message": message})
|
|
|
|
|
|
|
+ return await self.send({'message': message})
|
|
|
|
|
|
|
|
def update_connection(self, ws: WebSocket):
|
|
def update_connection(self, ws: WebSocket):
|
|
|
self.websocket = ws
|
|
self.websocket = ws
|
|
@@ -67,8 +67,8 @@ class Session:
|
|
|
self.last_active_ts = int(time.time())
|
|
self.last_active_ts = int(time.time())
|
|
|
|
|
|
|
|
def load_from_data(self, data: Dict) -> bool:
|
|
def load_from_data(self, data: Dict) -> bool:
|
|
|
- self.last_active_ts = data.get("last_active_ts", 0)
|
|
|
|
|
|
|
+ self.last_active_ts = data.get('last_active_ts', 0)
|
|
|
if self.last_active_ts < int(time.time()) - DEL_DELT_SEC:
|
|
if self.last_active_ts < int(time.time()) - DEL_DELT_SEC:
|
|
|
return False
|
|
return False
|
|
|
- self.is_alive = data.get("is_alive", False)
|
|
|
|
|
|
|
+ self.is_alive = data.get('is_alive', False)
|
|
|
return True
|
|
return True
|