#!/bin/bash
# Check the health of AI Hub and Browser Service in production
source /app/.agent/utils/env_loader.sh
echo "Checking Node List Accessibility..."
curl -sL -w "\nStatus: %{http_code}\n" "https://ai.jerxie.com/api/v1/nodes?user_id=9a333ccd-9c3f-432f-a030-7b1e1284a436"
echo
echo "Checking Browser Service Connectivity from AI Hub..."
# Note: This executes a command on the remote hub to check its internal connectivity to the browser service
sshpass -p "$REMOTE_PASSWORD" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" "docker exec ai_hub_service python3 -c \"
import socket
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(3)
    s.connect(('cortex_browser_service', 50052))
    s.close()
    print('Browser Service Response: success (gRPC port 50052 open)')
except Exception as e:
    print('Browser Service error:', e)
\""
