mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2026-06-09 17:02:17 +00:00
- Decouple WebSocket connection from session lifecycle: workflows continue running after disconnect
- Message buffering with ring buffer (max 1000) for chat history replay on reconnect
- Session garbage collection: 24-hour TTL for terminal sessions via background asyncio task
- Multi-tab support: last tab wins, old WebSocket closed on new connection for same session
- Cancel now sends explicit WebSocket message instead of relying on disconnect detection
- Replace hardcoded API keys and BASE_URL with ${API_KEY}/${BASE_URL} placeholders in yaml configs
20 lines
581 B
Python
Executable File
20 lines
581 B
Python
Executable File
"""WebSocket endpoint routing."""
|
|
|
|
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
|
|
|
from server.state import get_websocket_manager
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.websocket("/ws")
|
|
async def websocket_endpoint(websocket: WebSocket, session_id: str = ""):
|
|
manager = get_websocket_manager()
|
|
sid = await manager.connect(websocket, session_id=session_id or None)
|
|
try:
|
|
while True:
|
|
message = await websocket.receive_text()
|
|
await manager.handle_message(sid, message)
|
|
except WebSocketDisconnect:
|
|
manager.disconnect(sid)
|