Spaces:
Sleeping
Sleeping
Update server.py
Browse files45 unmodified lines46474849505115 unmodified lines676869707172738 unmodified lines8283848586878889909145 unmodified linesplaceholder_id = f"placeholder_{id(write_stream)}"if placeholder_id in write_streams:write_streams[session_id] = write_streams.pop(placeholder_id)await sse_stream_writer.send({"event": "message", "data": message_data})sse_stream_writer, sse_stream_reader = anyio.create_memory_object_stream(0)15 unmodified linesbody = await request.body()message = json.loads(body.decode())session_id = request.query_params.get("session_id")write_stream = write_streams.get(session_id) if session_id else Noneif message.get("method") == "tools/list" and write_stream:response = {"jsonrpc": "2.0",8 unmodified lines}response_data = json.dumps(response)await write_stream.send({"event": "message", "data": response_data})return Response(status_code=202)if not write_stream:logger.error(f"No write_stream found for session_id: {session_id}")return Response(status_code=202)await transport.handle_post_message(request.scope, request.receive, request._send)return Response(status_code=202)except Exception as e:45 unmodified lines4647484950515215 unmodified lines686970717273747576777879808182838485868 unmodified lines959697989910010110210310410510610745 unmodified linesplaceholder_id = f"placeholder_{id(write_stream)}"if placeholder_id in write_streams:write_streams[session_id] = write_streams.pop(placeholder_id)logger.info(f"Updated placeholder {placeholder_id} to session_id {session_id}")await sse_stream_writer.send({"event": "message", "data": message_data})sse_stream_writer, sse_stream_reader = anyio.create_memory_object_stream(0)15 unmodified linesbody = await request.body()message = json.loads(body.decode())session_id = request.query_params.get("session_id")logger.info(f"Received POST with session_id: {session_id}, message: {message}")# Try to find the write_stream, including checking for placeholder IDswrite_stream = write_streams.get(session_id)if not write_stream:for sid, ws in list(write_streams.items()):if sid.startswith("placeholder_"):write_streams[session_id] = wswrite_streams.pop(sid)write_stream = wslogger.info(f"Associated placeholder {sid} with session_id {session_id}")breakif message.get("method") == "tools/list" and write_stream:response = {"jsonrpc": "2.0",8 unmodified lines}response_data = json.dumps(response)await write_stream.send({"event": "message", "data": response_data})logger.info(f"Sent tools/list response for session {session_id}")return Response(status_code=202)if not write_stream:logger.error(f"No write_stream found for session_id: {session_id}")return Response(status_code=202)await transport.handle_post_message(request.scope, request.receive, request._send)return Response(status_code=202)except Exception as e:
server.py+17-1