"""Serve isolated browser regression checks without the API, model or user data. Run `python scripts/check_frontend.py`, then open http://127.0.0.1:8081. Only a temporary copy of frontend assets is exposed. Ctrl+C stops the server. """ from functools import partial from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer from pathlib import Path from tempfile import TemporaryDirectory import json import shutil ROOT = Path(__file__).resolve().parents[1] SAMPLE = '''# Markdown 标题 这是 **加粗**、*斜体*、~~删除线~~ 和 `inline code`。 - 第一项 - 嵌套项 - [x] 已完成 > 引用内容 | 项目 | 数值 | | --- | ---: | | 风量 | 120 | ```python def greet(): print("") ``` [文档](https://example.com) ''' HOSTILE = '[bad](javascript:alert%281%29)' class Handler(SimpleHTTPRequestHandler): def do_GET(self): if self.path.startswith('/api/'): if self.path.startswith('/api/chat/interrupt'): self.send_response(204) self.end_headers() return if self.path.startswith('/api/chat/history/'): payload={'items':[{'id':'markdown-1','msg_role':'assistant','content':SAMPLE}, {'id':'markdown-2','msg_role':'assistant','content':HOSTILE}],'agent_name':'main'} elif self.path.startswith('/api/sessions'): payload={'items':[{'id':'markdown-history','title':'Markdown历史测试','mode':'full'}]} elif self.path.startswith('/api/business-agents'): payload={'items':[{'name':'main_fan','display_name':'矿井主通风机研判智能体'}]} else: payload={'model':'test','items':[],'agents':[],'assets':[]} body = json.dumps(payload,ensure_ascii=False).encode() self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() self.wfile.write(body) else: super().do_GET() if __name__ == '__main__': with TemporaryDirectory(prefix='deep-agent-frontend-') as directory: shutil.copytree(ROOT / 'static', Path(directory) / 'static') shutil.copyfile(ROOT / 'tests/frontend_markdown.html', Path(directory) / 'index.html') server = ThreadingHTTPServer(('127.0.0.1', 8081), partial(Handler, directory=directory)) print('Frontend checks: http://127.0.0.1:8081', flush=True) try: server.serve_forever() except KeyboardInterrupt: pass finally: server.server_close()