|
|
|
import os |
|
import subprocess |
|
import sys |
|
import time |
|
from pathlib import Path |
|
import signal |
|
import threading |
|
|
|
def main(): |
|
processes = [] |
|
try: |
|
|
|
api_binary = Path("/app/server/bin/api") |
|
playground_dir = Path("/app/playground") |
|
|
|
|
|
if not api_binary.exists(): |
|
print(f"ERROR: API binary not found at {api_binary}", file=sys.stderr) |
|
return 1 |
|
|
|
if not playground_dir.exists(): |
|
print(f"ERROR: Playground directory not found at {playground_dir}", file=sys.stderr) |
|
return 1 |
|
|
|
|
|
print("Starting TEN-Agent API server on port 8080...") |
|
api_process = subprocess.Popen([str(api_binary)]) |
|
processes.append(api_process) |
|
|
|
|
|
time.sleep(3) |
|
|
|
|
|
print("Starting Playground UI in development mode on port 7860...") |
|
os.environ["PORT"] = "7860" |
|
os.environ["AGENT_SERVER_URL"] = "http://localhost:8080" |
|
os.environ["NEXT_PUBLIC_EDIT_GRAPH_MODE"] = "true" |
|
|
|
playground_process = subprocess.Popen( |
|
["pnpm", "dev"], |
|
cwd=str(playground_dir), |
|
env=os.environ |
|
) |
|
processes.append(playground_process) |
|
|
|
|
|
for proc in processes: |
|
proc.wait() |
|
|
|
except KeyboardInterrupt: |
|
print("Shutting down...") |
|
except Exception as e: |
|
print(f"Error: {e}", file=sys.stderr) |
|
finally: |
|
|
|
for proc in processes: |
|
if proc and proc.poll() is None: |
|
proc.terminate() |
|
try: |
|
proc.wait(timeout=5) |
|
except subprocess.TimeoutExpired: |
|
proc.kill() |
|
|
|
return 0 |
|
|
|
if __name__ == "__main__": |
|
|
|
signal.signal(signal.SIGINT, lambda sig, frame: sys.exit(0)) |
|
signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit(0)) |
|
|
|
sys.exit(main()) |