Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,6 +52,23 @@ class ChatResponse(BaseModel):
|
|
| 52 |
message: str
|
| 53 |
actions: List[Dict[str, Any]] = []
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
@app.get("/")
|
| 56 |
async def root():
|
| 57 |
return {
|
|
@@ -59,30 +76,58 @@ async def root():
|
|
| 59 |
"service": "Windows AI Controller Server",
|
| 60 |
"timestamp": datetime.now().isoformat(),
|
| 61 |
"connected_clients": len(connected_clients),
|
| 62 |
-
"pending_commands": len(pending_commands)
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
@app.post("/api/chat")
|
| 66 |
async def chat_with_ai(request: ChatRequest):
|
| 67 |
-
"""نقطة النهاية للمحادثة مع الذكاء الاصطناعي
|
| 68 |
try:
|
| 69 |
-
logger.info(f"طلب محادثة من العميل {request.client_id}: {request.message}")
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# محاكاة استجابة من نموذج الذكاء الاصطناعي الحقيقي
|
| 72 |
thinking = f"🤔 **التفكير الاستراتيجي**: تحليل متعمق لطلب المستخدم '{request.message}'. تحديد الإجراءات المطلوبة بناءً على نوع الطلب والمتطلبات."
|
| 73 |
|
| 74 |
if "لعبة" in request.message or "game" in request.message:
|
| 75 |
response_msg = "🎮 **الوكيل الاستراتيجي يحلل طلب الألعاب**\n\nتم استلام طلبك المتعلق بالألعاب بنجاح! 🚀\n\nجاري:\n• إعداد أدوات الهندسة العكسية المتقدمة\n• تحضير محلل الذاكرة والعمليات\n• تجهيز مكتبات تعديل القيم\n\n🔍 **أخبرني باسم اللعبة المحددة والميزة التي تريد تعديلها**"
|
| 76 |
-
actions = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
elif "بوت" in request.message or "bot" in request.message:
|
| 78 |
response_msg = "🤖 **تطوير البوتات - تحليل استراتيجي**\n\nممتاز! جاري:\n• تحضير بيئة التطوير المتقدمة\n• إعداد مكتبات الأتمتة\n• تحليل متطلبات الأداء\n\n💡 **ما نوع البوت الذي تريد تطويره وأي لعبة يستهدفها؟**"
|
| 79 |
-
actions = [
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
response_msg = "🧠 **الوكيل الاستراتيجي يرحب بك!**\n\n✅ **تم الاتصال بنجاح بالخادم المركزي**\n\n🔧 **الميزات المتاحة عبر الوكيل الاستراتيجي:**\n• تحليل ذاكرة متقدم للألعاب\n• هندسة عكسية باستخدام الذكاء الاصطناعي\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم\n\n🚀 **ما المهمة التي تريدني مساعدتك فيها؟**"
|
| 82 |
-
actions = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
else:
|
| 84 |
response_msg = f"🧠 **الوكيل الاستراتيجي يحلل طلبك**: '{request.message}'\n\n✅ **تم استلام طلبك بنجاح عبر الخادم المركزي**\n\n🔧 **جاري المعالجة باستخدام الذكاء الاصطناعي المتقدم...**\n\n💡 **الميزات المتاحة:**\n• تحليل متقدم للذاكرة والعمليات\n• هندسة عكسية متطورة للألعاب\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم"
|
| 85 |
-
actions = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
response = ChatResponse(
|
| 88 |
thinking_process=thinking,
|
|
@@ -90,18 +135,36 @@ async def chat_with_ai(request: ChatRequest):
|
|
| 90 |
actions=actions
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
"last_seen": datetime.now().isoformat(),
|
| 96 |
"status": "active",
|
| 97 |
-
"
|
| 98 |
}
|
| 99 |
|
| 100 |
-
logger.info(f"
|
| 101 |
-
return response
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
except Exception as e:
|
| 104 |
-
logger.error(f"خطأ في
|
| 105 |
raise HTTPException(status_code=500, detail=str(e))
|
| 106 |
|
| 107 |
@app.post("/api/send-command")
|
|
@@ -119,7 +182,9 @@ async def send_command(command: WindowsCommand):
|
|
| 119 |
"status": "pending"
|
| 120 |
}
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
|
| 124 |
return {
|
| 125 |
"success": True,
|
|
@@ -127,7 +192,7 @@ async def send_command(command: WindowsCommand):
|
|
| 127 |
"message": "تم استلام الأمر بنجاح"
|
| 128 |
}
|
| 129 |
except Exception as e:
|
| 130 |
-
logger.error(f"خطأ في استقبال الأمر: {e}")
|
| 131 |
raise HTTPException(status_code=500, detail=str(e))
|
| 132 |
|
| 133 |
@app.get("/api/get-commands/{client_id}")
|
|
@@ -148,7 +213,7 @@ async def get_commands(client_id: str):
|
|
| 148 |
|
| 149 |
return {"success": True, "commands": commands}
|
| 150 |
except Exception as e:
|
| 151 |
-
logger.error(f"خطأ في إرسال الأوامر: {e}")
|
| 152 |
raise HTTPException(status_code=500, detail=str(e))
|
| 153 |
|
| 154 |
@app.post("/api/submit-result")
|
|
@@ -162,16 +227,13 @@ async def submit_result(result: ClientResult):
|
|
| 162 |
"timestamp": datetime.now().isoformat()
|
| 163 |
}
|
| 164 |
|
| 165 |
-
|
| 166 |
-
"last_seen": datetime.now().isoformat(),
|
| 167 |
-
"status": "active"
|
| 168 |
-
}
|
| 169 |
|
| 170 |
-
logger.info(f"تم استلام نتيجة من العميل {result.client_id}")
|
| 171 |
|
| 172 |
return {"success": True, "message": "تم استلام النتيجة بنجاح"}
|
| 173 |
except Exception as e:
|
| 174 |
-
logger.error(f"خطأ في استقبال النتيجة: {e}")
|
| 175 |
raise HTTPException(status_code=500, detail=str(e))
|
| 176 |
|
| 177 |
@app.get("/api/client-status/{client_id}")
|
|
@@ -183,21 +245,41 @@ async def client_status(client_id: str):
|
|
| 183 |
"client_id": client_id,
|
| 184 |
"status": client_data.get("status", "offline"),
|
| 185 |
"last_seen": client_data.get("last_seen"),
|
|
|
|
| 186 |
"timestamp": datetime.now().isoformat()
|
| 187 |
}
|
| 188 |
|
| 189 |
@app.get("/api/system-status")
|
| 190 |
async def system_status():
|
| 191 |
"""حالة النظام العام"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
return {
|
| 193 |
"success": True,
|
| 194 |
"status": "running",
|
| 195 |
"connected_clients": len(connected_clients),
|
|
|
|
| 196 |
"pending_commands": len(pending_commands),
|
| 197 |
"total_results": len(client_results),
|
| 198 |
"server_time": datetime.now().isoformat()
|
| 199 |
}
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if __name__ == "__main__":
|
| 202 |
import uvicorn
|
| 203 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 52 |
message: str
|
| 53 |
actions: List[Dict[str, Any]] = []
|
| 54 |
|
| 55 |
+
class ClientRegistration(BaseModel):
|
| 56 |
+
client_id: str
|
| 57 |
+
machine_name: str
|
| 58 |
+
os_version: str
|
| 59 |
+
timestamp: str
|
| 60 |
+
agent_type: str
|
| 61 |
+
|
| 62 |
+
def update_client_activity(client_id: str, activity: str = "chat"):
|
| 63 |
+
"""تحديث نشاط العميل"""
|
| 64 |
+
connected_clients[client_id] = {
|
| 65 |
+
"last_seen": datetime.now().isoformat(),
|
| 66 |
+
"status": "active",
|
| 67 |
+
"last_activity": activity,
|
| 68 |
+
"message_count": connected_clients.get(client_id, {}).get("message_count", 0) + 1
|
| 69 |
+
}
|
| 70 |
+
logger.info(f"📊 تم تحديث نشاط العميل {client_id}: {activity}")
|
| 71 |
+
|
| 72 |
@app.get("/")
|
| 73 |
async def root():
|
| 74 |
return {
|
|
|
|
| 76 |
"service": "Windows AI Controller Server",
|
| 77 |
"timestamp": datetime.now().isoformat(),
|
| 78 |
"connected_clients": len(connected_clients),
|
| 79 |
+
"pending_commands": len(pending_commands),
|
| 80 |
+
"active_clients": list(connected_clients.keys())
|
| 81 |
}
|
| 82 |
|
| 83 |
@app.post("/api/chat")
|
| 84 |
async def chat_with_ai(request: ChatRequest):
|
| 85 |
+
"""نقطة النهاية للمحادثة مع الذكاء الاصطناعي"""
|
| 86 |
try:
|
| 87 |
+
logger.info(f"💬 طلب محادثة من العميل {request.client_id}: {request.message}")
|
| 88 |
+
|
| 89 |
+
# تحديث نشاط العميل فوراً
|
| 90 |
+
update_client_activity(request.client_id, "chat")
|
| 91 |
|
| 92 |
# محاكاة استجابة من نموذج الذكاء الاصطناعي الحقيقي
|
| 93 |
thinking = f"🤔 **التفكير الاستراتيجي**: تحليل متعمق لطلب المستخدم '{request.message}'. تحديد الإجراءات المطلوبة بناءً على نوع الطلب والمتطلبات."
|
| 94 |
|
| 95 |
if "لعبة" in request.message or "game" in request.message:
|
| 96 |
response_msg = "🎮 **الوكيل الاستراتيجي يحلل طلب الألعاب**\n\nتم استلام طلبك المتعلق بالألعاب بنجاح! 🚀\n\nجاري:\n• إعداد أدوات الهندسة العكسية المتقدمة\n• تحضير محلل الذاكرة والعمليات\n• تجهيز مكتبات تعديل القيم\n\n🔍 **أخبرني باسم اللعبة المحددة والميزة التي تريد تعديلها**"
|
| 97 |
+
actions = [
|
| 98 |
+
{
|
| 99 |
+
"type": "game_analysis",
|
| 100 |
+
"description": "تحليل هياكل اللعبة والذاكرة باستخدام الذكاء الاستراتيجي",
|
| 101 |
+
"parameters": {"game_detected": True, "analysis_level": "advanced"}
|
| 102 |
+
}
|
| 103 |
+
]
|
| 104 |
elif "بوت" in request.message or "bot" in request.message:
|
| 105 |
response_msg = "🤖 **تطوير البوتات - تحليل استراتيجي**\n\nممتاز! جاري:\n• تحضير بيئة التطوير المتقدمة\n• إعداد مكتبات الأتمتة\n• تحليل متطلبات الأداء\n\n💡 **ما نوع البوت الذي تريد تطويره وأي لعبة يستهدفها؟**"
|
| 106 |
+
actions = [
|
| 107 |
+
{
|
| 108 |
+
"type": "bot_development",
|
| 109 |
+
"description": "إعداد بيئة تطوير البوت باستراتيجيات متقدمة",
|
| 110 |
+
"parameters": {"development_phase": "requirements_analysis"}
|
| 111 |
+
}
|
| 112 |
+
]
|
| 113 |
+
elif "مرحبا" in request.message or "اهلا" in request.message or "hello" in request.message:
|
| 114 |
response_msg = "🧠 **الوكيل الاستراتيجي يرحب بك!**\n\n✅ **تم الاتصال بنجاح بالخادم المركزي**\n\n🔧 **الميزات المتاحة عبر الوكيل الاستراتيجي:**\n• تحليل ذاكرة متقدم للألعاب\n• هندسة عكسية باستخدام الذكاء الاصطناعي\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم\n\n🚀 **ما المهمة التي تريدني مساعدتك فيها؟**"
|
| 115 |
+
actions = [
|
| 116 |
+
{
|
| 117 |
+
"type": "strategic_welcome",
|
| 118 |
+
"description": "تهيئة البيئة الاستراتيجية للعميل",
|
| 119 |
+
"parameters": {"welcome_complete": True, "client_registered": True}
|
| 120 |
+
}
|
| 121 |
+
]
|
| 122 |
else:
|
| 123 |
response_msg = f"🧠 **الوكيل الاستراتيجي يحلل طلبك**: '{request.message}'\n\n✅ **تم استلام طلبك بنجاح عبر الخادم المركزي**\n\n🔧 **جاري المعالجة باستخدام الذكاء الاصطناعي المتقدم...**\n\n💡 **الميزات المتاحة:**\n• تحليل متقدم للذاكرة والعمليات\n• هندسة عكسية متطورة للألعاب\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم"
|
| 124 |
+
actions = [
|
| 125 |
+
{
|
| 126 |
+
"type": "strategic_analysis",
|
| 127 |
+
"description": "تحليل استراتيجي متقدم للمهمة المطلوبة",
|
| 128 |
+
"parameters": {"analysis_type": "general", "complexity": "high"}
|
| 129 |
+
}
|
| 130 |
+
]
|
| 131 |
|
| 132 |
response = ChatResponse(
|
| 133 |
thinking_process=thinking,
|
|
|
|
| 135 |
actions=actions
|
| 136 |
)
|
| 137 |
|
| 138 |
+
logger.info(f"✅ تم إرسال رد استراتيجي للعميل {request.client_id} - الإجراءات: {len(actions)}")
|
| 139 |
+
return response
|
| 140 |
+
|
| 141 |
+
except Exception as e:
|
| 142 |
+
logger.error(f"❌ خطأ في معالجة المحادثة: {e}")
|
| 143 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 144 |
+
|
| 145 |
+
@app.post("/api/register-client")
|
| 146 |
+
async def register_client(registration: ClientRegistration):
|
| 147 |
+
"""تسجيل عميل جديد"""
|
| 148 |
+
try:
|
| 149 |
+
connected_clients[registration.client_id] = {
|
| 150 |
+
"machine_name": registration.machine_name,
|
| 151 |
+
"os_version": registration.os_version,
|
| 152 |
+
"agent_type": registration.agent_type,
|
| 153 |
+
"first_seen": registration.timestamp,
|
| 154 |
"last_seen": datetime.now().isoformat(),
|
| 155 |
"status": "active",
|
| 156 |
+
"message_count": 0
|
| 157 |
}
|
| 158 |
|
| 159 |
+
logger.info(f"🆕 عميل جديد مسجل: {registration.client_id} - {registration.machine_name}")
|
|
|
|
| 160 |
|
| 161 |
+
return {
|
| 162 |
+
"success": True,
|
| 163 |
+
"message": "تم تسجيل العميل بنجاح",
|
| 164 |
+
"client_id": registration.client_id
|
| 165 |
+
}
|
| 166 |
except Exception as e:
|
| 167 |
+
logger.error(f"❌ خطأ في تسجيل العميل: {e}")
|
| 168 |
raise HTTPException(status_code=500, detail=str(e))
|
| 169 |
|
| 170 |
@app.post("/api/send-command")
|
|
|
|
| 182 |
"status": "pending"
|
| 183 |
}
|
| 184 |
|
| 185 |
+
update_client_activity(command.client_id, "command")
|
| 186 |
+
|
| 187 |
+
logger.info(f"📨 تم استلام أمر من العميل {command.client_id}: {command.action}")
|
| 188 |
|
| 189 |
return {
|
| 190 |
"success": True,
|
|
|
|
| 192 |
"message": "تم استلام الأمر بنجاح"
|
| 193 |
}
|
| 194 |
except Exception as e:
|
| 195 |
+
logger.error(f"❌ خطأ في استقبال الأمر: {e}")
|
| 196 |
raise HTTPException(status_code=500, detail=str(e))
|
| 197 |
|
| 198 |
@app.get("/api/get-commands/{client_id}")
|
|
|
|
| 213 |
|
| 214 |
return {"success": True, "commands": commands}
|
| 215 |
except Exception as e:
|
| 216 |
+
logger.error(f"❌ خطأ في إرسال الأوامر: {e}")
|
| 217 |
raise HTTPException(status_code=500, detail=str(e))
|
| 218 |
|
| 219 |
@app.post("/api/submit-result")
|
|
|
|
| 227 |
"timestamp": datetime.now().isoformat()
|
| 228 |
}
|
| 229 |
|
| 230 |
+
update_client_activity(result.client_id, "result")
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
+
logger.info(f"📊 تم استلام نتيجة من العميل {result.client_id}")
|
| 233 |
|
| 234 |
return {"success": True, "message": "تم استلام النتيجة بنجاح"}
|
| 235 |
except Exception as e:
|
| 236 |
+
logger.error(f"❌ خطأ في استقبال النتيجة: {e}")
|
| 237 |
raise HTTPException(status_code=500, detail=str(e))
|
| 238 |
|
| 239 |
@app.get("/api/client-status/{client_id}")
|
|
|
|
| 245 |
"client_id": client_id,
|
| 246 |
"status": client_data.get("status", "offline"),
|
| 247 |
"last_seen": client_data.get("last_seen"),
|
| 248 |
+
"message_count": client_data.get("message_count", 0),
|
| 249 |
"timestamp": datetime.now().isoformat()
|
| 250 |
}
|
| 251 |
|
| 252 |
@app.get("/api/system-status")
|
| 253 |
async def system_status():
|
| 254 |
"""حالة النظام العام"""
|
| 255 |
+
active_clients = []
|
| 256 |
+
for client_id, data in connected_clients.items():
|
| 257 |
+
if data.get("status") == "active":
|
| 258 |
+
active_clients.append({
|
| 259 |
+
"client_id": client_id,
|
| 260 |
+
"machine_name": data.get("machine_name"),
|
| 261 |
+
"last_seen": data.get("last_seen"),
|
| 262 |
+
"message_count": data.get("message_count", 0)
|
| 263 |
+
})
|
| 264 |
+
|
| 265 |
return {
|
| 266 |
"success": True,
|
| 267 |
"status": "running",
|
| 268 |
"connected_clients": len(connected_clients),
|
| 269 |
+
"active_clients": active_clients,
|
| 270 |
"pending_commands": len(pending_commands),
|
| 271 |
"total_results": len(client_results),
|
| 272 |
"server_time": datetime.now().isoformat()
|
| 273 |
}
|
| 274 |
|
| 275 |
+
@app.get("/api/debug-clients")
|
| 276 |
+
async def debug_clients():
|
| 277 |
+
"""تصحيح الأخطاء - عرض جميع العملاء"""
|
| 278 |
+
return {
|
| 279 |
+
"connected_clients": connected_clients,
|
| 280 |
+
"total": len(connected_clients)
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
if __name__ == "__main__":
|
| 284 |
import uvicorn
|
| 285 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|