Agent Zero AI framework
tunnel ports fix
frdel02833a21cf07
diff --git a/docker/run/Dockerfile b/docker/run/Dockerfileindex 8506db066..3b75412ca 100644--- a/docker/run/Dockerfile+++ b/docker/run/Dockerfile@@ -41,7 +41,7 @@ RUN bash /ins/post_install.sh $BRANCH# Expose portsEXPOSE 22 80-RUN chmod +x /exe/initialize.sh /exe/run_A0.sh /exe/run_searxng.sh+RUN chmod +x /exe/initialize.sh /exe/run_A0.sh /exe/run_searxng.sh /exe/run_tunnel_api.sh# initialize runtime and switch to supervisordCMD ["/exe/initialize.sh", "$BRANCH"]diff --git a/python/api/tunnel.py b/python/api/tunnel.pyindex f61d68e43..62f95f2f0 100644--- a/python/api/tunnel.py+++ b/python/api/tunnel.py@@ -1,4 +1,5 @@from flask import Request, Response+from python.helpers import runtimefrom python.helpers.api import ApiHandlerfrom python.helpers.tunnel_manager import TunnelManager@@ -8,12 +9,11 @@ class Tunnel(ApiHandler):tunnel_manager = TunnelManager.get_instance()- if action == "verify":+ if action == "health":return {"success": True}if action == "create":- # Get the port from the request or use default- port = input.get("port", 5000)+ port = runtime.get_web_ui_port()tunnel_url = tunnel_manager.start_tunnel(port)if tunnel_url is None:# Add a little delay and check again - tunnel might be startingdiff --git a/python/api/tunnel_proxy.py b/python/api/tunnel_proxy.pyindex 85e12ee46..16372a42f 100644--- a/python/api/tunnel_proxy.py+++ b/python/api/tunnel_proxy.py@@ -17,7 +17,7 @@ class TunnelProxy(ApiHandler):# first verify the service is running:service_ok = Falsetry:- response = requests.post(f"http://localhost:{tunnel_api_port}/", json={"action": "verify"})+ response = requests.post(f"http://localhost:{tunnel_api_port}/", json={"action": "health"})if response.status_code == 200:service_ok = Trueexcept Exception as e:diff --git a/python/helpers/runtime.py b/python/helpers/runtime.pyindex 189d45288..6fa9cc7b0 100644--- a/python/helpers/runtime.py+++ b/python/helpers/runtime.py@@ -124,3 +124,20 @@ def call_development_function_sync(func: Union[Callable[..., T], Callable[..., Aresult = result_queue.get_nowait()return cast(T, result)+++def get_web_ui_port():+ web_ui_port = (+ get_arg("port")+ or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0))+ or 5000+ )+ return web_ui_port++def get_tunnel_api_port():+ tunnel_api_port = (+ get_arg("tunnel_api_port")+ or int(dotenv.get_dotenv_value("TUNNEL_API_PORT", 0))+ or 5070+ )+ return tunnel_api_port\ No newline at end of filediff --git a/python/helpers/tunnel_manager.py b/python/helpers/tunnel_manager.pyindex 192249273..1c0251f47 100644--- a/python/helpers/tunnel_manager.py+++ b/python/helpers/tunnel_manager.py@@ -1,35 +1,36 @@from flaredantic import FlareTunnel, FlareConfigimport threading+# Singleton to manage the tunnel instanceclass TunnelManager:_instance = None_lock = threading.Lock()-+@classmethoddef get_instance(cls):with cls._lock:if cls._instance is None:cls._instance = cls()return cls._instance-+def __init__(self):self.tunnel = Noneself.tunnel_url = Noneself.is_running = False-- def start_tunnel(self, port=5000):++ def start_tunnel(self, port=80):"""Start a new tunnel or return the existing one's URL"""if self.is_running and self.tunnel_url:return self.tunnel_url-+# Create and start a new tunnelconfig = FlareConfig(port=port,verbose=True,- timeout=60 # Increase timeout from default 30 to 60 seconds+ timeout=60, # Increase timeout from default 30 to 60 seconds)-+try:# Start tunnel in a separate thread to avoid blockingdef run_tunnel():@@ -40,23 +41,24 @@ class TunnelManager:self.is_running = Trueexcept Exception as e:print(f"Error in tunnel thread: {str(e)}")-+tunnel_thread = threading.Thread(target=run_tunnel)tunnel_thread.daemon = Truetunnel_thread.start()-+# Wait for tunnel to start (max 15 seconds instead of 5)for _ in range(150): # Increased from 50 to 150 iterationsif self.tunnel_url:breakimport time+time.sleep(0.1)-+return self.tunnel_urlexcept Exception as e:print(f"Error starting tunnel: {str(e)}")return None-+def stop_tunnel(self):"""Stop the running tunnel"""if self.tunnel and self.is_running:@@ -68,7 +70,7 @@ class TunnelManager:except Exception:return Falsereturn False-+def get_tunnel_url(self):"""Get the current tunnel URL if available"""- return self.tunnel_url if self.is_running else None\ No newline at end of file+ return self.tunnel_url if self.is_running else Nonediff --git a/run_tunnel.py b/run_tunnel.pyindex ad71e5352..e50368838 100644--- a/run_tunnel.py+++ b/run_tunnel.py@@ -20,35 +20,24 @@ def run():from werkzeug.serving import make_serverPrintStyle().print("Starting tunnel server...")+class NoRequestLoggingWSGIRequestHandler(WSGIRequestHandler):def log_request(self, code="-", size="-"):pass # Override to suppress request logging# Get configuration from environment- web_ui_port = (- runtime.get_arg("port")- or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0))- or 5000- )- # Get configuration from environment- tunnel_api_port = (- runtime.get_arg("tunnel_api_port")- or int(dotenv.get_dotenv_value("TUNNEL_API_PORT", 0))- or 5070- )+ tunnel_api_port = runtime.get_tunnel_api_port()host = (runtime.get_arg("host") or dotenv.get_dotenv_value("WEB_UI_HOST") or "localhost")server = Nonelock = threading.Lock()tunnel = Tunnel(app, lock)-# handle api request@app.route("/", methods=["POST"])async def handle_request():- return await tunnel.handle_request(request=request) # type: ignore-+ return await tunnel.handle_request(request=request) # type: ignoretry:server = make_server(diff --git a/run_ui.py b/run_ui.pyindex 82ea40635..8d164d9a4 100644--- a/run_ui.py+++ b/run_ui.py@@ -157,11 +157,7 @@ def run():pass # Override to suppress request logging# Get configuration from environment- port = (- runtime.get_arg("port")- or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0))- or 5000- )+ port = runtime.get_web_ui_port()host = (runtime.get_arg("host") or dotenv.get_dotenv_value("WEB_UI_HOST") or "localhost")diff --git a/webui/js/tunnel.js b/webui/js/tunnel.jsindex 1ce4162e1..cf0bc9c4b 100644--- a/webui/js/tunnel.js+++ b/webui/js/tunnel.js@@ -177,7 +177,7 @@ document.addEventListener('alpine:init', () => {},body: JSON.stringify({action: 'create',- port: window.location.port || (window.location.protocol === 'https:' ? 443 : 80)+ // port: window.location.port || (window.location.protocol === 'https:' ? 443 : 80)}),});