feat(work): add auto-heal engine, chat filtering, and CDP revival to box work
This commit is contained in:
+19
-5
@@ -7,7 +7,7 @@ Usage:
|
||||
Requires: websocket-client (pip install --break-system-packages websocket-client)
|
||||
CDP relay must be up: http://10.201.87.2:9410/json/list
|
||||
"""
|
||||
import json, sys, time, urllib.request
|
||||
import json, sys, time, urllib.request, subprocess, os
|
||||
import websocket
|
||||
|
||||
CDP_URL = "http://10.201.87.2:9410/json/list"
|
||||
@@ -20,10 +20,24 @@ def get_page():
|
||||
raise RuntimeError("no muse.ai page found")
|
||||
return pages[0]
|
||||
|
||||
def connect():
|
||||
page = get_page()
|
||||
ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=10)
|
||||
return ws
|
||||
def revive_browser():
|
||||
script = os.path.expanduser("~/Projects/NetVM/bin/netvm-chrome.sh")
|
||||
print("CDP disconnect detected. Reviving Chromium smoke profile...", file=sys.stderr)
|
||||
subprocess.Popen([script, "--headless", "smoke", "https://muse.ai"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
time.sleep(4)
|
||||
|
||||
def connect(retries=2):
|
||||
for attempt in range(retries + 1):
|
||||
try:
|
||||
page = get_page()
|
||||
ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=10)
|
||||
return ws
|
||||
except Exception as e:
|
||||
if attempt < retries:
|
||||
revive_browser()
|
||||
else:
|
||||
raise RuntimeError(f"Failed to connect to CDP after {retries} retries: {e}")
|
||||
|
||||
|
||||
def ev(ws, expr, await_promise=False):
|
||||
ws.send(json.dumps({"id":1,"method":"Runtime.evaluate",
|
||||
|
||||
Reference in New Issue
Block a user