Spaces:
Running
Running
| import re | |
| file_path = 'shadow_brain_core/web_server.py' | |
| with open(file_path, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| # 1. Remove old init logic calls | |
| old_init_block = """ # Initialize modular logic with shared dependencies | |
| db_url = os.environ.get("DATABASE_URL") | |
| init_service_logic(project_root, db_url, app.config) | |
| init_chat_logic(project_root, db_url, jarvis_brain) | |
| init_admin_logic(project_root, db_url) | |
| init_agent_logic(project_root, db_url, jarvis_brain) | |
| init_security_logic(app, project_root) | |
| init_deploy_logic(app, project_root) | |
| init_report_logic(app, project_root)""" | |
| new_init_block = """ # Init block moved to the end of create_web_server | |
| db_url = os.environ.get("DATABASE_URL")""" | |
| content = content.replace(old_init_block, new_init_block) | |
| # 2. Add correct init logic at the end of create_web_server | |
| # Find where the catch block ends. | |
| end_hook_start = " print(f\"[TTS_PROXY] Qwen ?청 ?치명???류: {e}\", flush=True)\n return jsonify({\"error\": str(e)}), 500" | |
| new_end_block = """ print(f"[TTS_PROXY] Qwen ?청 ?치명???류: {e}", flush=True) | |
| return jsonify({"error": str(e)}), 500 | |
| def _require_master_user(): | |
| from flask import jsonify | |
| user = _load_session_user() | |
| if not user or user.get("role") != "Master": | |
| return None, (jsonify({"status": "ERROR", "message": "Master Role Required"}), 403) | |
| return user, None | |
| # [Imperial] Initialize modular logic with all required dependencies | |
| from compaction import CompactionEngine | |
| from sovereign_memory import memory_write_vector | |
| import services.brain_service as brain_service | |
| compaction_engine = CompactionEngine(db_url, jarvis_brain) | |
| init_service_logic(project_root, db_url, app.config) | |
| init_chat_logic(app, project_root, db_url, lambda: _load_session_user(), compaction_engine, memory_write_vector) | |
| init_admin_logic(app, project_root, db_url, lambda: _require_master_user()) | |
| init_agent_logic(app, project_root, jarvis_brain, lambda: _load_session_user(), _save_chat_history, brain_service) | |
| init_security_logic(app, project_root) | |
| init_deploy_logic(app, project_root) | |
| init_report_logic(app, project_root) | |
| return app""" | |
| content = content.replace(end_hook_start, new_end_block) | |
| with open(file_path, 'w', encoding='utf-8') as f: | |
| f.write(content) | |
| print('Patch applied successfully.') | |