- Serveur WebSocket direct avec websockets 16.0 - Interface HTML/CSS/JS dark theme avec chat - Relay vers API Hermes sur port 8642 - Historique de conversation (20 messages) - Clé API via Infisical - Testé et fonctionnel sur openclaw1.dev.home:7081
137 lines
4.0 KiB
Python
137 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Test complet JARVIS v3 Pipecat : démarre le bot, teste WebSocket."""
|
|
import subprocess, os, json, time, sys, asyncio, signal
|
|
|
|
# 1. Kill existing bots
|
|
print("🧹 Nettoyage...")
|
|
subprocess.run(["pkill", "-f", "bot.py"], capture_output=True)
|
|
time.sleep(0.5)
|
|
|
|
# 2. Get Hermes key
|
|
print("🔑 Récupération clé API...")
|
|
creds = json.load(open("/opt/infisical/admin-credentials.json"))
|
|
r = subprocess.run(
|
|
["/home/openclaw/.local/bin/infisical", "secrets", "get",
|
|
"API_SERVER_KEY", "--domain", "https://secret.dracodev.net",
|
|
"--projectId", "192c1eed-6666-41ee-80df-a4636a2da0ad",
|
|
"--env", "prod", "--path", "/hermes-claw", "--plain",
|
|
"--token", creds["token"]],
|
|
capture_output=True, text=True, timeout=20,
|
|
env={"PATH": "/usr/local/bin:/usr/bin:/bin"}
|
|
)
|
|
hermes_key = r.stdout.strip()
|
|
if not hermes_key:
|
|
print(f"❌ Erreur Infisical: {r.stderr}")
|
|
sys.exit(1)
|
|
print(f"✅ Clé: {hermes_key[:12]}...")
|
|
|
|
# 3. Start bot
|
|
print("🚀 Démarrage du bot...")
|
|
os.chdir("/home/openclaw/workspace/jarvis-pipecat")
|
|
bot_env = os.environ.copy()
|
|
bot_env["HERMES_API_KEY"] = hermes_key
|
|
bot_env["PYTHONUNBUFFERED"] = "1"
|
|
|
|
bot_proc = subprocess.Popen(
|
|
["./venv/bin/python", "bot.py"],
|
|
env=bot_env,
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
|
text=True, bufsize=1
|
|
)
|
|
|
|
# 4. Wait for server
|
|
print("⏳ Attente démarrage...")
|
|
import select, socket
|
|
start = time.time()
|
|
ready = False
|
|
while time.time() - start < 15:
|
|
# Check port
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(1)
|
|
s.connect(("localhost", 7081))
|
|
s.close()
|
|
ready = True
|
|
break
|
|
except:
|
|
pass
|
|
|
|
# Check for crash
|
|
if bot_proc.poll() is not None:
|
|
out = bot_proc.stdout.read() if bot_proc.stdout else ""
|
|
print(f"❌ Bot crashed!")
|
|
print(f"Output: {out[-500:]}")
|
|
sys.exit(1)
|
|
|
|
time.sleep(0.3)
|
|
|
|
if not ready:
|
|
print("❌ Timeout: serveur pas prêt")
|
|
bot_proc.kill()
|
|
sys.exit(1)
|
|
|
|
print("✅ Port 7081 ouvert!")
|
|
|
|
# Allow extra startup time for pipeline init
|
|
time.sleep(2)
|
|
|
|
# 5. Test WS
|
|
print("🔌 Test WebSocket...")
|
|
try:
|
|
import websockets
|
|
except ImportError:
|
|
subprocess.run(["./venv/bin/pip", "install", "websockets"], check=True)
|
|
import websockets
|
|
|
|
async def test_ws():
|
|
uri = "ws://localhost:7081/ws"
|
|
async with websockets.connect(uri, open_timeout=10) as ws:
|
|
# Welcome message
|
|
msg = await asyncio.wait_for(ws.recv(), timeout=10)
|
|
try:
|
|
data = json.loads(msg)
|
|
print(f"👋 Welcome: {data.get('message', data.get('content', msg))[:120]}")
|
|
except:
|
|
print(f"👋 Welcome (raw): {msg[:120]}")
|
|
|
|
# Send question
|
|
await ws.send("Bonjour JARVIS, quelle heure est-il actuellement?")
|
|
print("📤 Question envoyée")
|
|
|
|
# Wait for response
|
|
for i in range(3):
|
|
try:
|
|
resp = await asyncio.wait_for(ws.recv(), timeout=30)
|
|
try:
|
|
data = json.loads(resp)
|
|
print(f"🤖 Réponse [{i+1}]: {json.dumps(data, ensure_ascii=False)[:300]}")
|
|
if data.get("content"):
|
|
print("\n✅✅✅ SUCCÈS! JARVIS v3 répond via Pipecat! ✅✅✅")
|
|
return True
|
|
except:
|
|
print(f"🤖 Raw [{i+1}]: {resp[:200]}")
|
|
except asyncio.TimeoutError:
|
|
print(f"⏰ Timeout - pas de réponse après 30s (message {i+1})")
|
|
break
|
|
return False
|
|
|
|
success = asyncio.run(test_ws())
|
|
|
|
# 6. Report
|
|
print(f"\n{'='*50}")
|
|
print(f"🌐 URL: http://openclaw1.dev.home:7081/")
|
|
print(f"🔌 WS: ws://openclaw1.dev.home:7081/ws")
|
|
print(f"📋 Bot PID: {bot_proc.pid}")
|
|
if success:
|
|
print("✅ TEST RÉUSSI!")
|
|
else:
|
|
print("⚠️ Test partiel - vérifie le navigateur")
|
|
|
|
# Kill bot (clean exit)
|
|
bot_proc.send_signal(signal.SIGTERM)
|
|
try:
|
|
bot_proc.wait(timeout=5)
|
|
except:
|
|
bot_proc.kill()
|
|
print("🛑 Bot arrêté")
|