MCPcopy Create free account
hub / github.com/modelscope/ms-agent / websocket_session

Function websocket_session

webui/backend/websocket_handler.py:115–140  ·  view source on GitHub ↗

WebSocket endpoint for session communication

(websocket: WebSocket, session_id: str)

Source from the content-addressed store, hash-verified

113
114@router.websocket('/session/{session_id}')
115async def websocket_session(websocket: WebSocket, session_id: str):
116 """WebSocket endpoint for session communication"""
117 print(f'[WS] Client connecting to session: {session_id}')
118 await connection_manager.connect(websocket, session_id)
119 print(f'[WS] Client connected to session: {session_id}')
120
121 try:
122 while True:
123 data = await websocket.receive_json()
124 print(f'[WS] Received message: {data}')
125 await handle_session_message(session_id, data, websocket)
126 except WebSocketDisconnect:
127 print(f'[WS] Client disconnected from session: {session_id}')
128 connection_manager.disconnect(websocket, session_id)
129 session = session_manager.get_session(session_id)
130 is_deep_research = bool(
131 session and session.get('project_id') == 'deep_research_v2')
132 # Stop agent if running
133 if session_id in agent_runners:
134 await agent_runners[session_id].stop()
135 del agent_runners[session_id]
136 if session_id in agent_tasks:
137 agent_tasks[session_id].cancel()
138 del agent_tasks[session_id]
139 if not is_deep_research:
140 await deep_research_manager.stop(session_id)
141
142
143@router.websocket('/logs')

Callers

nothing calls this directly

Calls 6

handle_session_messageFunction · 0.85
disconnectMethod · 0.80
get_sessionMethod · 0.80
getMethod · 0.80
connectMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected