update computer SDK and computer-server SDK to support the new .sandbox.cua.ai domain

This commit is contained in:
Dillon DuPont
2025-11-11 12:44:24 -05:00
parent 129d8c1238
commit 679eafe7c7
2 changed files with 126 additions and 23 deletions

View File

@@ -75,14 +75,23 @@ class Watchdog:
Returns:
WebSocket URI for the Computer API Server
"""
ip_address = (
"localhost"
if not self.container_name
else f"{self.container_name}.containers.cloud.trycua.com"
)
protocol = "wss" if self.container_name else "ws"
port = "8443" if self.container_name else "8000"
return f"{protocol}://{ip_address}:{port}/ws"
if not self.container_name:
return "ws://localhost:8000/ws"
# Try .sandbox.cua.ai first, fallback to .containers.cloud.trycua.com
return f"wss://{self.container_name}.sandbox.cua.ai:8443/ws"
@property
def ws_uri_fallback(self) -> str:
"""Get the fallback WebSocket URI using legacy hostname.
Returns:
Fallback WebSocket URI for the Computer API Server
"""
if not self.container_name:
return "ws://localhost:8000/ws"
return f"wss://{self.container_name}.containers.cloud.trycua.com:8443/ws"
async def ping(self) -> bool:
"""
@@ -91,11 +100,11 @@ class Watchdog:
Returns:
True if connection successful, False otherwise
"""
# Create a simple ping message
ping_message = {"command": "get_screen_size", "params": {}}
# Try primary URI first (.sandbox.cua.ai)
try:
# Create a simple ping message
ping_message = {"command": "get_screen_size", "params": {}}
# Try to connect to the WebSocket
async with websockets.connect(
self.ws_uri, max_size=1024 * 1024 * 10 # 10MB limit to match server
) as websocket:
@@ -105,13 +114,35 @@ class Watchdog:
# Wait for any response or just close
try:
response = await asyncio.wait_for(websocket.recv(), timeout=5)
logger.debug(f"Ping response received: {response[:100]}...")
logger.debug(f"Ping response received from primary URI: {response[:100]}...")
return True
except asyncio.TimeoutError:
return False
except Exception as e:
logger.warning(f"Ping failed: {e}")
return False
logger.debug(f"Primary URI ping failed: {e}")
# Try fallback URI (.containers.cloud.trycua.com)
if self.container_name:
try:
async with websockets.connect(
self.ws_uri_fallback, max_size=1024 * 1024 * 10 # 10MB limit to match server
) as websocket:
# Send ping message
await websocket.send(json.dumps(ping_message))
# Wait for any response or just close
try:
response = await asyncio.wait_for(websocket.recv(), timeout=5)
logger.debug(f"Ping response received from fallback URI: {response[:100]}...")
return True
except asyncio.TimeoutError:
return False
except Exception as fallback_e:
logger.warning(f"Both primary and fallback ping failed. Primary: {e}, Fallback: {fallback_e}")
return False
else:
logger.warning(f"Ping failed: {e}")
return False
def kill_processes_on_port(self, port: int) -> bool:
"""