"""Final patch: homepage fix + AI topics at top + SSE auto-update""" import re, json, time from fastapi.responses import HTMLResponse, JSONResponse from fastapi import Query # Import chain - must be after ai_runtime_final6 try: import ai_runtime_final6 as f6 from ai_runtime_final6 import app, f5 from main import rt except Exception as e: print(f"[ERROR] f6 import: {e}") f6 = None f5 = None rt = None PATCH_CSS_JS = r'''
''' # Register route if possible if f6 and app: try: # Remove duplicate / route to avoid conflict original_routes = [r for r in app.router.routes if not (getattr(r,'path',None)=='/' and 'GET' in getattr(r,'methods',set()))] app.router.routes = original_routes @app.get('/') async def patch_homepage(): html = f5.f4.f3.f2.f1._load_index_html() if f5 else "" body = "" if hasattr(rt,'old') and hasattr(rt.old,'PATCH_INJECT'): body += getattr(rt.old,'PATCH_INJECT','') if f5: body += getattr(f5.f4.f3.f2.f1,'FINAL_INJECT','') if hasattr(f5,'f4') else '' body += getattr(f5.f4.f3,'FINAL3_INJECT','') if hasattr(f5,'f4') else '' body += getattr(f5.f4,'FINAL4_INJECT','') if hasattr(f5,'f4') else '' body += getattr(f5,'FINAL5_INJECT','') if hasattr(f5,'f4') else '' body += getattr(f6,'FINAL6_INJECT','') if f6 else '' body += getattr(f6,'FINAL6_FAST_HOME_INJECT','') if f6 else '' body += getattr(f6,'FINAL6E_INJECT','') if f6 else '' body += PATCH_CSS_JS if '' in html: html = html.replace('', body + '\n') else: html = html + body return HTMLResponse(html) except Exception as e: print(f"[ERROR] register route: {e}")