"""Serve the legacy decompose demo from repo-local files. The legacy `web/index.html` expects assets at root paths such as `/frameworks.json`, `/payloads.json`, `/prompt-read/...`, and `/data/...`. This tiny server preserves those paths without changing the old frontend. """ from __future__ import annotations from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer from pathlib import Path from urllib.parse import unquote, urlparse ROOT = Path(__file__).resolve().parent.parent WEB = ROOT / "web" PROMPTS = ROOT / "prompts" SKILL_EXTRACTION = ROOT / "创作知识提取-skill" / "extraction" class LegacyDemoHandler(SimpleHTTPRequestHandler): def translate_path(self, path: str) -> str: parsed = urlparse(path) clean = unquote(parsed.path) if clean in {"", "/"}: return str(WEB / "index.html") if clean.startswith("/data/"): return str(ROOT / clean.lstrip("/")) if clean.startswith("/runs/"): return str(WEB / clean.lstrip("/")) if clean.startswith("/prompt-read/"): return str(PROMPTS / clean.removeprefix("/prompt-read/")) if clean.startswith("/prompt-skill/"): return str(SKILL_EXTRACTION / clean.removeprefix("/prompt-skill/")) return str(WEB / clean.lstrip("/")) def main() -> None: server = ThreadingHTTPServer(("127.0.0.1", 8127), LegacyDemoHandler) print("Serving legacy demo at http://127.0.0.1:8127/") server.serve_forever() if __name__ == "__main__": main()