diff --git a/Data/Server/server.py b/Data/Server/server.py
index c92d71e..b3ac2e4 100644
--- a/Data/Server/server.py
+++ b/Data/Server/server.py
@@ -4,25 +4,18 @@ import eventlet
# Monkey-patch stdlib for cooperative sockets
eventlet.monkey_patch()
-from flask import Flask, request, jsonify, send_from_directory, Response
+from flask import Flask, request, jsonify, Response
from flask_socketio import SocketIO, emit
import time
-import os
-import base64
# Borealis Python API Endpoints
from Python_API_Endpoints.ocr_engines import run_ocr_on_base64
# ---------------------------------------------
-# React Frontend Hosting Configuration
+# Flask + WebSocket Server Configuration
# ---------------------------------------------
-build_folder = os.path.join(os.getcwd(), "web-interface", "build")
-if not os.path.exists(build_folder):
- print("WARNING: web-interface build folder not found. Please build your React app.")
-
-app = Flask(__name__, static_folder=build_folder, static_url_path="/")
-# Use Eventlet, switch async mode, and raise HTTP buffer size to ~100 MB
+app = Flask(__name__)
socketio = SocketIO(
app,
cors_allowed_origins="*",
@@ -33,25 +26,18 @@ socketio = SocketIO(
}
)
-@app.route("/")
-def serve_index():
- index_path = os.path.join(build_folder, "index.html")
- if os.path.exists(index_path):
- return send_from_directory(build_folder, "index.html")
- return ("
Borealis React App Code Not Found
"
- "Please re-deploy Borealis Workflow Automation Tool
"), 404
-
-@app.route("/")
-def serve_react_app(path):
- full_path = os.path.join(build_folder, path)
- if os.path.exists(full_path):
- return send_from_directory(build_folder, path)
- return send_from_directory(build_folder, "index.html")
+# ---------------------------------------------
+# Health Check Endpoint
+# ---------------------------------------------
+@app.route("/health")
+def health():
+ return jsonify({"status": "ok"})
# ---------------------------------------------
# Borealis Python API Endpoints
# ---------------------------------------------
-# Process image data into OCR text output.
+# /api/ocr: Accepts a base64 image and OCR engine selection,
+# and returns extracted text lines.
@app.route("/api/ocr", methods=["POST"])
def ocr_endpoint():
payload = request.get_json()
@@ -59,7 +45,6 @@ def ocr_endpoint():
engine = payload.get("engine", "tesseract").lower().strip()
backend = payload.get("backend", "cpu").lower().strip()
- # Normalize engine aliases
if engine in ["tesseractocr", "tesseract"]:
engine = "tesseract"
elif engine == "easyocr":
@@ -76,6 +61,7 @@ def ocr_endpoint():
# ---------------------------------------------
# Borealis Agent API Endpoints
# ---------------------------------------------
+# These endpoints handle agent registration, provisioning, and image streaming.
registered_agents = {}
agent_configurations = {}
latest_images = {}
@@ -88,28 +74,24 @@ def get_agents():
def provision_agent():
data = request.json
agent_id = data.get("agent_id")
- roles = data.get("roles", []) # <- MODULAR ROLES ARRAY
+ roles = data.get("roles", [])
if not agent_id or not isinstance(roles, list):
return jsonify({"error": "Missing agent_id or roles[] in provision payload."}), 400
- # Save configuration
config = {"roles": roles}
agent_configurations[agent_id] = config
- # Update status if agent already registered
if agent_id in registered_agents:
registered_agents[agent_id]["status"] = "provisioned"
- # Emit config to the agent
socketio.emit("agent_config", config)
-
return jsonify({"status": "provisioned", "roles": roles})
-
-# ----------------------------------------------
-# Canvas Image Feed Viewer for Screenshot Agents
-# ----------------------------------------------
+# ---------------------------------------------
+# Live Screenshot Viewer for Debugging
+# ---------------------------------------------
+# Serves an HTML canvas that shows real-time screenshots from a given agent+node.
@app.route("/api/agent//node//screenshot/live")
def screenshot_node_viewer(agent_id, node_id):
return f"""
@@ -166,7 +148,7 @@ def screenshot_node_viewer(agent_id, node_id):
"""
# ---------------------------------------------
-# WebSocket Events
+# WebSocket Events for Real-Time Communication
# ---------------------------------------------
@socketio.on("agent_screenshot_task")
def receive_screenshot_task(data):
@@ -178,7 +160,6 @@ def receive_screenshot_task(data):
print("[WS] Screenshot task missing fields.")
return
- # Optional: Store for debugging
latest_images[f"{agent_id}:{node_id}"] = {
"image_base64": image,
"timestamp": time.time()
@@ -190,7 +171,7 @@ def receive_screenshot_task(data):
"image_base64": image
}, broadcast=True)
-@socketio.on('connect_agent')
+@socketio.on("connect_agent")
def connect_agent(data):
agent_id = data.get("agent_id")
hostname = data.get("hostname", "unknown")
@@ -203,14 +184,14 @@ def connect_agent(data):
"status": "orphaned" if agent_id not in agent_configurations else "provisioned"
}
-@socketio.on('request_config')
+@socketio.on("request_config")
def send_agent_config(data):
agent_id = data.get("agent_id")
config = agent_configurations.get(agent_id)
if config:
- emit('agent_config', config)
+ emit("agent_config", config)
-@socketio.on('screenshot')
+@socketio.on("screenshot")
def receive_screenshot(data):
agent_id = data.get("agent_id")
image = data.get("image_base64")
@@ -222,12 +203,12 @@ def receive_screenshot(data):
}
emit("new_screenshot", {"agent_id": agent_id, "image_base64": image}, broadcast=True)
-@socketio.on('disconnect')
+@socketio.on("disconnect")
def on_disconnect():
print("[WS] Agent disconnected")
# ---------------------------------------------
-# Server Start
+# Server Launch
# ---------------------------------------------
if __name__ == "__main__":
import eventlet.wsgi
diff --git a/Launch-Borealis.ps1 b/Launch-Borealis.ps1
index a353685..8e3dbd2 100644
--- a/Launch-Borealis.ps1
+++ b/Launch-Borealis.ps1
@@ -161,8 +161,7 @@ switch ($choice) {
Write-Host "`nLaunching Borealis..." -ForegroundColor Green
Write-Host "===================================================================================="
- Write-Host "$($symbols.Running) Python Flask Server Started..."
- Write-Host "$($symbols.Running) Preloading OCR Engines... Please be patient..."
+ Write-Host "$($symbols.Running) Python Flask API Server Started..."
& $py $server_py
Pop-Location