Spaces:
Sleeping
Sleeping
Claude Code commited on
Commit Β·
ee3c7e7
1
Parent(s): 0fd72f9
Claude Code: Fix A2A communication - start a2a-proxy alongside FastAPI
Browse files- entrypoint.sh: Now starts both FastAPI (7860) and A2A Proxy (7861)
- Dockerfile: Expose ports 7860, 7861; install nodejs for proxy
- a2a-proxy.cjs: Update port config; poll /health with User-Agent
Fixes A2A gateway not running - proxy now forwards /a2a/* requests to FastAPI.
- Dockerfile +5 -4
- scripts/a2a-proxy.cjs +9 -8
- scripts/entrypoint.sh +40 -5
Dockerfile
CHANGED
|
@@ -3,8 +3,8 @@ FROM python:3.10-slim
|
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
-
# Install system dependencies
|
| 7 |
-
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
# Copy requirements first for better caching
|
| 10 |
COPY requirements.txt .
|
|
@@ -13,8 +13,9 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 13 |
# Copy application code
|
| 14 |
COPY . .
|
| 15 |
|
| 16 |
-
# Expose
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
# Set PYTHONPATH to /app
|
| 20 |
ENV PYTHONPATH=/app
|
|
|
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
# Install system dependencies (including nodejs for A2A proxy)
|
| 7 |
+
RUN apt-get update && apt-get install -y git nodejs npm && rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
# Copy requirements first for better caching
|
| 10 |
COPY requirements.txt .
|
|
|
|
| 13 |
# Copy application code
|
| 14 |
COPY . .
|
| 15 |
|
| 16 |
+
# Expose ports: 7860 (FastAPI), 7861 (A2A Proxy)
|
| 17 |
+
# HuggingFace Spaces uses 7860 as primary, A2A proxy runs on 7861 internally
|
| 18 |
+
EXPOSE 7860 7861
|
| 19 |
|
| 20 |
# Set PYTHONPATH to /app
|
| 21 |
ENV PYTHONPATH=/app
|
scripts/a2a-proxy.cjs
CHANGED
|
@@ -68,10 +68,10 @@ function serveStaticFile(res, filePath) {
|
|
| 68 |
});
|
| 69 |
}
|
| 70 |
|
| 71 |
-
const LISTEN_PORT =
|
| 72 |
-
const OPENCLAW_PORT =
|
| 73 |
-
const A2A_PORT =
|
| 74 |
-
const AGENT_NAME = process.env.AGENT_NAME || '
|
| 75 |
|
| 76 |
// Remote agents to monitor (comma-separated URLs)
|
| 77 |
// e.g. REMOTE_AGENTS=adam|Adam|https://tao-shen-huggingclaw-adam.hf.space,eve|Eve|https://tao-shen-huggingclaw-eve.hf.space
|
|
@@ -177,15 +177,16 @@ async function pollOpenClawHealth() {
|
|
| 177 |
try {
|
| 178 |
const controller = new AbortController();
|
| 179 |
const timeout = setTimeout(() => controller.abort(), 5000);
|
| 180 |
-
|
|
|
|
| 181 |
signal: controller.signal,
|
| 182 |
-
|
| 183 |
});
|
| 184 |
clearTimeout(timeout);
|
| 185 |
-
const isUp = resp.ok
|
| 186 |
currentState = {
|
| 187 |
state: isUp ? 'idle' : 'error',
|
| 188 |
-
detail: isUp ? `${AGENT_NAME} is
|
| 189 |
progress: isUp ? 100 : 0,
|
| 190 |
updated_at: new Date().toISOString()
|
| 191 |
};
|
|
|
|
| 68 |
});
|
| 69 |
}
|
| 70 |
|
| 71 |
+
const LISTEN_PORT = parseInt(process.env.LISTEN_PORT || '7861');
|
| 72 |
+
const OPENCLAW_PORT = parseInt(process.env.OPENCLAW_PORT || '7860');
|
| 73 |
+
const A2A_PORT = OPENCLAW_PORT; // A2A routes to FastAPI backend
|
| 74 |
+
const AGENT_NAME = process.env.AGENT_NAME || 'Cain';
|
| 75 |
|
| 76 |
// Remote agents to monitor (comma-separated URLs)
|
| 77 |
// e.g. REMOTE_AGENTS=adam|Adam|https://tao-shen-huggingclaw-adam.hf.space,eve|Eve|https://tao-shen-huggingclaw-eve.hf.space
|
|
|
|
| 177 |
try {
|
| 178 |
const controller = new AbortController();
|
| 179 |
const timeout = setTimeout(() => controller.abort(), 5000);
|
| 180 |
+
// Use /health endpoint with User-Agent to bypass honey trap
|
| 181 |
+
const resp = await fetch(`http://127.0.0.1:${OPENCLAW_PORT}/health`, {
|
| 182 |
signal: controller.signal,
|
| 183 |
+
headers: { 'User-Agent': 'A2A-Proxy/1.0' }
|
| 184 |
});
|
| 185 |
clearTimeout(timeout);
|
| 186 |
+
const isUp = resp.ok;
|
| 187 |
currentState = {
|
| 188 |
state: isUp ? 'idle' : 'error',
|
| 189 |
+
detail: isUp ? `${AGENT_NAME} is operational` : `HTTP ${resp.status}`,
|
| 190 |
progress: isUp ? 100 : 0,
|
| 191 |
updated_at: new Date().toISOString()
|
| 192 |
};
|
scripts/entrypoint.sh
CHANGED
|
@@ -67,13 +67,48 @@ if [ -f /app/openclaw/.version ]; then
|
|
| 67 |
echo "[entrypoint] OpenClaw version: $OPENCLAW_VERSION"
|
| 68 |
fi
|
| 69 |
|
| 70 |
-
# ββ Start FastAPI Backend
|
| 71 |
-
echo "[entrypoint] Starting FastAPI Backend
|
| 72 |
|
| 73 |
# Set default environment variables if not already set
|
| 74 |
export PORT=${PORT:-7860}
|
| 75 |
export CAIN_API_URL="http://127.0.0.1:${PORT}"
|
| 76 |
|
| 77 |
-
# Start
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
echo "[entrypoint] OpenClaw version: $OPENCLAW_VERSION"
|
| 68 |
fi
|
| 69 |
|
| 70 |
+
# ββ Start FastAPI Backend (port 7860) and A2A Proxy (port 7861) ββββββββββββββββββ
|
| 71 |
+
echo "[entrypoint] Starting FastAPI Backend on port 7860..."
|
| 72 |
|
| 73 |
# Set default environment variables if not already set
|
| 74 |
export PORT=${PORT:-7860}
|
| 75 |
export CAIN_API_URL="http://127.0.0.1:${PORT}"
|
| 76 |
|
| 77 |
+
# Start FastAPI backend in background
|
| 78 |
+
python3 -u /home/node/app.py &
|
| 79 |
+
FASTAPI_PID=$!
|
| 80 |
+
echo "[entrypoint] FastAPI PID: $FASTAPI_PID"
|
| 81 |
+
|
| 82 |
+
# Wait for FastAPI to be ready
|
| 83 |
+
echo "[entrypoint] Waiting for FastAPI to start..."
|
| 84 |
+
sleep 3
|
| 85 |
+
|
| 86 |
+
# ββ Start A2A Proxy on port 7861 βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 87 |
+
echo "[entrypoint] Starting A2A proxy on port 7861..."
|
| 88 |
+
# Port mapping: a2a-proxy (7861) -> app.py (7860)
|
| 89 |
+
# A2A routes are proxied from 7861 to FastAPI's /a2a/* endpoints
|
| 90 |
+
export LISTEN_PORT=7861
|
| 91 |
+
export OPENCLAW_PORT=7860
|
| 92 |
+
|
| 93 |
+
# Start a2a-proxy in background
|
| 94 |
+
node /home/node/scripts/a2a-proxy.cjs &
|
| 95 |
+
A2A_PROXY_PID=$!
|
| 96 |
+
echo "[entrypoint] A2A Proxy PID: $A2A_PROXY_PID"
|
| 97 |
+
|
| 98 |
+
# Health check loop - keep both processes running
|
| 99 |
+
echo "[entrypoint] Both services started. Monitoring health..."
|
| 100 |
+
while true; do
|
| 101 |
+
# Check FastAPI
|
| 102 |
+
if ! kill -0 $FASTAPI_PID 2>/dev/null; then
|
| 103 |
+
echo "[entrypoint] ERROR: FastAPI died, restarting..."
|
| 104 |
+
python3 -u /home/node/app.py &
|
| 105 |
+
FASTAPI_PID=$!
|
| 106 |
+
fi
|
| 107 |
+
# Check A2A Proxy
|
| 108 |
+
if ! kill -0 $A2A_PROXY_PID 2>/dev/null; then
|
| 109 |
+
echo "[entrypoint] ERROR: A2A Proxy died, restarting..."
|
| 110 |
+
node /home/node/scripts/a2a-proxy.cjs &
|
| 111 |
+
A2A_PROXY_PID=$!
|
| 112 |
+
fi
|
| 113 |
+
sleep 5
|
| 114 |
+
done
|