#!/usr/bin/env python3 """ FSI_FELON v4.0 — API Demo Run this after starting the server: python3 ide/server.py """ import requests, json, sys BASE = "http://localhost:9090" PAD = " " * 4 def try_endpoint(method, path, **kwargs): url = f"{BASE}{path}" try: if method == "GET": r = requests.get(url, timeout=5) else: r = requests.post(url, json=kwargs.get("json", {}), timeout=10) return r.json() except requests.exceptions.ConnectionError: return {"error": f"Cannot connect to {url}. Is the server running?"} except Exception as e: return {"error": str(e)} def section(title): print(f"\n{'═'*60}") print(f" {title}") print(f"{'═'*60}") def print_result(label, data): if isinstance(data, dict): print(f"{PAD}{label}:") for k, v in list(data.items())[:8]: val = str(v)[:60] print(f"{PAD} {k}: {val}") else: print(f"{PAD}{label}: {str(data)[:80]}") section("1. SYSTEM STATUS") r = try_endpoint("GET", "/api/stats") print_result("Stats", r) section("2. CHIMERA ENGINE — Route a Task") r = try_endpoint("POST", "/api/chimera", json={"input": "build a web app with JWT authentication", "mode": "route"}) print_result("Route", r) section("3. FORGE — Build a Project with Sandbox") r = try_endpoint("POST", "/api/build", json={"desc": "fastapi todo app with postgres"}) print_result("Build", r) section("4. DREAM — Generate a Dream Sequence") r = try_endpoint("POST", "/api/dream", json={"prompt": "a city made of code"}) print_result("Dream", r) section("5. SUPERIMPOSITION — Generate 5 Variants") r = try_endpoint("POST", "/api/super/generate", json={"description": "user authentication microservice"}) variants = r.get("variants", []) for v in variants: print(f"{PAD}[{v['id']}] {v['approach']:14s} → {v['organ']:8s}") section("6. WHITE RABBIT — Truth Investigation") r = try_endpoint("POST", "/api/command", json={"command": "rabbit what really happened"}) output = r.get("output", []) if output: print(f"{PAD}{output[0][:80]}") output = r.get("output", []) if output: print(f"{PAD}{output[0][:80]}") section("7. MESH P2P — Initialize a Repo") r = try_endpoint("POST", "/api/mesh/init", json={"name": "demo_project"}) print_result("Mesh Init", r) section("✅ ALL ENDPOINTS DEMONSTRATED") print(f"\n{PAD}Server: {BASE}") print(f"{PAD}IDE: http://localhost:9090") print(f"{PAD}Open in browser for the full 7-panel workspace.\n")