| 43 | self.active_connections: Dict[str, WebSocket] = {} |
| 44 | |
| 45 | async def connect(self, client_id: str, websocket: WebSocket): |
| 46 | await websocket.accept() |
| 47 | self.active_connections[client_id] = websocket |
| 48 | logger = logging.getLogger("AIStudioProxyServer") |
| 49 | logger.info(f"WebSocket logging client connected: {client_id}") |
| 50 | try: |
| 51 | await websocket.send_text( |
| 52 | json.dumps( |
| 53 | { |
| 54 | "type": "connection_status", |
| 55 | "status": "connected", |
| 56 | "message": "Connected to real-time log stream.", |
| 57 | "timestamp": datetime.datetime.now().isoformat(), |
| 58 | } |
| 59 | ) |
| 60 | ) |
| 61 | except asyncio.CancelledError: |
| 62 | raise |
| 63 | except Exception as e: |
| 64 | logger.warning(f"Failed to send welcome message to WebSocket client {client_id}: {e}") |
| 65 | |
| 66 | def disconnect(self, client_id: str): |
| 67 | if client_id in self.active_connections: |